Skip to content
Snippets Groups Projects
Commit 4b5755c8 authored by Nils-Arne Dreier's avatar Nils-Arne Dreier
Browse files

add python bindings for compute_grid_cell_areas

parent 44ccc1f3
No related branches found
No related tags found
No related merge requests found
......@@ -756,6 +756,9 @@
<td style="vertical-align:top;width:33%">
<ul style="margin:0px">
<li> \ref yac::yac_fcompute_grid_cell_areas "yac_fcompute_grid_cell_areas (*)"
<td style="vertical-align:top;width:33%">
<ul style="margin:0px">
<li> \ref yac.YAC.Grid.compute_gril_cell_areas
<tr>
<td style="vertical-align:top;width:33%">
<ul style="margin:0px">
......
......@@ -366,6 +366,7 @@ cdef extern from "yac.h":
const char * filename,
int fileformat,
int sync_location);
void yac_ccompute_grid_cell_areas(int grid_id, double* cell_areas);
# helper functions for py interface (not in yac_interface.h)
cdef extern void yac_cget_comp_size_c2py(int comp_id, int* size)
......@@ -1034,6 +1035,16 @@ class Grid:
&mask_id )
return Mask(mask_id)
def compute_grid_cell_areas(self, cell_areas = None):
"""
@see yac_ccompute_grid_cell_areas
"""
if cell_areas is None:
cell_areas = _np.empty(self.nbr_cells)
cdef double[::1] np_cell_areas = _np.ascontiguousarray(cell_areas, dtype=_np.double)
yac_ccompute_grid_cell_areas(self.grid_id, &np_cell_areas[0])
return cell_areas
class Points:
"""
Stores the points_id and provides further functionality
......
......@@ -60,6 +60,7 @@ x.setflags(write=0) # require a const memoryview in Reg2d
grid1 = yac.Reg2dGrid("grid1", x, x)
grid1.set_global_index(range(9), yac.Location.CORNER)
grid1.set_global_index(np.arange(4, dtype=np.intc), yac.Location.CELL)
print(f"{grid1.compute_grid_cell_areas()=}")
assert grid1.nbr_cells == 4
assert grid1.nbr_corners == 9
assert grid1.nbr_edges == 12
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment