Skip to content

Commit 3dba2ae

Browse files
author
Rusty Holleman
committed
working wse and U depth average with new code
1 parent 618b132 commit 3dba2ae

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

stompy/model/openfoam/depth_average.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -926,14 +926,16 @@ def precalc_raster_weights_proc_by_faces(fld, xyz, face_nodes, face_cells, cell_
926926
# compile into matrix
927927

928928
mesh_state = (xyz,face_nodes,face_cells,cell_faces)
929+
n_cells_orig = len(cell_faces)
929930

930931
fld_x,fld_y = fld.xy() # I think these are pixel centers
931932

933+
cell_mapping=None
932934
for col in utils.progress(range(fld.shape[1])):
933935
if col==0: continue
934936
xmin=fld_x[col]-fld.dx/2
935937
xmax=fld_x[col]+fld.dx/2
936-
mesh_state = mesh_ops.mesh_slice(np.r_[1,0,0], xmin, *mesh_state)
938+
cell_mapping, mesh_state = mesh_ops.mesh_slice(np.r_[1,0,0], xmin, cell_mapping, *mesh_state)
937939

938940
if 0: # debugging checks
939941
print("Checking cells")
@@ -946,7 +948,7 @@ def precalc_raster_weights_proc_by_faces(fld, xyz, face_nodes, face_cells, cell_
946948
if row==0: continue
947949
ymin=fld_y[row]-fld.dy/2
948950
ymax=fld_y[row]+fld.dy/2
949-
mesh_state = mesh_ops.mesh_slice(np.r_[0,1,0], ymin, *mesh_state)
951+
cell_mapping, mesh_state = mesh_ops.mesh_slice(np.r_[0,1,0], ymin, cell_mapping, *mesh_state)
950952

951953
if 0: # debugging checks
952954
print("Checking cells after all slicing")
@@ -958,7 +960,7 @@ def precalc_raster_weights_proc_by_faces(fld, xyz, face_nodes, face_cells, cell_
958960
volumes,centers = mesh_ops.mesh_cell_volume_centers(*mesh_state)
959961

960962
raster_weights = sparse.dok_matrix((fld.F.shape[0]*fld.F.shape[1],
961-
centers.shape[0]),
963+
n_cells_orig),
962964
np.float64)
963965

964966
# check bounds, then compute clipped volume.
@@ -981,7 +983,7 @@ def precalc_raster_weights_proc_by_faces(fld, xyz, face_nodes, face_cells, cell_
981983

982984
for cIdx in np.nonzero(sel)[0]:
983985
# alpha-weighting is included per timestep
984-
raster_weights[pix,cIdx] = volumes[cIdx]/Apixel
986+
raster_weights[pix,cell_mapping[cIdx]] = volumes[cIdx]/Apixel
985987

986988
return raster_weights
987989

stompy/model/openfoam/mesh_ops.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,11 @@ def mesh_check_cell(cIdx,verbose,mesh_state):
227227
return np.all(np.array(outwards)>0)
228228

229229

230-
def mesh_slice(slice_normal, slice_offset, xyz, face_nodes, face_cells, cell_faces):
230+
def mesh_slice(slice_normal, slice_offset, cell_mapping, xyz, face_nodes, face_cells, cell_faces):
231231
tol = 1e-10
232+
if cell_mapping is None:
233+
cell_mapping = np.arange(len(cell_faces))
234+
232235
# identify which faces to slice:
233236
if 1:
234237
offset_xyz = np.dot(xyz,slice_normal) - slice_offset
@@ -495,7 +498,10 @@ def mesh_slice(slice_normal, slice_offset, xyz, face_nodes, face_cells, cell_fac
495498
# bad here.
496499
if f_i==0 and side_xyz[f_nodes[f_i+1]]!=0:
497500
# last-to-first edge is the one.
498-
assert f_nodes[-1]>=n_node_orig,"More trouble with slice nodes"
501+
# pretty sure this overly restrictive. face could have come in with a node
502+
# on the slice. Even if it's a new face, one of the nodes could have already
503+
# been on the slice.
504+
#assert f_nodes[-1]>=n_node_orig,"More trouble with slice nodes"
499505
nodeA = f_nodes[-1]
500506
nodeB = f_nodes[0]
501507
assert nodeA!=nodeB
@@ -563,6 +569,7 @@ def mesh_slice(slice_normal, slice_offset, xyz, face_nodes, face_cells, cell_fac
563569
new_cIdx = len(cell_faces)
564570
cell_faces[cIdx,:] = cell_face_neg
565571
cell_faces = utils.array_append(cell_faces,cell_face_pos)
572+
cell_mapping = utils.array_append(cell_mapping, cell_mapping[cIdx])
566573
face_cells = utils.array_append(face_cells,np.array([cIdx,new_cIdx]))
567574

568575
#import pdb
@@ -602,7 +609,7 @@ def mesh_slice(slice_normal, slice_offset, xyz, face_nodes, face_cells, cell_fac
602609
else:
603610
assert False,"Failed to find face to flip"
604611

605-
return (xyz, face_nodes, face_cells, cell_faces)
612+
return cell_mapping, (xyz, face_nodes, face_cells, cell_faces)
606613

607614

608615
def mesh_cell_bboxes(xyz,face_nodes,face_cells,cell_faces):

0 commit comments

Comments
 (0)