@@ -156,7 +156,7 @@ def __init__(
156156 )
157157 self .add_BC (component = 'T' , equation = 'T' , axis = 1 , x = - 1 , v = self .BCs ['T_bottom' ], kind = 'Dirichlet' , line = - 1 )
158158 self .add_BC (component = 'T' , equation = 'T' , axis = 1 , x = 1 , v = self .BCs ['T_top' ], kind = 'Dirichlet' , line = - 2 )
159- self .add_BC (component = 'v' , equation = 'v' , axis = 1 , x = 1 , v = self .BCs ['v_bottom ' ], kind = 'Dirichlet' , line = - 1 )
159+ self .add_BC (component = 'v' , equation = 'v' , axis = 1 , x = 1 , v = self .BCs ['v_top ' ], kind = 'Dirichlet' , line = - 1 )
160160 self .add_BC (component = 'v' , equation = 'v' , axis = 1 , x = - 1 , v = self .BCs ['v_bottom' ], kind = 'Dirichlet' , line = - 2 )
161161 self .remove_BC (component = 'v' , equation = 'v' , axis = 1 , x = - 1 , kind = 'Dirichlet' , line = - 2 , scalar = True )
162162 self .add_BC (component = 'u' , equation = 'u' , axis = 1 , v = self .BCs ['u_top' ], x = 1 , kind = 'Dirichlet' , line = - 2 )
@@ -264,6 +264,45 @@ def u_exact(self, t=0, noise_level=1e-3, seed=99):
264264 else :
265265 return me
266266
267+ def apply_BCs (self , sol ):
268+ """
269+ Enforce the Dirichlet BCs at the top and bottom for arbitrary solution.
270+ The function modifies the last two modes of u, v, and T in order to achieve this.
271+ Note that the pressure is not modified here and the Nyquist mode is not altered either.
272+
273+ Args:
274+ sol: Some solution that does not need to enforce boundary conditions
275+
276+ Returns:
277+ Modified version of the solution that satisfies Dirichlet BCs.
278+ """
279+ ultraspherical = self .spectral .axes [- 1 ]
280+
281+ if self .spectral_space :
282+ sol_half_hat = self .itransform (sol , axes = (- 2 ,))
283+ else :
284+ sol_half_hat = self .transform (sol , axes = (- 1 ,))
285+
286+ BC_bottom = ultraspherical .get_BC (x = - 1 , kind = 'dirichlet' )
287+ BC_top = ultraspherical .get_BC (x = 1 , kind = 'dirichlet' )
288+
289+ M = np .array ([BC_top [- 2 :], BC_bottom [- 2 :]])
290+ M_I = np .linalg .inv (M )
291+ rhs = np .empty ((2 , self .nx ), dtype = complex )
292+ for component in ['u' , 'v' , 'T' ]:
293+ i = self .index (component )
294+ rhs [0 ] = self .BCs [f'{ component } _top' ] - self .xp .sum (sol_half_hat [i , :, :- 2 ] * BC_top [:- 2 ], axis = 1 )
295+ rhs [1 ] = self .BCs [f'{ component } _bottom' ] - self .xp .sum (sol_half_hat [i , :, :- 2 ] * BC_bottom [:- 2 ], axis = 1 )
296+
297+ BC_vals = M_I @ rhs
298+
299+ sol_half_hat [i , :, - 2 :] = BC_vals .T
300+
301+ if self .spectral_space :
302+ return self .transform (sol_half_hat , axes = (- 2 ,))
303+ else :
304+ return self .itransform (sol_half_hat , axes = (- 1 ,))
305+
267306 def get_fig (self ): # pragma: no cover
268307 """
269308 Get a figure suitable to plot the solution of this problem
0 commit comments