@@ -37,42 +37,51 @@ class HelmholtzProblem(SpatialProblem):
3737 "boundary" : Condition (domain = "boundary" , equation = FixedValue (0.0 )),
3838 }
3939
40- def __init__ (self , alpha = 3.0 ):
40+ def __init__ (self , k = 1.0 , alpha_x = 1 , alpha_y = 4 ):
4141 """
4242 Initialization of the :class:`HelmholtzProblem` class.
4343
44- :param alpha: Parameter of the forcing term. Default is 3.0.
45- :type alpha: float | int
44+ :param k: The squared wavenumber. Default is 1.0.
45+ :type k: float | int
46+ :param int alpha_x: The frequency in the x-direction. Default is 1.
47+ :param int alpha_y: The frequency in the y-direction. Default is 4.
4648 """
4749 super ().__init__ ()
48- check_consistency (alpha , (int , float ))
49- self .alpha = alpha
50+ check_consistency (k , (int , float ))
51+ check_consistency (alpha_x , int )
52+ check_consistency (alpha_y , int )
53+ self .k = k
54+ self .alpha_x = alpha_x
55+ self .alpha_y = alpha_y
5056
5157 def forcing_term (input_ ):
5258 """
5359 Implementation of the forcing term.
5460 """
61+ x , y , pi = input_ ["x" ], input_ ["y" ], torch .pi
62+ factor = (self .alpha_x ** 2 + self .alpha_y ** 2 ) * pi ** 2
5563 return (
56- (1 - 2 * ( self .alpha * torch . pi ) ** 2 )
57- * torch .sin (self .alpha * torch . pi * input_ . extract ( "x" ) )
58- * torch .sin (self .alpha * torch . pi * input_ . extract ( "y" ) )
64+ (self .k - factor )
65+ * torch .sin (self .alpha_x * pi * x )
66+ * torch .sin (self .alpha_y * pi * y )
5967 )
6068
6169 self .conditions ["D" ] = Condition (
6270 domain = "D" ,
63- equation = Helmholtz (self .alpha , forcing_term ),
71+ equation = Helmholtz (self .k , forcing_term ),
6472 )
6573
6674 def solution (self , pts ):
6775 """
6876 Implementation of the analytical solution of the Helmholtz problem.
6977
7078 :param LabelTensor pts: Points where the solution is evaluated.
71- :return: The analytical solution of the Poisson problem.
79+ :return: The analytical solution of the Helmholtz problem.
7280 :rtype: LabelTensor
7381 """
74- sol = torch .sin (self .alpha * torch .pi * pts .extract ("x" )) * torch .sin (
75- self .alpha * torch .pi * pts .extract ("y" )
82+ x , y , pi = pts ["x" ], pts ["y" ], torch .pi
83+ sol = torch .sin (self .alpha_x * pi * x ) * torch .sin (
84+ self .alpha_y * pi * y
7685 )
7786 sol .labels = self .output_variables
7887 return sol
0 commit comments