Skip to content

Commit

Permalink
Merge pull request #1606 from OceanParcels/using_particledlon_in_cfun…
Browse files Browse the repository at this point in the history
…c_header_test

Fixing customed_Cfunc_header_test to use particle_dlon
  • Loading branch information
erikvansebille authored Jul 22, 2024
2 parents 85f52df + 5cf9de1 commit e7ad17b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
4 changes: 2 additions & 2 deletions tests/customed_header.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

static inline StatusCode func(CField *f, double *lon, double *dt)
static inline StatusCode func(CField *f, double *particle_dlon, double *dt)
{
float data2D[2][2][2];
StatusCode status = getCell2D(f, 1, 2, 0, data2D, 1); CHECKSTATUS(status);
float u = data2D[0][0][0];
*lon += u * *dt;
*particle_dlon = +u * *dt;
return SUCCESS;
}
16 changes: 5 additions & 11 deletions tests/test_kernel_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,29 +346,23 @@ def func(U, lon, dt):

if c_inc == 'str':
c_include = """
static inline StatusCode func(CField *f, float *lon, double *dt)
static inline StatusCode func(CField *f, double *particle_dlon, double *dt)
{
float data2D[2][2][2];
StatusCode status = getCell2D(f, 1, 2, 0, data2D, 1); CHECKSTATUS(status);
float u = data2D[0][0][0];
*lon += u * *dt;
*particle_dlon = +u * *dt;
return SUCCESS;
}
"""
else:
c_include = path.join(path.dirname(__file__), 'customed_header.h')

def ckernel(particle, fieldset, time):
func('parcels_customed_Cfunc_pointer_args', fieldset.U, particle.lon, particle.dt)
func('parcels_customed_Cfunc_pointer_args', fieldset.U, particle_dlon, particle.dt) # noqa

def pykernel(particle, fieldset, time):
particle_dlon = func(fieldset.U, particle.lon, particle.dt) # noqa

if mode == 'scipy':
kernel = pset.Kernel(pykernel)
else:
kernel = pset.Kernel(ckernel, c_include=c_include)
pset.execute(kernel, endtime=3., dt=3.)
kernel = pset.Kernel(ckernel, c_include=c_include)
pset.execute(kernel, endtime=4., dt=1.)
assert np.allclose(pset.lon[0], 0.81578948)


Expand Down

0 comments on commit e7ad17b

Please sign in to comment.