-
Notifications
You must be signed in to change notification settings - Fork 314
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
fix(get_structured_faceflows): cover edge cases, expand tests #1968
fix(get_structured_faceflows): cover edge cases, expand tests #1968
Conversation
* reproduce and fix provided 2D model * stub simpler parametrized 2D tests * add freyberg mf6/mf2005 comparison
Codecov Report
@@ Coverage Diff @@
## develop #1968 +/- ##
=======================================
Coverage 72.6% 72.7%
=======================================
Files 257 257
Lines 57800 57809 +9
=======================================
+ Hits 42017 42063 +46
+ Misses 15783 15746 -37
|
Not sure if this would be any clearer, but scrolling through k, i, j seems a bit more intuitive to me. Just a thought. I didn't fully test, so there could be a sign issue with the flows. I think the convention is positive for leaving the k, i, j cell. Feel free to scrap if this is wrong or unclear. # requires nlay, nrow, ncol, ia, ja, flowja be in scope
frf = np.zeros((nlay, nrow, ncol))
fff = np.zeros((nlay, nrow, ncol))
flf = np.zeros((nlay, nrow, ncol))
def get_node(k, i, j):
return j + i * ncol + k * nrow * ncol
def get_flow(n, m, ia, ja, flowja):
for ipos in range(ia[n] + 1, ia[n + 1]):
if m == ja[ipos]:
return flowja[ipos]
return 0.
for k in range(nlay):
for i in range(nrow):
for j in range(ncol):
# get node number for k, i, j
n = get_node(k, i, j)
# fill flow to right (positive to east)
if j < ncol - 1:
m = get_node(k, i, j + 1)
frf[k, i, j] = -get_flow(n, m, ia, ja, flowja)
# fill flow to front (positive to south)
if i < nrow - 1:
m = get_node(k, i + 1, j)
fff[k, i, j] = -get_flow(n, m, ia, ja, flowja)
# fill flow to lower (positive flow upward)
if k < nlay - 1:
m = get_node(k + 1, i, j)
flf[k, i, j] = -get_flow(n, m, ia, ja, flowja) |
@langevin-usgs your proposed version passes all tests. I agree iterating cell indices (k, i, j) is easier to understand than nodes / CSR matrix entries. I did a quick benchmark. The grid shape (nlay, nrow, ncol) is in the name column, all times are ms.
Iterating nodes is generally faster than indices. I suspect the inner loop checking up to 6 neighbors to find the correct one in |
Hey @wpbonelli, thanks for running the tests. I'm not sure we can avoid the inner loop with this k,i,j indexing. If any of the adjacent cells for cell |
* reproduce and fix provided 2D model * stub simpler parametrized 2D tests * add freyberg mf6/mf2005 comparison * move get_face into get_structured_faceflows * remove og repro (covered by parametrized test)
nlay
/nrow
/ncol
params (needed ifgrb_file
not provided)