Skip to content

Commit

Permalink
Handle use-before-assign warnings from pylint (#340)
Browse files Browse the repository at this point in the history
* Handle use-before-assign warnings from pylint

* fix remaining flake8, pylint errors

---------

Co-authored-by: Matthias Diener <[email protected]>
  • Loading branch information
inducer and matthiasdiener authored May 21, 2024
1 parent c2be523 commit 5b73a2b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
10 changes: 5 additions & 5 deletions examples/advection/var-velocity.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ def rhs(t, u):
norm_u = actx.to_numpy(op.norm(dcoll, event.state_component, 2))
plot(event, "fld-var-velocity-%04d" % step)

step += 1
logger.info("[%04d] t = %.5f |u| = %.5e", step, event.t, norm_u)
logger.info("[%04d] t = %.5f |u| = %.5e", step, event.t, norm_u)
# NOTE: These are here to ensure the solution is bounded for the
# time interval specified
assert norm_u < 1

# NOTE: These are here to ensure the solution is bounded for the
# time interval specified
assert norm_u < 1
step += 1

# }}}

Expand Down
16 changes: 12 additions & 4 deletions grudge/models/em.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ def flux(self, wtpair):
e, h = self.split_eh(wtpair)
epsilon = self.epsilon
mu = self.mu
else:
raise NotImplementedError("only fixed material spported for now")

Z_int = (mu/epsilon)**0.5 # noqa: N806
Y_int = 1/Z_int # noqa: N806
Expand Down Expand Up @@ -348,6 +350,8 @@ def absorbing_bc(self, w):
if self.fixed_material:
epsilon = self.epsilon
mu = self.mu
else:
raise NotImplementedError("only fixed material supported for now")

absorb_Z = (mu/epsilon)**0.5 # noqa: N806
absorb_Y = 1/absorb_Z # noqa: N806
Expand Down Expand Up @@ -394,6 +398,8 @@ def operator(self, t, w):
# need to check this
material_divisor = (
[self.epsilon]*elec_components+[self.mu]*mag_components)
else:
raise NotImplementedError("only fixed material supported for now")

tags_and_bcs = [
(self.pec_tag, self.pec_bc(w)),
Expand Down Expand Up @@ -567,9 +573,6 @@ def get_rectangular_cavity_mode(actx, nodes, t, E_0, mode_indices): # noqa: N80
cx = actx.np.cos(kx*x)
sy = actx.np.sin(ky*y)
cy = actx.np.cos(ky*y)
if dims == 3:
sz = actx.np.sin(kz*z)
cz = actx.np.cos(kz*z)

if dims == 2:
tfac = t * omega
Expand All @@ -584,7 +587,10 @@ def get_rectangular_cavity_mode(actx, nodes, t, E_0, mode_indices): # noqa: N80
* np.sin(tfac) / omega), # hy
zeros,
)
else:
elif dims == 3:
sz = actx.np.sin(kz*z)
cz = actx.np.cos(kz*z)

tdep = np.exp(-1j * omega * t)

gamma_squared = ky**2 + kx**2
Expand All @@ -596,6 +602,8 @@ def get_rectangular_cavity_mode(actx, nodes, t, E_0, mode_indices): # noqa: N80
1j * omega * kx*E_0*cx*sy*cz*tdep / gamma_squared,
zeros,
)
else:
raise NotImplementedError("only 2D and 3D supported")

return result

Expand Down
10 changes: 9 additions & 1 deletion test/test_grudge.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def test_face_normal_surface(actx_factory, mesh_name):
dof_desc.FACE_RESTR_INTERIOR, dof_desc.VTAG_ALL)
)(face_normal_i)

if mesh.ambient_dim == 3:
if ambient_dim == 3:
from grudge.geometry import pseudoscalar, area_element
# NOTE: there's only one face tangent in 3d
face_tangent = (
Expand Down Expand Up @@ -884,6 +884,8 @@ def rhs(t, w):

logger.info("dt %.5e nsteps %5d", dt, nsteps)

esc = None

step = 0
for event in dt_stepper.run(t_end=final_t):
if isinstance(event, dt_stepper.StateComputed):
Expand Down Expand Up @@ -1045,6 +1047,8 @@ def test_norm_real(actx_factory, p):
ref_norm = (1/3)**0.5
elif p == np.inf:
ref_norm = 1
else:
raise AssertionError("unsupported p")

logger.info("norm: %.5e %.5e", norm, ref_norm)
assert abs(norm-ref_norm) / abs(ref_norm) < 1e-13
Expand All @@ -1066,6 +1070,8 @@ def test_norm_complex(actx_factory, p):
ref_norm = (2/3)**0.5
elif p == np.inf:
ref_norm = 2**0.5
else:
raise AssertionError("unsupported p")

logger.info("norm: %.5e %.5e", norm, ref_norm)
assert abs(norm-ref_norm) / abs(ref_norm) < 1e-13
Expand All @@ -1088,6 +1094,8 @@ def test_norm_obj_array(actx_factory, p):
ref_norm = (dim/3)**0.5
elif p == np.inf:
ref_norm = 1
else:
raise AssertionError("unsupported p")

logger.info("norm: %.5e %.5e", norm, ref_norm)
assert abs(norm-ref_norm) / abs(ref_norm) < 1e-14
Expand Down

0 comments on commit 5b73a2b

Please sign in to comment.