Skip to content

Commit

Permalink
Added substitute data component data files for nutrient components #93
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjbr123 committed Feb 23, 2024
1 parent 1bae8a2 commit a0c3bd8
Show file tree
Hide file tree
Showing 47 changed files with 659 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/data/dummy_openwater_diff_t_substitute_data_2daily_1deg.nc
Binary file not shown.
Binary file not shown.
Binary file modified tests/data/dummy_openwater_same_t_substitute_data_daily_1deg.nc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/data/dummy_subsurface_same_t_substitute_data_daily_1deg.nc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions tests/tests/components/nutrientopenwater/dummyc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

all: clean lib

lib:
python setup.py build_ext --inplace
rm -rf ./build
rm dummyc.c

clean:
rm -rf *.so
Empty file.
87 changes: 87 additions & 0 deletions tests/tests/components/nutrientopenwater/dummyc/dummy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
void initialise_(int ny, int nx,
// component constants,
double constant_d,
// component states
double *state_a_m1)
{
int j, k, l, m;
int nv, nw;
int jklm;

// dimensions for state division
nw = 4;
nv = constant_d;

for (j=0; j < ny; j++)
for (k=0; k < nx; k++)
for (l=0; l < nw; l++)
for (m=0; m < nv; m++)
{
// vectorisation of 5d-array
jklm = m + nv * (l + nw * (k + nx * j));
// initialise states
state_a_m1[jklm] = 0.0;
}
}

void run_(int ny, int nx,
// to exchanger
double *transfer_b, double *transfer_e, double *transfer_p
// component ancillary data
double *ancillary_d,
// component parameters
double *parameter_e,
// component states
double *state_a_m1, double *state_a_0,
// component constants,
double constant_d,
// from exchanger
double *transfer_d, double *transfer_f, double *transfer_g,
// component outputs
double *output_x, double *output_y)
{
int h, j, k, l, m;
int nv, nw;
int jklm, hjk, jk;

// time dimension for monthly ancillary
h = 11;

// dimensions for state division
nw = 4;
nv = constant_d;

for (j=0; j < ny; j++)
for (k=0; k < nx; k++)
{
// vectorisation of 3d-array (space with time)
hjk = k + nx * (j + ny * h);
// vectorisation of 2d-array (space without time)
jk = k + nx * j;
// update states
for (l=0; l < nw; l++)
for (m=0; m < nv; m++)
{
// vectorisation of 5d-array
jklm = m + nv * (l + nw * (k + nx * j));
// initialise states
state_a_0[jklm] = state_a_m1[jklm] + 1;
}
// vectorisation of 5d-array
l = 0;
m = 0;
jklm = m + nv * (l + nw * (k + nx * j));
// compute transfers to exchanger
transfer_d[jk] = (ancillary_d[hjk] * transfer_e[jk])
+ state_a_0[jklm];
transfer_f[jk] = parameter_e[jk] * transfer_b[jk];
transfer_g[jk] = constant_d + transfer_b[jk];
// compute outputs
output_x[jk] = (parameter_e[jk] * transfer_b[jk]) + constant_d;
output_y[jk] = (ancillary_d[jk] * transfer_e[jk])
- state_a_0[jklm] + transfer_p[jk];
}
}

void finalise_(void)
{}
9 changes: 9 additions & 0 deletions tests/tests/components/nutrientopenwater/dummyc/dummy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
void initialise_(int ny, int nx, double constant_d, double *state_a_m1);

void run_(int ny, int nx, double *transfer_b, double *transfer_e,
double *transfer_p, double *ancillary_d, double *parameter_e,
double *state_a_m1, double *state_a_0, double constant_d,
double *transfer_d, double *transfer_f, double *transfer_g,
double *output_x, double *output_y);

void finalise_(void);
58 changes: 58 additions & 0 deletions tests/tests/components/nutrientopenwater/dummyc/dummyc.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import numpy as np
cimport numpy as cnp

cdef extern from "dummy.h":

void initialise_(int ny, int nx, double constant_d,
double *state_a_m1)

void run_(int ny, int nx, double *transfer_b, double *transfer_e,
double *transfer_p, double *ancillary_d, double *parameter_e,
double *state_a_m1, double *state_a_0, double constant_d,
double *transfer_d, double *transfer_f, double *transfer_g,
double *output_x, double *output_y)

void finalise_()

def initialise(double constant_d,
cnp.ndarray[cnp.npy_float64, ndim=4] state_a_m1):

cdef int ny = state_a_m1.shape[0]
cdef int nx = state_a_m1.shape[1]

initialise_(ny, nx, constant_d, &state_a_m1[0, 0, 0, 0])

def run(cnp.ndarray[cnp.npy_float64, ndim=2] transfer_b,
cnp.ndarray[cnp.npy_float64, ndim=2] transfer_e,
cnp.ndarray[cnp.npy_float64, ndim=2] transfer_p,
cnp.ndarray[cnp.npy_float64, ndim=3] ancillary_d,
cnp.ndarray[cnp.npy_float64, ndim=2] parameter_e,
cnp.ndarray[cnp.npy_float64, ndim=4] state_a_m1,
cnp.ndarray[cnp.npy_float64, ndim=4] state_a_0,
double constant_d):

cdef int ny = transfer_b.shape[0]
cdef int nx = transfer_b.shape[1]

cdef cnp.ndarray[cnp.npy_float64, ndim=2] transfer_d = np.zeros(
(ny, nx), dtype=np.float64)
cdef cnp.ndarray[cnp.npy_float64, ndim=2] transfer_f = np.zeros(
(ny, nx), dtype=np.float64)
cdef cnp.ndarray[cnp.npy_float64, ndim=2] transfer_g = np.zeros(
(ny, nx), dtype=np.float64)
cdef cnp.ndarray[cnp.npy_float64, ndim=2] output_x = np.zeros(
(ny, nx), dtype=np.float64)
cdef cnp.ndarray[cnp.npy_float64, ndim=2] output_y = np.zeros(
(ny, nx), dtype=np.float64)

run_(ny, nx, &transfer_b[0, 0], &transfer_e[0, 0], &transfer_p[0, 0],
&ancillary_d[0, 0, 0], &parameter_e[0, 0],
&state_a_m1[0, 0, 0, 0], &state_a_0[0, 0, 0, 0],
constant_d, &transfer_d[0, 0],
&transfer_f[0, 0], &transfer_g[0, 0],
&output_x[0, 0], &output_y[0, 0])

return transfer_d, transfer_f, transfer_g, output_x, output_y

def finalise():
finalise_()
7 changes: 7 additions & 0 deletions tests/tests/components/nutrientopenwater/dummyc/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from distutils.core import setup, Extension
from Cython.Build import cythonize
import numpy as np

ext = Extension(name="dummyc", sources=["dummyc.pyx", "dummy.c"])

setup(ext_modules=cythonize(ext, language_level="3"), include_dirs=[np.get_include()])
13 changes: 13 additions & 0 deletions tests/tests/components/nutrientopenwater/dummyfortran/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

all: clean sig lib

sig:
python -m numpy.f2py -m dummyfortran -h dummyfortran.pyf --overwrite-signature dummy.f90

lib:
rm -rf *.so
python -m numpy.f2py -c dummyfortran.pyf dummy.f90
rm -rf *.pyf

clean:
rm -rf *.pyf *.so
Empty file.
60 changes: 60 additions & 0 deletions tests/tests/components/nutrientopenwater/dummyfortran/dummy.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
subroutine initialise(y, x, constant_d, state_a_m1)
implicit none

! spaceshape
integer, intent(in) :: y, x
! component constants
integer, intent(in) :: constant_d
! component states
real(kind=8), intent(inout), dimension(y, x, 4, constant_d) :: state_a_m1

state_a_m1 = 0

end subroutine initialise

subroutine run(y, x, &
transfer_b, transfer_e, transfer_p, &
ancillary_d, &
parameter_e, &
state_a_m1, state_a_0, &
constant_d, &
transfer_d, transfer_f, transfer_g, &
output_x, output_y)

implicit none

! spaceshape
integer, intent(in) :: y, x
! from exchanger
real(kind=8), intent(in), dimension(y, x) :: transfer_b, transfer_e, transfer_p
! component ancillary data
real(kind=8), intent(in), dimension(12, y, x) :: ancillary_d
! component parameters
real(kind=8), intent(in), dimension(y, x) :: parameter_e
! component constants
integer, intent(in) :: constant_d
! component states
real(kind=8), intent(in), dimension(y, x, 4, constant_c) :: state_a_m1
real(kind=8), intent(inout), dimension(y, x, 4, constant_c) :: state_a_0
! to exchanger
real(kind=8), intent(out), dimension(y, x) :: &
transfer_d, transfer_f, transfer_g
! component outputs
real(kind=8), intent(out), dimension(y, x) :: &
output_x, output_y

state_a_0 = state_a_m1 + 1

transfer_d = (ancillary_d(12,:,:) * transfer_e) + state_a_0(:,:,1,1)
transfer_f = parameter_e * transfer_b
transfer_g = constant_d + transfer_b

output_x = (parameter_e * transfer_b) + constant_d
output_y = (ancillary_d(12,:,:) * transfer_e) - state_a_0(:,:,1,1) + transfer_p

end subroutine run

subroutine finalise()
implicit none

end subroutine finalise
10 changes: 10 additions & 0 deletions tests/tests/components/nutrientsubsurface/dummyc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

all: clean lib

lib:
python setup.py build_ext --inplace
rm -rf ./build
rm dummyc.c

clean:
rm -rf *.so
Empty file.
57 changes: 57 additions & 0 deletions tests/tests/components/nutrientsubsurface/dummyc/dummy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
void initialise_(int ny, int nx,
// component states
double *state_a_m1, double *state_b_m1)
{
int j, k;
int jk;

for (j=0; j < ny; j++)
for (k=0; k < nx; k++)
{
// vectorisation of 3d-array
jk = k + nx * j;
// initialise states
state_a_m1[jk] = 0.0;
state_b_m1[jk] = 0.0;
}
}

void run_(int ny, int nx,
// from exchanger
double *transfer_a, double *transfer_f,
// component driving data
double *driving_d,
// component parameters
double *parameter_d,
// component states
double *state_a_m1, double *state_a_0,
double *state_b_m1, double *state_b_0,
// to exchanger
double *transfer_c, double *transfer_e,
// component outputs
double *output_x)
{
int j, k;
int jk;

for (j=0; j < ny; j++)
for (k=0; k < nx; k++)
{
// vectorisation of 3d-array
jk = k + nx * j;
// update states
state_a_0[jk] = state_a_m1[jk] + 1;
state_b_0[jk] = state_b_m1[jk] + 2;
// compute transfers to exchanger
transfer_c[jk] = (driving_d[jk] * parameter_d[jk]) + transfer_f[jk]
+ state_a_0[jk];
transfer_e[jk] = (driving_d[jk] * parameter_d[jk]) + transfer_a[jk]
+ state_b_0[jk];
// compute outputs
output_x[jk] = (driving_d[jk] * parameter_d[jk]) + transfer_f[jk]
- state_a_0[jk];
}
}

void finalise_(void)
{}
9 changes: 9 additions & 0 deletions tests/tests/components/nutrientsubsurface/dummyc/dummy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
void initialise_(int ny, int nx, double *state_a_m1,
double *state_b_m1);

void run_(int ny, int nx, double *transfer_a, double *transfer_f,
double *driving_d, double *parameter_d, double *state_a_m1,
double *state_a_0, double *state_b_m1, double *state_b_0,
double *transfer_c, double *transfer_e, double *output_x);

void finalise_(void);
51 changes: 51 additions & 0 deletions tests/tests/components/nutrientsubsurface/dummyc/dummyc.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import numpy as np
cimport numpy as cnp

cdef extern from "dummy.h":

void initialise_(int ny, int nx, double *state_a_m1,
double *state_b_m1)

void run_(int ny, int nx, double *transfer_a, double *transfer_f,
double *driving_d, double *parameter_d, double *state_a_m1,
double *state_a_0, double *state_b_m1, double *state_b_0,
double *transfer_c, double *transfer_e, double *output_x)

void finalise_()

def initialise(cnp.ndarray[cnp.npy_float64, ndim=2] state_a_m1,
cnp.ndarray[cnp.npy_float64, ndim=2] state_b_m1):

cdef int ny = state_a_m1.shape[0]
cdef int nx = state_a_m1.shape[1]

initialise_(ny, nx, &state_a_m1[0, 0], &state_b_m1[0, 0])

def run(cnp.ndarray[cnp.npy_float64, ndim=2] transfer_a,
cnp.ndarray[cnp.npy_float64, ndim=2] transfer_f,
cnp.ndarray[cnp.npy_float64, ndim=2] driving_d,
cnp.ndarray[cnp.npy_float64, ndim=2] parameter_d,
cnp.ndarray[cnp.npy_float64, ndim=2] state_a_m1,
cnp.ndarray[cnp.npy_float64, ndim=2] state_a_0,
cnp.ndarray[cnp.npy_float64, ndim=2] state_b_m1,
cnp.ndarray[cnp.npy_float64, ndim=2] state_b_0):

cdef int ny = transfer_i.shape[0]
cdef int nx = transfer_i.shape[1]

cdef cnp.ndarray[cnp.npy_float64, ndim=2] transfer_c = np.zeros(
(ny, nx), dtype=np.float64)
cdef cnp.ndarray[cnp.npy_float64, ndim=2] transfer_e = np.zeros(
(ny, nx), dtype=np.float64)
cdef cnp.ndarray[cnp.npy_float64, ndim=2] output_x = np.zeros(
(ny, nx), dtype=np.float64)

run_(ny, nx, &transfer_a[0, 0], &transfer_f[0, 0],
&driving_d[0, 0], &parameter_d[0, 0], &state_a_m1[0, 0],
&state_a_0[0, 0], &state_b_m1[0, 0], &state_b_0[0, 0],
&transfer_c[0, 0], &transfer_e[0, 0], &output_x[0, 0])

return transfer_c, transfer_e, output_x

def finalise():
finalise_()
7 changes: 7 additions & 0 deletions tests/tests/components/nutrientsubsurface/dummyc/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from distutils.core import setup, Extension
from Cython.Build import cythonize
import numpy as np

ext = Extension(name="dummyc", sources=["dummyc.pyx", "dummy.c"])

setup(ext_modules=cythonize(ext, language_level="3"), include_dirs=[np.get_include()])
Loading

0 comments on commit a0c3bd8

Please sign in to comment.