50 (
char const*[]){
"torc",
"bggd",
"nogt",
"sse7",
"icos",
"icoh"},
54 .num_interpolations = 1},
59 (
char const*[]){
"torc",
"bggd",
"nogt",
"sse7",
"icos"},
69 .num_interpolations = 7},
73 .component_names = (
char const*[]){
"nogt",
"icoh"},
83 .num_interpolations = 7},
87 .component_names = (
char const*[]){
"icos",
"icoh"},
97 .num_interpolations = 7},
101 .component_names = (
char const*[]){
"dummy"},
111 .num_interpolations = 7}};
119 double (*
p)(
double lon,
double lat);
131 .name =
"gulfstream"},
140static void LLtoXYZ(
double lon,
double lat,
double p_out[]);
142static int *
read_mask(
char const * filename,
char const * grid_name,
int const valid_mask_value);
144#define STR_USAGE "Usage: %s -e experimentName\n"
145#define YAC_ASSERT_ARGS(exp, msg) \
148 fprintf(stderr, "ERROR: %s\n" STR_USAGE, msg, argv[0]); \
149 exit(EXIT_FAILURE); \
156int main (
int argc,
char *argv[]) {
176 MPI_Comm_rank(MPI_COMM_WORLD,&rank);
177 MPI_Comm_size(MPI_COMM_WORLD,&size);
181 "Wrong number of processes (has to be %zu)\n", exp_config.
num_components);
191 for (
size_t src_comp_idx = 0; src_comp_idx < exp_config.
num_components;
194 for (
size_t tgt_comp_idx = src_comp_idx + 1;
201 char field_name[256];
202 sprintf(field_name,
"%s_%s_out",
204 char weight_filename[1024];
206 weight_filename, 1024,
"./output/rmp_%s_to_%s_yac_%s.nc",
210 int ext_couple_config_id;
214 ext_couple_config_id, weight_filename);
227 ext_couple_config_id);
239 char * grid_filename =
"./input/grids.nc";
240 char * mask_filename =
"./input/masks_no_atm.nc";
241 int valid_mask_value = 0;
242 size_t num_vertices = 0;
244 int * num_vertices_per_cell = NULL;
245 double * x_vertices = NULL;
246 double * y_vertices = NULL;
247 double * x_cell = NULL;
248 double * y_cell = NULL;
251 if (strcmp(comp_name,
"dummy"))
253 grid_filename, mask_filename, comp_name, valid_mask_value,
254 &num_vertices, &
num_cells, &num_vertices_per_cell,
261 comp_name, (
int)num_vertices, (
int)
num_cells, num_vertices_per_cell,
265 int * global_cell_ids = malloc(
num_cells *
sizeof(*global_cell_ids));
266 int * global_vertex_ids =
267 malloc(num_vertices *
sizeof(*global_vertex_ids));
268 for (
size_t i = 0;
i <
num_cells; ++
i) global_cell_ids[i] = i;
269 for (
size_t i = 0;
i < num_vertices; ++
i) global_vertex_ids[i] = i;
274 int * nogt_mask =
read_mask(
"./input/masks_nogt_yac.nc", comp_name, 0);
275 int * torc_mask =
read_mask(
"./input/masks_torc_yac.nc", comp_name, 0);
278 int cell_point_id_no_mask,
279 cell_point_id_nogt_mask,
280 cell_point_id_torc_mask;
283 &cell_point_id_no_mask);
284 if (nogt_mask != NULL) {
287 &cell_point_id_nogt_mask);
289 }
else cell_point_id_nogt_mask = cell_point_id_no_mask;
290 if (torc_mask != NULL) {
293 &cell_point_id_torc_mask);
295 }
else cell_point_id_torc_mask = cell_point_id_no_mask;
299 for (
size_t src_comp_idx = 0; src_comp_idx < exp_config.
num_components;
310 char field_name[1024];
312 field_name, 1024,
"%s_%s_out",
317 &field_ids[src_comp_idx][interp_idx]);
328 char vtk_filename[1024];
329 sprintf(vtk_filename,
"./output/%s.vtk", comp_name);
331 double (*point_data)[3] = malloc(num_vertices *
sizeof(*point_data));
332 for (
size_t i = 0;
i < num_vertices; ++
i)
333 LLtoXYZ(x_vertices[i], y_vertices[i], point_data[i]);
339 (
unsigned*)num_vertices_per_cell, (
int)
num_cells);
341 vtk_file, global_vertex_ids, (
int)num_vertices,
"global_vertex_id");
345 vtk_file, global_cell_ids, (
int)
num_cells,
"global_cell_id");
346 if (nogt_mask != NULL)
348 vtk_file, nogt_mask, (
int)
num_cells,
"nogt_mask");
349 if (torc_mask != NULL)
351 vtk_file, torc_mask, (
int)
num_cells,
"torc_mask");
355 if (nogt_mask) free(nogt_mask);
356 if (torc_mask) free(torc_mask);
359 double * out_data = malloc(
num_cells *
sizeof(*out_data));
360 double * in_data = malloc(
num_cells *
sizeof(*in_data));
373 char field_name[1024];
376 vtk_file, out_data, (
int)
num_cells, field_name);
380 double *point_set_data[1] = {out_data};
381 double **collection_data[1] = {point_set_data};
384 yac_cput(field_ids[rank][tgt_comp_idx], 1, collection_data, &info, &err);
387 for (
size_t src_comp_idx = 0; src_comp_idx < exp_config.
num_components;
389 if ((
int)src_comp_idx == rank)
continue;
394 for (
size_t l = 0; l <
num_cells; ++l) in_data[l] = 0.0;
395 double *collection_data[1] = {in_data};
397 field_ids[src_comp_idx][interp_idx], 1, collection_data, &info, &err);
401 char field_name[1024];
403 field_name, 1024,
"test_%s_%s_%s",
408 vtk_file, in_data, (
int)
num_cells, field_name);
428 free(num_vertices_per_cell);
435 free(global_vertex_ids);
436 free(global_cell_ids);
442 char const * filename,
char const * grid_name,
int const valid_mask_value) {
444 size_t grid_name_len = strlen(grid_name) + 1;
445 char x_dim_name[2 + grid_name_len];
446 char y_dim_name[2 + grid_name_len];
447 char mask_var_name[4 + grid_name_len];
449 snprintf(x_dim_name, 2 + grid_name_len,
"x_%s", grid_name);
450 snprintf(y_dim_name, 2 + grid_name_len,
"y_%s", grid_name);
451 snprintf(mask_var_name, 4 + grid_name_len,
"%s.msk", grid_name);
459 status = nc_inq_varid(ncid, mask_var_name, &mask_var_id);
461 if (status == NC_ENOTVAR) {
464 }
else if (status != NC_NOERR)
477 size_t num_cells = x_dim_len * y_dim_len;
494 while ((opt = getopt(argc, argv,
"e:")) != -1) {
499 if (!strcmp(optarg,
"GEN_MASK")) *experiment =
GEN_MASK;
500 else if (!strcmp(optarg,
"NOICOH")) *experiment =
NOICOH;
501 else if (!strcmp(optarg,
"NOGT_ICOH")) *experiment =
NOGT_ICOH;
502 else if (!strcmp(optarg,
"ICOS_ICOH")) *experiment =
ICOS_ICOH;
503 else if (!strcmp(optarg,
"DUMMY")) *experiment =
DUMMY;
587static void LLtoXYZ(
double lon,
double lat,
double p_out[]) {
589 while (lon < -M_PI) lon += 2.0 * M_PI;
590 while (lon >= M_PI) lon -= 2.0 * M_PI;
592 double cos_lat = cos(lat);
593 p_out[0] = cos_lat * cos(lon);
594 p_out[1] = cos_lat * sin(lon);
#define YAC_INTERP_NNN_MAX_SEARCH_DISTANCE_DEFAULT
void yac_nc_open(const char *path, int omode, int *ncidp)
void yac_nc_inq_dimid(int ncid, char const *name, int *dimidp)
int yac_file_exists(const char *filename)
void yac_read_scrip_grid_information(char const *grid_filename, char const *mask_filename, char const *grid_name, int valid_mask_value, size_t *num_vertices, size_t *num_cells, int **num_vertices_per_cell, double **x_vertices, double **y_vertices, double **x_cells, double **y_cells, int **cell_to_vertex, int **cell_core_mask, size_t **duplicated_cell_idx, size_t **orig_cell_idx, size_t *nbr_duplicated_cells)
size_t num_interpolations
enum interp_stack_type * interpolations
char const ** component_names
double yac_test_one(double lon, double lat)
double yac_test_ana_fcos(double lon, double lat)
double yac_test_harmonic(double lon, double lat)
double yac_test_vortex(double lon, double lat)
double yac_test_func(double lon, double lat)
double yac_test_ana_fcossin(double lon, double lat)
double yac_test_gulfstream(double lon, double lat)
#define YAC_HANDLE_ERROR(exp)
static void generate_interp_stacks(void)
struct @0 interp_stacks[NUM_INTERP_STACK_TYPES]
static void free_interp_stacks(void)
static void parse_arguments(int argc, char **argv, enum experiment_type *experiment)
#define YAC_ASSERT_ARGS(exp, msg)
@ INTERP_STACK_CONSERV_DESTAREA
@ INTERP_STACK_CONS2ND_FRACAREA
@ INTERP_STACK_CONSERV_FRACAREA
double(* p)(double lon, double lat)
static void LLtoXYZ(double lon, double lat, double p_out[])
struct @1 test_functions[]
struct experiment_configuration experiment_configs[]
static int * read_mask(char const *filename, char const *grid_name, int const valid_mask_value)
void yac_vtk_write_cell_scalars_double(YAC_VTK_FILE *vtk_file, double *scalars, unsigned num_cells, char *name)
void yac_vtk_write_cell_scalars_int(YAC_VTK_FILE *vtk_file, int *scalars, unsigned num_cells, char *name)
void yac_vtk_write_point_data(YAC_VTK_FILE *vtk_file, double *point_data, unsigned num_points)
void yac_vtk_write_point_scalars_int(YAC_VTK_FILE *vtk_file, int *scalars, unsigned num_points, char *name)
void yac_vtk_close(YAC_VTK_FILE *vtk_file)
void yac_vtk_write_cell_data(YAC_VTK_FILE *vtk_file, unsigned *cell_corners, unsigned *num_points_per_cell, unsigned num_cells)
YAC_VTK_FILE * yac_vtk_open(const char *filename, const char *title)
void yac_cset_global_index(int const *global_index, int location, int grid_id)
void yac_cfree_ext_couple_config(int ext_couple_config_id)
void yac_cdef_datetime(const char *start_datetime, const char *end_datetime)
int const YAC_LOCATION_CELL
int const YAC_AVG_ARITHMETIC
void yac_cfinalize()
Finalises YAC.
void yac_cget_ext_couple_config(int *ext_couple_config_id)
void yac_cset_ext_couple_config_weight_file(int ext_couple_config_id, char const *weight_file)
int const YAC_LOCATION_CORNER
void yac_cdef_couple_custom(char const *src_comp_name, char const *src_grid_name, char const *src_field_name, char const *tgt_comp_name, char const *tgt_grid_name, char const *tgt_field_name, char const *coupling_timestep, int time_unit, int time_reduction, int interp_stack_config_id, int src_lag, int tgt_lag, int ext_couple_config_id)
int const YAC_CONSERV_DESTAREA
void yac_cget(int const field_id, int collection_size, double **recv_field, int *info, int *ierr)
int const YAC_REDUCTION_TIME_ACCUMULATE
int const YAC_TIME_UNIT_SECOND
void yac_cadd_interp_stack_config_conservative(int interp_stack_config_id, int order, int enforced_conserv, int partial_coverage, int normalisation)
void yac_cdef_grid_unstruct(const char *grid_name, int nbr_vertices, int nbr_cells, int *num_vertices_per_cell, double *x_vertices, double *y_vertices, int *cell_to_vertex, int *grid_id)
void yac_cdef_points_unstruct(int const grid_id, int const nbr_points, int const located, double const *x_points, double const *y_points, int *point_id)
void yac_cput(int const field_id, int const collection_size, double ***const send_field, int *info, int *ierr)
void yac_cdef_calendar(int calendar)
void yac_cset_core_mask(int const *is_core, int location, int grid_id)
int const YAC_PROLEPTIC_GREGORIAN
void yac_cset_mask(int const *is_valid, int points_id)
void yac_cadd_interp_stack_config_hcsbb(int interp_stack_config_id)
void yac_cadd_interp_stack_config_fixed(int interp_stack_config_id, double value)
int const YAC_CONSERV_FRACAREA
void yac_cfree_interp_stack_config(int interp_stack_config_id)
void yac_cadd_interp_stack_config_nnn(int interp_stack_config_id, int type, size_t n, double max_search_distance, double scale)
void yac_cget_interp_stack_config(int *interp_stack_config_id)
void yac_cadd_interp_stack_config_average(int interp_stack_config_id, int reduction_type, int partial_coverage)
void yac_cdef_comp(char const *comp_name, int *comp_id)
void yac_cdef_field(char const *name, int const comp_id, int const *point_ids, int const num_pointsets, int collection_size, const char *timestep, int time_unit, int *field_id)
#define YAC_ASSERT_F(exp, format,...)