Skip to content

Commit

Permalink
refactor(triangle): raise if output files not found
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed Sep 19, 2023
1 parent 2fa32da commit d95635b
Showing 1 changed file with 4 additions and 25 deletions.
29 changes: 4 additions & 25 deletions flopy/utils/triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def __init__(
self._nodes = nodes
self.additional_args = additional_args
self._initialize_vars()
return

def add_polygon(self, polygon):
"""
Expand Down Expand Up @@ -90,7 +89,6 @@ def add_polygon(self, polygon):
if len(polygon) > 1:
for hole in polygon[1:]:
self.add_hole(hole)
return

def add_hole(self, hole):
"""
Expand All @@ -107,7 +105,6 @@ def add_hole(self, hole):
"""
self._holes.append(hole)
return

def add_region(self, point, attribute=0, maximum_area=None):
"""
Expand All @@ -131,7 +128,6 @@ def add_region(self, point, attribute=0, maximum_area=None):
"""
self._regions.append([point, attribute, maximum_area])
return

def build(self, verbose=False):
"""
Expand Down Expand Up @@ -196,8 +192,6 @@ def build(self, verbose=False):
for row in self.ele:
self.iverts.append([row[1], row[2], row[3]])

return

def plot(
self,
ax=None,
Expand Down Expand Up @@ -320,7 +314,6 @@ def plot_boundary(self, ibm, ax=None, **kwargs):
y1 = self.node["y"][iv1]
y2 = self.node["y"][iv2]
ax.plot([x1, x2], [y1, y2], **kwargs)
return

def plot_vertices(self, ax=None, **kwargs):
"""
Expand All @@ -342,7 +335,6 @@ def plot_vertices(self, ax=None, **kwargs):
if ax is None:
ax = plt.gca()
ax.plot(self.node["x"], self.node["y"], lw=0, **kwargs)
return

def label_vertices(self, ax=None, onebased=True, **kwargs):
"""
Expand Down Expand Up @@ -374,7 +366,6 @@ def label_vertices(self, ax=None, onebased=True, **kwargs):
if onebased:
s += 1
ax.text(x, y, str(s), **kwargs)
return

def plot_centroids(self, ax=None, **kwargs):
"""
Expand All @@ -397,7 +388,6 @@ def plot_centroids(self, ax=None, **kwargs):
ax = plt.gca()
xcyc = self.get_xcyc()
ax.plot(xcyc[:, 0], xcyc[:, 1], lw=0, **kwargs)
return

def label_cells(self, ax=None, onebased=True, **kwargs):
"""
Expand Down Expand Up @@ -430,7 +420,6 @@ def label_cells(self, ax=None, onebased=True, **kwargs):
if onebased:
s += 1
ax.text(x, y, str(s), **kwargs)
return

def get_xcyc(self):
"""
Expand Down Expand Up @@ -600,7 +589,6 @@ def clean(self):
os.remove(fname)
if os.path.isfile(fname):
print(f"Could not remove: {fname}")
return

def _initialize_vars(self):
self.file_prefix = "_triangle"
Expand All @@ -613,16 +601,14 @@ def _initialize_vars(self):
self.verts = None
self.iverts = None
self.edgedict = None
return

def _load_results(self):
# node file
ext = "node"
dt = [("ivert", int), ("x", float), ("y", float)]
fname = os.path.join(self.model_ws, f"{self.file_prefix}.1.{ext}")
setattr(self, ext, None)
if os.path.isfile(fname):
f = open(fname, "r")
with open(fname, "r") as f:
line = f.readline()
f.close()
ll = line.strip().split()
Expand All @@ -644,8 +630,7 @@ def _load_results(self):
dt = [("icell", int), ("iv1", int), ("iv2", int), ("iv3", int)]
fname = os.path.join(self.model_ws, f"{self.file_prefix}.1.{ext}")
setattr(self, ext, None)
if os.path.isfile(fname):
f = open(fname, "r")
with open(fname, "r") as f:
line = f.readline()
f.close()
ll = line.strip().split()
Expand All @@ -664,8 +649,7 @@ def _load_results(self):
dt = [("iedge", int), ("endpoint1", int), ("endpoint2", int)]
fname = os.path.join(self.model_ws, f"{self.file_prefix}.1.{ext}")
setattr(self, ext, None)
if os.path.isfile(fname):
f = open(fname, "r")
with open(fname, "r") as f:
line = f.readline()
f.close()
ll = line.strip().split()
Expand All @@ -687,8 +671,7 @@ def _load_results(self):
]
fname = os.path.join(self.model_ws, f"{self.file_prefix}.1.{ext}")
setattr(self, ext, None)
if os.path.isfile(fname):
f = open(fname, "r")
with open(fname, "r") as f:
line = f.readline()
f.close()
ll = line.strip().split()
Expand All @@ -699,8 +682,6 @@ def _load_results(self):
assert a.shape[0] == ncells
setattr(self, ext, a)

return

def _write_nodefile(self, fname):
f = open(fname, "w")
nvert = 0
Expand Down Expand Up @@ -776,7 +757,6 @@ def _write_polyfile(self, fname):
f.write(s)

f.close()
return

def _create_edge_dict(self):
"""
Expand All @@ -789,4 +769,3 @@ def _create_edge_dict(self):
edgedict[(iv1, iv2)] = iseg
edgedict[(iv2, iv1)] = iseg
self.edgedict = edgedict
return

0 comments on commit d95635b

Please sign in to comment.