44profiles for wave propagation simulations on a regular grid.
55"""
66
7- from typing import List , Union
7+ from typing import List
88
99import torch
1010
@@ -83,8 +83,12 @@ def set_pml_profiles(
8383 device ,
8484 pml_freq ,
8585 )
86- dbydy = diffx1 (by , accuracy , 1 / grid_spacing [0 ])
87- dbxdx = diffx1 (bx , accuracy , 1 / grid_spacing [1 ])
86+ dbydy = diffx1 (
87+ by , accuracy , torch .tensor (1 / grid_spacing [0 ], dtype = dtype , device = device )
88+ )
89+ dbxdx = diffx1 (
90+ bx , accuracy , torch .tensor (1 / grid_spacing [1 ], dtype = dtype , device = device )
91+ )
8892 ay = ay [None , :, None ]
8993 ax = ax [None , None , :]
9094 by = by [None , :, None ]
@@ -94,9 +98,7 @@ def set_pml_profiles(
9498 return [ay , ax , by , bx , dbydy , dbxdx ]
9599
96100
97- def diffy1 (
98- a : torch .Tensor , accuracy : int , rdy : Union [torch .Tensor , float ]
99- ) -> torch .Tensor :
101+ def diffy1 (a : torch .Tensor , accuracy : int , rdy : torch .Tensor ) -> torch .Tensor :
100102 """Calculates the first derivative in the y-direction."""
101103 if accuracy == 2 :
102104 return torch .nn .functional .pad (
@@ -133,9 +135,7 @@ def diffy1(
133135 )
134136
135137
136- def diffx1 (
137- a : torch .Tensor , accuracy : int , rdx : Union [torch .Tensor , float ]
138- ) -> torch .Tensor :
138+ def diffx1 (a : torch .Tensor , accuracy : int , rdx : torch .Tensor ) -> torch .Tensor :
139139 """Calculates the first derivative in the x-direction."""
140140 if accuracy == 2 :
141141 return torch .nn .functional .pad (
@@ -172,9 +172,7 @@ def diffx1(
172172 )
173173
174174
175- def diffy2 (
176- a : torch .Tensor , accuracy : int , rdy2 : Union [torch .Tensor , float ]
177- ) -> torch .Tensor :
175+ def diffy2 (a : torch .Tensor , accuracy : int , rdy2 : torch .Tensor ) -> torch .Tensor :
178176 """Calculates the second derivative in the y-direction."""
179177 if accuracy == 2 :
180178 return torch .nn .functional .pad (
@@ -215,9 +213,7 @@ def diffy2(
215213 )
216214
217215
218- def diffx2 (
219- a : torch .Tensor , accuracy : int , rdx2 : Union [torch .Tensor , float ]
220- ) -> torch .Tensor :
216+ def diffx2 (a : torch .Tensor , accuracy : int , rdx2 : torch .Tensor ) -> torch .Tensor :
221217 """Calculates the second derivative in the x-direction."""
222218 if accuracy == 2 :
223219 return torch .nn .functional .pad (
0 commit comments