Skip to content
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

fregrid_acc - first and second order conservative interpolation #300

Merged
merged 86 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 77 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
22bc984
read weight file
Apr 11, 2024
955870c
makefile to test
Apr 12, 2024
c493780
small changes
Apr 12, 2024
5ee116c
untracked makefile.am
Apr 12, 2024
6c1a6eb
remove omp from create_xgrid and clean it up
May 13, 2024
d41c451
create create_xgrid_utils
May 13, 2024
a17fbbc
add untracked files
May 13, 2024
04529f5
add get_minmaxavg_list
May 13, 2024
e5ff2ee
replace create_xgrids with _acc
May 13, 2024
49ace47
add parameters file
May 13, 2024
efc9e94
more cleanup
May 15, 2024
f5a0535
untracked parameters.h
May 15, 2024
d3de5fe
commit before losing work
May 15, 2024
3c81eba
bring in updates from remove_omp
May 15, 2024
8ce5636
gather data transfer
May 15, 2024
41022e9
add general_utils_acc
May 15, 2024
c74a607
start unit test
May 15, 2024
75f4ef7
change name to cell_info
May 15, 2024
3c4c640
change minmaxavg_list to cell
May 15, 2024
74a46f1
untracked files
May 15, 2024
7801141
add get_bounding_indices
May 15, 2024
b93c6e2
remove masks
May 15, 2024
5502dd8
change avg to cent
May 16, 2024
20e8e91
fix warnings
May 16, 2024
ff54c30
add poly_ctr lat/lon back
May 16, 2024
a1162bf
save comment
May 16, 2024
5281a21
Merge remote-tracking branch 'origin/remove_omp' into get_minmaxavg_list
May 16, 2024
333e575
add get_nxgrid_upbound_2dx2d_order1_acc
May 16, 2024
e8fc36c
Merge remote-tracking branch 'origin/get_minmaxavg_list' into get_ubo…
May 16, 2024
5f849f5
fix header guard
May 16, 2024
71ac747
Merge remote-tracking branch 'origin/remove_omp' into get_minmaxavg_list
May 16, 2024
583e74a
more cleanup
May 17, 2024
af8f3a3
fix things
May 17, 2024
f249dbf
more cleanup
May 17, 2024
551ce8e
commiting before merging changes
May 17, 2024
d78957d
Merge remote-tracking branch 'origin/get_minmaxavg_list' into get_ubo…
May 17, 2024
6aaa997
self contain
May 17, 2024
e117016
intuitive variable names
May 17, 2024
2cbc4e2
fix errors and update tests
May 17, 2024
55896ab
bring in changes
May 17, 2024
97d74c4
Merge remote-tracking branch 'origin/get_minmaxavg_list' into get_ubo…
May 17, 2024
65deded
more work
May 17, 2024
b0ff2fd
Merge remote-tracking branch 'fms/master' into get_minmaxavg_list
May 22, 2024
e7bc734
minor changes, bring up to date with main
May 22, 2024
edceb32
will not pass in structs other than interp
May 22, 2024
e8cb4db
Merge remote-tracking branch 'origin/get_minmaxavg_list' into get_ubo…
May 22, 2024
48332ba
add mask back in
May 22, 2024
795f42e
change names part 1 create_xgrid_acc
May 24, 2024
1c7b092
rename variables
May 24, 2024
f866c05
rename function to get supposed mask
May 24, 2024
f56bde0
better names for getting jstart and jend
May 24, 2024
30894a0
skip cells name change
May 24, 2024
b8a7e57
UNTRACKED FILE!
May 24, 2024
04ae80b
update forgotten unit test
May 24, 2024
ab0dd5c
call get_grid_cells_struct_acc among other small things
May 24, 2024
3d763ed
fix get_cell_minmaxavg_latlons
May 28, 2024
d5bde8e
partial unit test for upbound_nxgrid
May 29, 2024
a4cdf85
upbound_nxgrid unit test
May 30, 2024
dee1010
first order almost
May 31, 2024
caf6bd0
working first order maybe
May 31, 2024
42c00dd
working first order
Jun 5, 2024
b0449bd
working 2nd order
Jun 6, 2024
3e63672
working 2nd order
Jun 7, 2024
fd576fb
minor changes in 1rst order
Jun 7, 2024
bdd3d5d
add untracked files
Jun 7, 2024
366f1d5
fix copy data to xgrid
Jun 7, 2024
e2576b5
working entire first order
Jun 7, 2024
45f765e
working 1 and 2
Jun 10, 2024
26b1c2e
fix error
Jun 10, 2024
48e95b1
final free
Jun 10, 2024
63f2e4e
fregrid_acc cleanup
Jun 10, 2024
5f99a33
change xgrid back to interp
Jun 26, 2024
01f411a
rename skip cells to mask
Jun 26, 2024
c24c3a4
dangling pointers
Jun 27, 2024
50878ae
fix free pointer twice
Jun 27, 2024
165664b
change mtile
Jun 27, 2024
6d7048f
remove nz from do_scalar argument
Jun 27, 2024
298f00f
fix read remap file
Jul 2, 2024
08be05c
fix test_get_grid_cell_struct
Jul 2, 2024
57acb08
test_get_upbound_nxcells
Jul 2, 2024
8f26421
get_interp_order1 test cleanup
Jul 3, 2024
ce5c68b
comments for test_read_remap_file
Jul 5, 2024
bb21e80
fix todo comment in fregrid_acc
Jul 5, 2024
d1ef1ea
add untracked files
Jul 5, 2024
4f5cf77
fix makefile.am for t_acc
Jul 19, 2024
65d0b4e
remove return before checking conserve
Jul 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ endif
if ENABLE_ACC
SUBDIRS += tools/libfrencutils_acc
SUBDIRS += tools/fregrid_acc
SUBDIRS += t_acc
endif
8 changes: 7 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,18 @@ AC_CONFIG_FILES([Makefile
tools/river_regrid/Makefile
tools/runoff_regrid/Makefile
tools/transfer_to_mosaic_grid/Makefile
t/Makefile
tools/simple_hydrog/Makefile
tools/simple_hydrog/postp/Makefile
tools/simple_hydrog/lakes/Makefile
tools/simple_hydrog/rmvpr/Makefile
tools/simple_hydrog/libfmslite/Makefile
t/Makefile
t_acc/Makefile
t_acc/test_read_remap_file/Makefile
t_acc/test_get_cell_minmaxavg_latlons/Makefile
t_acc/test_get_upbound_nxcells_2dx2d/Makefile
t_acc/test_get_xgrid_order1/Makefile

])

AC_OUTPUT
21 changes: 21 additions & 0 deletions t_acc/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#***********************************************************************
#* GNU Lesser General Public License
#*
#* This file is part of the GFDL Flexible Modeling System (FMS).
#*
#* FMS is free software: you can redistribute it and/or modify it under
#* the terms of the GNU Lesser General Public License as published by
#* the Free Software Foundation, either version 3 of the License, or (at
#* your option) any later version.
#*
#* FMS is distributed in the hope that it will be useful, but WITHOUT
#* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
#* for more details.
#*
#* You should have received a copy of the GNU Lesser General Public
#* License along with FMS. If not, see <http://www.gnu.org/licenses/>.
#***********************************************************************

SUBDIRS = test_read_remap_file test_get_cell_minmaxavg_latlons test_get_upbound_nxcells_2dx2d\
test_get_xgrid_order1
34 changes: 34 additions & 0 deletions t_acc/test_get_cell_minmaxavg_latlons/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#***********************************************************************
#* GNU Lesser General Public License
#*
#* This file is part of the GFDL Flexible Modeling System (FMS).
#*
#* FMS is free software: you can redistribute it and/or modify it under
#* the terms of the GNU Lesser General Public License as published by
#* the Free Software Foundation, either version 3 of the License, or (at
#* your option) any later version.
#*
#* FMS is distributed in the hope that it will be useful, but WITHOUT
#* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
#* for more details.
#*
#* You should have received a copy of the GNU Lesser General Public
#* License along with FMS. If not, see <http://www.gnu.org/licenses/>.
#***********************************************************************

check_PROGRAMS = test_get_cell_minmaxavg_latlons

AM_CFLAGS = $(NETCDF_CFLAGS) \
-I$(top_srcdir)/tools/fregrid_acc \
-I$(top_srcdir)/tools/libfrencutils \
-I$(top_srcdir)/tools/libfrencutils_acc -acc

LDADD = $(NETCDF_LDFLAGS) $(NETCDF_LIBS) $(RPATH_FLAGS) \
$(top_builddir)/tools/fregrid_acc/interp_utils_acc.o \
$(top_builddir)/tools/libfrencutils/libfrencutils.a \
$(top_builddir)/tools/libfrencutils_acc/libfrencutils_acc.a

test_get_cell_minmaxavg_latlons = test_get_cell_minmaxavg_latlons.c

TESTS = test_get_cell_minmaxavg_latlons
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
/***********************************************************************
* GNU Lesser General Public License
*
* This file is part of the GFDL FRE NetCDF tools package (FRE-NCTools).
*
* FRE-NCtools is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any loner version.
*
* FRE-NCtools is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FRE-NCTools. If not, see
* <http://www.gnu.org/licenses/>.
**********************************************************************/

mlee03 marked this conversation as resolved.
Show resolved Hide resolved
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "create_xgrid_utils_acc.h"
#include "interp_utils_acc.h"
#include "parameters.h"
#include "globals_acc.h"

#define NLON 36 // 36 cells in lon direction (36+1 grid points in the lon direction for each lat point)
#define NLAT 4 // 4 cells in lat direction ( 4+1 grid points in the lat direction for each lon point)

double dlon = 360.0/NLON;
double dlat = 30.0;

double const tolerance = 1.e-7;

typedef struct {
double lon_min[NLON*NLAT];
double lon_max[NLON*NLAT];
double lat_min[NLON*NLAT];
double lat_max[NLON*NLAT];
double lon_cent[NLON*NLAT];
double *lon_vertices[NLON*NLAT];
double *lat_vertices[NLON*NLAT];
} Answers;

void copy_cell_to_host(Grid_cells_struct_config *grid_cells);
void reset_cell_on_host(Grid_cells_struct_config *grid_cells);
void get_answers(const double *lon, const double *lat, Answers *answers);
void check_answers( const Grid_cells_struct_config *grid_cells, const Answers *answers);
void check_ranswer( const int n, const double *answer, const double *checkme);

//TODO: test for compute poly_area

int main(){

Answers answers;
Grid_cells_struct_config grid_cells;
Grid_config grid[1];

grid[0].nxc=NLON;
grid[0].nyc=NLAT;
grid[0].lonc = (double *)calloc( (NLON+1)*(NLAT+1), sizeof(double) );
grid[0].latc = (double *)calloc( (NLON+1)*(NLAT+1), sizeof(double) );

// no poles, do not need to worry about fix_lon
for(int ilat=0 ; ilat<NLAT+1 ; ilat++) {
double latitude = (-30.0 + dlat*ilat)*D2R;
for(int ilon=0 ; ilon<NLON+1 ; ilon++) {
int ipt=ilat*(NLON+1)+ilon;
grid[0].latc[ipt] = latitude;
grid[0].lonc[ipt] = (0.0 + dlon*ilon)*D2R;
}
}

copy_grid_to_device_acc((NLON+1)*(NLAT+1), grid[0].latc, grid[0].lonc);
get_grid_cells_struct_acc( NLON, NLAT, grid[0].lonc, grid[0].latc, &grid_cells);

get_answers(grid[0].lonc, grid[0].latc, &answers);

reset_cell_on_host(&grid_cells); //to verify data is copied out from device
copy_cell_to_host(&grid_cells);

check_answers(&grid_cells, &answers);

printf("TODO: add check for areas");

return 0;
}

void get_answers(const double *lon, const double *lat, Answers *answers ){

for(int icell=0 ; icell<NLON*NLAT ; icell++){
answers->lon_vertices[icell] = (double *)calloc(MAX_V, sizeof(double));
answers->lat_vertices[icell] = (double *)calloc(MAX_V, sizeof(double));
}

//get min max avg replaceme lon values of a cell
for(int ilat=0 ; ilat<NLAT ; ilat++) {
double latitude_min = (-30.0 + dlat*ilat)* D2R;
double latitude_max = (-30.0 + dlat*(ilat+1))* D2R;
for(int ilon=0 ; ilon<NLON ; ilon++) {
int icell = ilat*NLON + ilon;
answers->lat_min[icell] = latitude_min;
answers->lat_max[icell] = latitude_max;
answers->lon_min[icell] = (0 + dlon*ilon)* D2R;
answers->lon_max[icell] = (0 + dlon*(ilon+1))* D2R;
answers->lon_cent[icell] = (dlon*ilon+0.5*dlon)* D2R;
}
}

//get vertices for each cell
for(int ilat=0 ; ilat<NLAT ; ilat++) {
for( int ilon=0 ; ilon<NLON ; ilon++) {
int icell=ilat*(NLON) + ilon;
// 3-----2
// | |
// | |
// 0-----1
answers->lat_vertices[icell][0]=answers->lat_min[icell];
answers->lat_vertices[icell][1]=answers->lat_min[icell];
answers->lat_vertices[icell][2]=answers->lat_max[icell];
answers->lat_vertices[icell][3]=answers->lat_max[icell];

answers->lon_vertices[icell][0]=answers->lon_min[icell];
answers->lon_vertices[icell][1]=answers->lon_max[icell];
answers->lon_vertices[icell][2]=answers->lon_max[icell];
answers->lon_vertices[icell][3]=answers->lon_min[icell];
}
}

}

void reset_cell_on_host(Grid_cells_struct_config *grid_cells)
{

for( int icell=0 ; icell<NLON*NLAT; icell++) {
grid_cells->lon_min[icell]=-99.;
grid_cells->lon_max[icell]=-99.;
grid_cells->lat_min[icell]=-99.;
grid_cells->lat_max[icell]=-99.;
grid_cells->lon_cent[icell]=-99.;
grid_cells->nvertices[icell]=-99;
for(int ipt=0 ; ipt<MAX_V ; ipt++){
grid_cells->lon_vertices[icell][ipt]=-99.;
grid_cells->lat_vertices[icell][ipt]=-99.;
}
}

}

void copy_cell_to_host(Grid_cells_struct_config *grid_cells)
{

int ncell = NLON*NLAT;
#pragma acc exit data copyout( grid_cells->lon_min[:ncell], grid_cells->lon_max[:ncell], \
grid_cells->lat_min[:ncell], grid_cells->lat_max[:ncell], \
grid_cells->lon_cent[:ncell], grid_cells->nvertices[:ncell], \
grid_cells->lon_vertices[:ncell][:MAX_V],\
grid_cells->lat_vertices[:ncell][:MAX_V])
}

void check_answers( const Grid_cells_struct_config *grid_cells, const Answers *answers)
{

printf("Checking for nubmer of cell vertices\n");
for(int i=0 ; i<NLON*NLAT ; i++) {
if( grid_cells->nvertices[i] != 4 ) {
printf("ERROR element %d: %d vs %d\n", i, grid_cells->nvertices[i], 4);
exit(1);
}
}

printf("Checking for min longitudinal point for each cell\n");
check_ranswer(NLON*NLAT, answers->lon_min, grid_cells->lon_min);

printf("Checking for max longitudinal point for each cell\n");
check_ranswer(NLON*NLAT, answers->lon_max, grid_cells->lon_max);

printf("Checking for min latitudinal point for each cell\n");
check_ranswer(NLON*NLAT, answers->lat_min, grid_cells->lat_min);

printf("Checking for max latitudinal point for each cell\n");
check_ranswer(NLON*NLAT, answers->lat_max, grid_cells->lat_max);

printf("Checking for avg longitudinal point for each cell\n");
check_ranswer(NLON*NLAT, answers->lon_cent, grid_cells->lon_cent);

printf("Checking for longitudinal vertices for each cell\n");
for(int icell=0 ; icell<NLAT*NLON ; icell++) {
check_ranswer(MAX_V, answers->lon_vertices[icell], grid_cells->lon_vertices[icell]);
}

printf("Checking for latitudinal vertices for each cell\n");
for(int icell=0 ; icell<NLAT*NLON ; icell++) {
check_ranswer(MAX_V, answers->lat_vertices[icell], grid_cells->lat_vertices[icell]);
}


}

void check_ranswer( const int n, const double *answers, const double *checkme) {
for(int i=0 ; i<n ; i++) {
if( abs(answers[i]-checkme[i])>tolerance ) {
printf(" ERROR element %d: %lf vs %lf, difference of %e\n",
i, answers[i], checkme[i], abs(answers[i]-checkme[i]));
exit(1);
}
}
}
34 changes: 34 additions & 0 deletions t_acc/test_get_upbound_nxcells_2dx2d/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#***********************************************************************
#* GNU Lesser General Public License
#*
#* This file is part of the GFDL Flexible Modeling System (FMS).
#*
#* FMS is free software: you can redistribute it and/or modify it under
#* the terms of the GNU Lesser General Public License as published by
#* the Free Software Foundation, either version 3 of the License, or (at
#* your option) any later version.
#*
#* FMS is distributed in the hope that it will be useful, but WITHOUT
#* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
#* for more details.
#*
#* You should have received a copy of the GNU Lesser General Public
#* License along with FMS. If not, see <http://www.gnu.org/licenses/>.
#***********************************************************************

check_PROGRAMS = test_get_upbound_nxcells_2dx2d

AM_CFLAGS = $(NETCDF_CFLAGS) \
-I$(top_srcdir)/tools/fregrid_acc \
-I$(top_srcdir)/tools/libfrencutils \
-I$(top_srcdir)/tools/libfrencutils_acc -acc

LDADD = $(NETCDF_LDFLAGS) $(NETCDF_LIBS) $(RPATH_FLAGS) \
$(top_builddir)/tools/fregrid_acc/interp_utils_acc.o \
$(top_builddir)/tools/libfrencutils/libfrencutils.a \
$(top_builddir)/tools/libfrencutils_acc/libfrencutils_acc.a

test_get_upbound_nxcells_2dx2d = test_get_upbound_nxcells_2dx2d.c

TESTS = test_get_upbound_nxcells_2dx2d
Loading
Loading