Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(triangle): raise if output files not found #1954

Merged
merged 2 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions autotest/test_triangle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import shutil
from os import environ
from platform import system

import pytest
from modflow_devtools.markers import requires_exe
from modflow_devtools.misc import set_env

import flopy
from flopy.utils.triangle import Triangle


@requires_exe("mf6")
def test_output_files_not_found(function_tmpdir):
tri = Triangle(model_ws=function_tmpdir, maximum_area=1.0, angle=30)

# if expected output files are not found,
# Triangle should raise FileNotFoundError
with pytest.raises(FileNotFoundError):
tri._load_results()
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
Loading