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