Skip to content

Commit

Permalink
add modflow 6 input tests for ic, dis
Browse files Browse the repository at this point in the history
  • Loading branch information
mjreno authored and mjreno committed Jul 24, 2024
1 parent 8f82fb9 commit fb5230d
Show file tree
Hide file tree
Showing 13 changed files with 511 additions and 195 deletions.
17 changes: 3 additions & 14 deletions flopy4/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def __init__(
):
MFParam.__init__(
self,
shape=shape,
block=block,
name=name,
type=type,
Expand Down Expand Up @@ -405,26 +406,14 @@ def read_array(f):
Read a MODFLOW 6 array from an open file
into a flat NumPy array representation.
"""
import re

astr = []
while True:
pos = f.tell()
line = f.readline()
line = line_strip(line)
if line in (
CommonNames.empty,
CommonNames.internal,
CommonNames.external,
CommonNames.constant,
):
f.seek(pos, 0)
break
elif (
CommonNames.internal in line
or CommonNames.external in line
or CommonNames.constant in line
or CommonNames.end in line.upper()
):
if not re.match("^[0-9. ]+$", line):
f.seek(pos, 0)
break
astr.append(line)
Expand Down
5 changes: 4 additions & 1 deletion flopy4/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ def get_param(members, key, block):
param = ks[0]
else:
param = members.get(key)
param.name = key
if param is not None:
param.name = key
else:
raise ValueError(f"Invalid parameter: {key.upper()}")
param.block = block
return param

Expand Down
31 changes: 31 additions & 0 deletions spec/dfn/gwf-ic.dfn
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# --------------------- gwf ic options ---------------------

block options
name export_array_ascii
type keyword
reader urword
optional true
mf6internal export_ascii
longname export array variables to layered ascii files.
description keyword that specifies input griddata arrays should be written to layered ascii output files.

block options
name export_array_netcdf
type keyword
reader urword
optional true
mf6internal export_nc
longname export array variables to netcdf output files.
description keyword that specifies input griddata arrays should be written to the model output netcdf file.

# --------------------- gwf ic griddata ---------------------

block griddata
name strt
type double precision
shape (nodes)
reader readarray
layered true
longname starting head
description is the initial (starting) head---that is, head at the beginning of the GWF Model simulation. STRT must be specified for all simulations, including steady-state simulations. One value is read for every model cell. For simulations in which the first stress period is steady state, the values used for STRT generally do not affect the simulation (exceptions may occur if cells go dry and (or) rewet). The execution time, however, will be less if STRT includes hydraulic heads that are close to the steady-state solution. A head value lower than the cell bottom can be provided if a cell should start as dry.
default_value 1.0
41 changes: 4 additions & 37 deletions spec/dfn2toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(
d["block"][b][name] = block_d[p]

if self._multi_package:
d["multipkg"] = True
d["multi"] = True
if self._stress_package:
d["stress"] = True
if self._advanced_package:
Expand Down Expand Up @@ -201,40 +201,9 @@ def _substitute(self, blockname, component, subcomponent):
if "block_variable" in v and v["block_variable"].upper() == "TRUE":
continue

vtype = v["type"].upper()
if vtype == "DOUBLE PRECISION":
vtype = "DOUBLE"
recarray = vtype and vtype.startswith("RECARRAY")

vname = v["name"].upper()

shape = ""
shapelist = []
if "shape" in v:
shape = v["shape"]
shape = shape.replace("(", "")
shape = shape.replace(")", "")
shape = shape.replace(",", "")
shape = shape.upper()
if shape == "NCOL*NROW; NCPL":
if (
vname == "AUX"
and "reader" in v
and v["reader"] == "readarray"
):
shape = "NAUX NCPL"
else:
shape = "NCPL"
shapelist = shape.strip().split()

ndim = len(shapelist)
if (
shape != ""
and ndim > 0
and not recarray
and (vtype == "DOUBLE" or vtype == "INTEGER")
):
vtype = f"{vtype}{ndim}D"
vtype = v["type"].lower()
if vtype == "double precision":
vtype = "double"

d = None
d = mf6_param_dfn.copy()
Expand All @@ -249,8 +218,6 @@ def _substitute(self, blockname, component, subcomponent):
valid = v[k].strip().split()
if len(valid) > 0:
d[k] = valid.copy()
elif k == "shape":
d[k] = shape
elif k == "type":
d[k] = vtype
else:
Expand Down
1 change: 1 addition & 0 deletions spec/dfns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# gwf model
gwf-dis.dfn
gwf-ic.dfn

# gwt model
gwt-dis.dfn
Expand Down
48 changes: 24 additions & 24 deletions spec/toml/gwe-dis.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ stress = false
advanced = false

[block.options.length_units]
type = "STRING"
type = "string"
block_variable = false
valid = []
shape = ""
Expand All @@ -23,7 +23,7 @@ description = "is the length units used for this model. Values can be ``FEET'',
deprecated = ""

[block.options.nogrb]
type = "KEYWORD"
type = "keyword"
block_variable = false
valid = []
shape = ""
Expand All @@ -40,7 +40,7 @@ description = "keyword to deactivate writing of the binary grid file."
deprecated = ""

[block.options.xorigin]
type = "DOUBLE"
type = "double"
block_variable = false
valid = []
shape = ""
Expand All @@ -57,7 +57,7 @@ description = "x-position of the lower-left corner of the model grid. A default
deprecated = ""

[block.options.yorigin]
type = "DOUBLE"
type = "double"
block_variable = false
valid = []
shape = ""
Expand All @@ -74,7 +74,7 @@ description = "y-position of the lower-left corner of the model grid. If not sp
deprecated = ""

[block.options.angrot]
type = "DOUBLE"
type = "double"
block_variable = false
valid = []
shape = ""
Expand All @@ -91,7 +91,7 @@ description = "counter-clockwise rotation angle (in degrees) of the lower-left c
deprecated = ""

[block.options.export_array_ascii]
type = "KEYWORD"
type = "keyword"
block_variable = false
valid = []
shape = ""
Expand All @@ -108,7 +108,7 @@ description = "keyword that specifies input griddata arrays should be written to
deprecated = ""

[block.options.export_array_netcdf]
type = "KEYWORD"
type = "keyword"
block_variable = false
valid = []
shape = ""
Expand All @@ -125,7 +125,7 @@ description = "keyword that specifies input griddata arrays should be written to
deprecated = ""

[block.options.ncf_filerecord]
type = "RECORD NCF6 FILEIN NCF6_FILENAME"
type = "record ncf6 filein ncf6_filename"
block_variable = false
valid = []
shape = ""
Expand All @@ -142,7 +142,7 @@ description = ""
deprecated = ""

[block.options.ncf6]
type = "KEYWORD"
type = "keyword"
block_variable = false
valid = []
shape = ""
Expand All @@ -159,7 +159,7 @@ description = "keyword to specify that record corresponds to a netcdf configurat
deprecated = ""

[block.options.filein]
type = "KEYWORD"
type = "keyword"
block_variable = false
valid = []
shape = ""
Expand All @@ -176,7 +176,7 @@ description = "keyword to specify that an input filename is expected next."
deprecated = ""

[block.options.ncf6_filename]
type = "STRING"
type = "string"
block_variable = false
valid = []
shape = ""
Expand All @@ -193,7 +193,7 @@ description = "defines a netcdf configuration (NCF) input file."
deprecated = ""

[block.dimensions.nlay]
type = "INTEGER"
type = "integer"
block_variable = false
valid = []
shape = ""
Expand All @@ -211,7 +211,7 @@ description = "is the number of layers in the model grid."
deprecated = ""

[block.dimensions.nrow]
type = "INTEGER"
type = "integer"
block_variable = false
valid = []
shape = ""
Expand All @@ -229,7 +229,7 @@ description = "is the number of rows in the model grid."
deprecated = ""

[block.dimensions.ncol]
type = "INTEGER"
type = "integer"
block_variable = false
valid = []
shape = ""
Expand All @@ -247,10 +247,10 @@ description = "is the number of columns in the model grid."
deprecated = ""

[block.griddata.delr]
type = "DOUBLE1D"
type = "double"
block_variable = false
valid = []
shape = "NCOL"
shape = "(ncol)"
tagged = true
in_record = false
layered = false
Expand All @@ -265,10 +265,10 @@ description = "is the column spacing in the row direction."
deprecated = ""

[block.griddata.delc]
type = "DOUBLE1D"
type = "double"
block_variable = false
valid = []
shape = "NROW"
shape = "(nrow)"
tagged = true
in_record = false
layered = false
Expand All @@ -283,10 +283,10 @@ description = "is the row spacing in the column direction."
deprecated = ""

[block.griddata.top]
type = "DOUBLE2D"
type = "double"
block_variable = false
valid = []
shape = "NCOL NROW"
shape = "(ncol, nrow)"
tagged = true
in_record = false
layered = false
Expand All @@ -301,10 +301,10 @@ description = "is the top elevation for each cell in the top model layer."
deprecated = ""

[block.griddata.botm]
type = "DOUBLE3D"
type = "double"
block_variable = false
valid = []
shape = "NCOL NROW NLAY"
shape = "(ncol, nrow, nlay)"
tagged = true
in_record = false
layered = true
Expand All @@ -319,10 +319,10 @@ description = "is the bottom elevation for each cell."
deprecated = ""

[block.griddata.idomain]
type = "INTEGER3D"
type = "integer"
block_variable = false
valid = []
shape = "NCOL NROW NLAY"
shape = "(ncol, nrow, nlay)"
tagged = true
in_record = false
layered = true
Expand Down
Loading

0 comments on commit fb5230d

Please sign in to comment.