Skip to content

Commit 8da816a

Browse files
zingaleyut23
andauthored
some pylint-ing on mesh/ (#120)
Co-authored-by: Eric Johnson <yut23@users.noreply.github.com>
1 parent 6cbe5fc commit 8da816a

File tree

5 files changed

+57
-71
lines changed

5 files changed

+57
-71
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[flake8]
2-
max-line-length = 120
2+
max-line-length = 132
33
ignore = E126, E127, E128, E129, E226, E241, E265, E741, F401, F403, F841, W504, W291
44
exclude = docs/,lm_combustion,radhydro

pyro/mesh/array_indexer.py

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class ArrayIndexer(np.ndarray):
3131
3232
"""
3333

34-
def __new__(self, d, grid=None):
35-
obj = np.asarray(d).view(self)
34+
def __new__(cls, d, grid=None):
35+
obj = np.asarray(d).view(cls)
3636
obj.g = grid
3737
obj.c = len(d.shape)
3838

@@ -86,9 +86,9 @@ def ip_jp(self, ishift, jshift, buf=0, n=0, s=1):
8686
if c == 2:
8787
return np.asarray(self[self.g.ilo-bxlo+ishift:self.g.ihi+1+bxhi+ishift:s,
8888
self.g.jlo-bylo+jshift:self.g.jhi+1+byhi+jshift:s])
89-
else:
90-
return np.asarray(self[self.g.ilo-bxlo+ishift:self.g.ihi+1+bxhi+ishift:s,
91-
self.g.jlo-bylo+jshift:self.g.jhi+1+byhi+jshift:s, n])
89+
90+
return np.asarray(self[self.g.ilo-bxlo+ishift:self.g.ihi+1+bxhi+ishift:s,
91+
self.g.jlo-bylo+jshift:self.g.jhi+1+byhi+jshift:s, n])
9292

9393
def lap(self, n=0, buf=0):
9494
"""return the 5-point Laplacian"""
@@ -107,10 +107,9 @@ def norm(self, n=0):
107107
return np.sqrt(self.g.dx * self.g.dy *
108108
np.sum((self[self.g.ilo:self.g.ihi+1, self.g.jlo:self.g.jhi+1]**2).flat))
109109

110-
else:
111-
_tmp = self[:, :, n]
112-
return np.sqrt(self.g.dx * self.g.dy *
113-
np.sum((_tmp[self.g.ilo:self.g.ihi+1, self.g.jlo:self.g.jhi+1]**2).flat))
110+
_tmp = self[:, :, n]
111+
return np.sqrt(self.g.dx * self.g.dy *
112+
np.sum((_tmp[self.g.ilo:self.g.ihi+1, self.g.jlo:self.g.jhi+1]**2).flat))
114113

115114
def copy(self):
116115
"""make a copy of the array, defined on the same grid"""
@@ -341,8 +340,8 @@ class ArrayIndexerFC(ArrayIndexer):
341340
342341
"""
343342

344-
def __new__(self, d, idir, grid=None):
345-
obj = np.asarray(d).view(self)
343+
def __new__(cls, d, idir, grid=None):
344+
obj = np.asarray(d).view(cls)
346345
obj.g = grid
347346
obj.idir = idir
348347
obj.c = len(d.shape)
@@ -375,17 +374,15 @@ def ip_jp(self, ishift, jshift, buf=0, n=0, s=1):
375374
if c == 2:
376375
return np.asarray(self[self.g.ilo-bxlo+ishift:self.g.ihi+2+bxhi+ishift:s,
377376
self.g.jlo-bylo+jshift:self.g.jhi+1+byhi+jshift:s])
378-
else:
379-
return np.asarray(self[self.g.ilo-bxlo+ishift:self.g.ihi+2+bxhi+ishift:s,
380-
self.g.jlo-bylo+jshift:self.g.jhi+1+byhi+jshift:s, n])
381-
elif self.idir == 2:
377+
return np.asarray(self[self.g.ilo-bxlo+ishift:self.g.ihi+2+bxhi+ishift:s,
378+
self.g.jlo-bylo+jshift:self.g.jhi+1+byhi+jshift:s, n])
379+
else: # idir == 2
382380
# face-centered in y
383381
if c == 2:
384382
return np.asarray(self[self.g.ilo-bxlo+ishift:self.g.ihi+1+bxhi+ishift:s,
385383
self.g.jlo-bylo+jshift:self.g.jhi+2+byhi+jshift:s])
386-
else:
387-
return np.asarray(self[self.g.ilo-bxlo+ishift:self.g.ihi+1+bxhi+ishift:s,
388-
self.g.jlo-bylo+jshift:self.g.jhi+2+byhi+jshift:s, n])
384+
return np.asarray(self[self.g.ilo-bxlo+ishift:self.g.ihi+1+bxhi+ishift:s,
385+
self.g.jlo-bylo+jshift:self.g.jhi+2+byhi+jshift:s, n])
389386

390387
def lap(self, n=0, buf=0):
391388
raise NotImplementedError("lap not implemented for ArrayIndexerFC")
@@ -402,19 +399,18 @@ def norm(self, n=0):
402399
return np.sqrt(self.g.dx * self.g.dy *
403400
np.sum((self[self.g.ilo:self.g.ihi+2, self.g.jlo:self.g.jhi+1]**2).flat))
404401

405-
else:
406-
_tmp = self[:, :, n]
407-
return np.sqrt(self.g.dx * self.g.dy *
408-
np.sum((_tmp[self.g.ilo:self.g.ihi+2, self.g.jlo:self.g.jhi+1]**2).flat))
409-
elif self.idir == 2:
410-
if c == 2:
411-
return np.sqrt(self.g.dx * self.g.dy *
412-
np.sum((self[self.g.ilo:self.g.ihi+1, self.g.jlo:self.g.jhi+2]**2).flat))
402+
_tmp = self[:, :, n]
403+
return np.sqrt(self.g.dx * self.g.dy *
404+
np.sum((_tmp[self.g.ilo:self.g.ihi+2, self.g.jlo:self.g.jhi+1]**2).flat))
413405

414-
else:
415-
_tmp = self[:, :, n]
416-
return np.sqrt(self.g.dx * self.g.dy *
417-
np.sum((_tmp[self.g.ilo:self.g.ihi+1, self.g.jlo:self.g.jhi+2]**2).flat))
406+
# idir == 2
407+
if c == 2:
408+
return np.sqrt(self.g.dx * self.g.dy *
409+
np.sum((self[self.g.ilo:self.g.ihi+1, self.g.jlo:self.g.jhi+2]**2).flat))
410+
411+
_tmp = self[:, :, n]
412+
return np.sqrt(self.g.dx * self.g.dy *
413+
np.sum((_tmp[self.g.ilo:self.g.ihi+1, self.g.jlo:self.g.jhi+2]**2).flat))
418414

419415
def copy(self):
420416
"""make a copy of the array, defined on the same grid"""

pyro/mesh/boundary.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ def define_bc(bc_type, function, is_solid=False):
3535
def _set_reflect(odd_reflect_dir, dir_string):
3636
if odd_reflect_dir == dir_string:
3737
return "reflect-odd"
38-
else:
39-
return "reflect-even"
38+
return "reflect-even"
4039

4140

4241
class BCProp:
@@ -157,31 +156,31 @@ def __init__(self,
157156
if self.xlb == "reflect":
158157
self.xlb = _set_reflect(odd_reflect_dir, "x")
159158
else:
160-
msg.fail("ERROR: xlb = %s invalid BC" % (xlb))
159+
msg.fail(f"ERROR: xlb = {xlb} invalid BC")
161160

162161
# +x boundary
163162
if xrb in valid:
164163
self.xrb = xrb
165164
if self.xrb == "reflect":
166165
self.xrb = _set_reflect(odd_reflect_dir, "x")
167166
else:
168-
msg.fail("ERROR: xrb = %s invalid BC" % (xrb))
167+
msg.fail(f"ERROR: xrb = {xrb} invalid BC")
169168

170169
# -y boundary
171170
if ylb in valid:
172171
self.ylb = ylb
173172
if self.ylb == "reflect":
174173
self.ylb = _set_reflect(odd_reflect_dir, "y")
175174
else:
176-
msg.fail("ERROR: ylb = %s invalid BC" % (ylb))
175+
msg.fail(f"ERROR: ylb = {ylb} invalid BC")
177176

178177
# +y boundary
179178
if yrb in valid:
180179
self.yrb = yrb
181180
if self.yrb == "reflect":
182181
self.yrb = _set_reflect(odd_reflect_dir, "y")
183182
else:
184-
msg.fail("ERROR: yrb = %s invalid BC" % (yrb))
183+
msg.fail(f"ERROR: yrb = {yrb} invalid BC")
185184

186185
# periodic checks
187186
if ((xlb == "periodic" and xrb != "periodic") or
@@ -207,7 +206,6 @@ def __init__(self,
207206
def __str__(self):
208207
""" print out some basic information about the BC object """
209208

210-
string = "BCs: -x: %s +x: %s -y: %s +y: %s" % \
211-
(self.xlb, self.xrb, self.ylb, self.yrb)
209+
string = f"BCs: -x: {self.xlb} +x: {self.xrb} -y: {self.ylb} +y: {self.yrb}"
212210

213211
return string

pyro/mesh/patch.py

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ def fine_like(self, N):
174174

175175
def __str__(self):
176176
""" print out some basic information about the grid object """
177-
return "2-d grid: nx = {}, ny = {}, ng = {}".format(
178-
self.nx, self.ny, self.ng)
177+
return f"2-d grid: nx = {self.nx}, ny = {self.ny}, ng = {self.ng}"
179178

180179
def __eq__(self, other):
181180
""" are two grids equivalent? """
@@ -336,19 +335,15 @@ def __str__(self):
336335
my_str = "CellCenterData2d object not yet initialized"
337336
return my_str
338337

339-
my_str = "cc data: nx = {}, ny = {}, ng = {}\n".format(
340-
self.grid.nx, self.grid.ny, self.grid.ng)
338+
my_str = f"cc data: nx = {self.grid.nx}, ny = {self.grid.ny}, ng = {self.grid.ng}\n"
341339
my_str += f" nvars = {self.nvar}\n"
342340
my_str += " variables:\n"
343341

344342
for n in range(self.nvar):
345-
my_str += "%16s: min: %15.10f max: %15.10f\n" % \
346-
(self.names[n], self.min(self.names[n]), self.max(self.names[n]))
347-
my_str += "%16s BCs: -x: %-12s +x: %-12s -y: %-12s +y: %-12s\n" %\
348-
(" ", self.BCs[self.names[n]].xlb,
349-
self.BCs[self.names[n]].xrb,
350-
self.BCs[self.names[n]].ylb,
351-
self.BCs[self.names[n]].yrb)
343+
name = self.names[n]
344+
my_str += f"{name:>16s}: min: {self.min(name):15.10f} max: {self.max(name):15.10f}\n"
345+
my_str += f"{' ':>16s} BCs: -x: {self.BCs[name].xlb:12s} +x: {self.BCs[name].xrb:12s}"
346+
my_str += f" -y: {self.BCs[name].ylb:12s} +y: {self.BCs[name].yrb:12s}\n"
352347

353348
return my_str
354349

@@ -434,7 +429,7 @@ def get_aux(self, keyword):
434429
The value corresponding to the keyword
435430
436431
"""
437-
if keyword in self.aux.keys():
432+
if keyword in self.aux:
438433
return self.aux[keyword]
439434

440435
return None
@@ -482,22 +477,22 @@ def fill_BC(self, name):
482477

483478
# that will handle the standard type of BCs, but if we asked
484479
# for a custom BC, we handle it here
485-
if self.BCs[name].xlb in bnd.ext_bcs.keys():
480+
if self.BCs[name].xlb in bnd.ext_bcs:
486481
try:
487482
bnd.ext_bcs[self.BCs[name].xlb](self.BCs[name].xlb, "xlb", name, self, self.ivars)
488483
except TypeError:
489484
bnd.ext_bcs[self.BCs[name].xlb](self.BCs[name].xlb, "xlb", name, self)
490-
if self.BCs[name].xrb in bnd.ext_bcs.keys():
485+
if self.BCs[name].xrb in bnd.ext_bcs:
491486
try:
492487
bnd.ext_bcs[self.BCs[name].xrb](self.BCs[name].xrb, "xrb", name, self)
493488
except TypeError:
494489
bnd.ext_bcs[self.BCs[name].xrb](self.BCs[name].xrb, "xrb", name, self, self.ivars)
495-
if self.BCs[name].ylb in bnd.ext_bcs.keys():
490+
if self.BCs[name].ylb in bnd.ext_bcs:
496491
try:
497492
bnd.ext_bcs[self.BCs[name].ylb](self.BCs[name].ylb, "ylb", name, self)
498493
except TypeError:
499494
bnd.ext_bcs[self.BCs[name].ylb](self.BCs[name].ylb, "ylb", name, self, self.ivars)
500-
if self.BCs[name].yrb in bnd.ext_bcs.keys():
495+
if self.BCs[name].yrb in bnd.ext_bcs:
501496
try:
502497
bnd.ext_bcs[self.BCs[name].yrb](self.BCs[name].yrb, "yrb", name, self)
503498
except TypeError:
@@ -725,19 +720,15 @@ def __str__(self):
725720
my_str = "FaceCenterData2d object not yet initialized"
726721
return my_str
727722

728-
my_str = "fc data: idir = {}, nx = {}, ny = {}, ng = {}\n".format(
729-
self.idir, self.grid.nx, self.grid.ny, self.grid.ng)
723+
my_str = f"fc data: idir = {self.idir}, nx = {self.grid.nx}, ny = {self.grid.ny}, ng = {self.grid.ng}\n"
730724
my_str += f" nvars = {self.nvar}\n"
731725
my_str += " variables:\n"
732726

733727
for n in range(self.nvar):
734-
my_str += "%16s: min: %15.10f max: %15.10f\n" % \
735-
(self.names[n], self.min(self.names[n]), self.max(self.names[n]))
736-
my_str += "%16s BCs: -x: %-12s +x: %-12s -y: %-12s +y: %-12s\n" %\
737-
(" ", self.BCs[self.names[n]].xlb,
738-
self.BCs[self.names[n]].xrb,
739-
self.BCs[self.names[n]].ylb,
740-
self.BCs[self.names[n]].yrb)
728+
name = self.names[n]
729+
my_str += f"{name:>16s}: min: {self.min(name):15.10f} max: {self.max(name):15.10f}\n"
730+
my_str += f"{' ':>16s} BCs: -x: {self.BCs[name].xlb:12s} +x: {self.BCs[name].xrb:12s}"
731+
my_str += f" -y: {self.BCs[name].ylb:12s} +y: {self.BCs[name].yrb:12s}\n"
741732

742733
return my_str
743734

@@ -794,10 +785,10 @@ def fill_BC(self, name):
794785
n = self.names.index(name)
795786
self.data.fill_ghost(n=n, bc=self.BCs[name])
796787

797-
if self.BCs[name].xlb in bnd.ext_bcs.keys() or \
798-
self.BCs[name].xrb in bnd.ext_bcs.keys() or \
799-
self.BCs[name].ylb in bnd.ext_bcs.keys() or \
800-
self.BCs[name].yrb in bnd.ext_bcs.keys():
788+
if self.BCs[name].xlb in bnd.ext_bcs or \
789+
self.BCs[name].xrb in bnd.ext_bcs or \
790+
self.BCs[name].ylb in bnd.ext_bcs or \
791+
self.BCs[name].yrb in bnd.ext_bcs:
801792
raise NotImplementedError("custom boundary conditions not supported for FaceCenterData2d")
802793

803794
def restrict(self, varname, N=2):

pyro/mesh/reconstruction.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ def limit(data, myg, idir, limiter):
1111
of the limiter input variable."""
1212
if limiter == 0:
1313
return nolimit(data, myg, idir)
14-
elif limiter == 1:
14+
15+
if limiter == 1:
1516
return limit2(data, myg, idir)
16-
else:
17-
return limit4(data, myg, idir)
17+
18+
return limit4(data, myg, idir)
1819

1920

2021
def well_balance(q, myg, limiter, iv, grav):

0 commit comments

Comments
 (0)