39 double const tgt_coords[3],
int src_cell_id,
size_t src_cell_idx,
40 int const ** global_results_points,
double ** result_weights,
44 double const (*coordinates_xyz)[3],
size_t count,
void *
user_data);
46int main(
int argc,
char** argv) {
51 xt_initialize(MPI_COMM_WORLD);
53 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
54 MPI_Comm_size(MPI_COMM_WORLD, &size);
58 PUT_ERR(
"ERROR: wrong number of processes\n");
63 PUT_ERR(
"ERROR: missing config file directory");
82 if (compare_result != MPI_CONGRUENT)
83 PUT_ERR(
"error in yac_instance_get_comm");
90 malloc(strlen(argv[1]) + 32), argv[1]),
"instance_test_1_1.yaml");
112 size_t num_vertices[2] = {2,2};
116 yac_int global_cell_ids [3][1] = {{0},{1},{0}};
117 yac_int global_corner_ids[3][4] = {{0,1,3,4},{1,2,4,5},{0,1,2,3}};
127 char * grid_name[2] = {
"grid1",
"grid2"};
133 interp_fields[0].coordinates_idx = SIZE_MAX;
134 interp_fields[0].masks_idx = SIZE_MAX;
143 malloc(strlen(argv[1]) + 32), argv[1]),
"instance_test_1_1.yaml");
144 char const * grid_filename =
"instance_test_1_1_grid2.nc";
158 MPI_Barrier(MPI_COMM_WORLD);
161 unlink(
"comp_1.err");
162 unlink(
"comp_2.err");
163 unlink(
"comp_1.log");
164 unlink(
"comp_2.log");
167 grid_filename,
"grid2", 1, 4,
168 (
double[]){0,0,1,1}, (
double[]){0.5,1.5,1.5,0.5}, NULL, NULL,
169 (
int[]){0}, (
int[]){1}, NULL, NULL, NULL, NULL);
170 unlink(grid_filename);
172 MPI_Barrier(MPI_COMM_WORLD);
187 size_t num_vertices[2] = {2,2};
191 yac_int global_cell_ids [1] = {0};
192 yac_int global_corner_ids[4] = {0,1,2,3};
202 char * grid_name[3] = {
"grid1",
"grid2",
"grid3"};
208 interp_fields[0].coordinates_idx = SIZE_MAX;
209 interp_fields[0].masks_idx = SIZE_MAX;
211 char * field_name[3] = {
"field_1",
"field_2",
"field_3"};
222 malloc(strlen(argv[1]) + 32), argv[1]),
"instance_test_1_2.yaml");
247 size_t num_vertices[2] = {2,2};
251 yac_int global_cell_ids [1] = {0};
252 yac_int global_corner_ids[4] = {0,1,2,3};
262 char * grid_name[3] = {
"grid1",
"grid2",
"grid3"};
268 interp_fields[0].coordinates_idx = SIZE_MAX;
269 interp_fields[0].masks_idx = SIZE_MAX;
271 char * field_name[6] = {
"field_1",
"field_2",
"field_3",
272 "field_4",
"field_5",
"field_6"};
283 instance, field_name[((rank + 2) % 3) + 3],
component_names[rank], grid,
289 malloc(strlen(argv[1]) + 32), argv[1]),
"instance_test_1_3.yaml");
315 size_t num_vertices[2] = {2,2};
319 yac_int global_cell_ids [1] = {0};
320 yac_int global_corner_ids[4] = {0,1,2,3};
330 char * grid_name[3] = {
"grid1",
"grid2",
"grid3"};
336 interp_fields[0].coordinates_idx = SIZE_MAX;
337 interp_fields[0].masks_idx = SIZE_MAX;
346 malloc(strlen(argv[1]) + 32), argv[1]),
"instance_test_1_4.yaml");
372 size_t num_vertices[2] = {5,5};
381 char * grid_name[3] = {
"grid1",
"grid2",
"grid3"};
387 interp_fields[0].coordinates_idx = SIZE_MAX;
388 interp_fields[0].masks_idx = SIZE_MAX;
397 malloc(strlen(argv[1]) + 32), argv[1]),
"instance_test_1_5.yaml");
421 size_t num_vertices[2] = {2,2};
425 yac_int global_cell_ids [3][1] = {{0},{1},{0}};
426 yac_int global_corner_ids[3][4] = {{0,1,3,4},{1,2,4,5},{0,1,2,3}};
436 char * grid_name[2] = {
"grid1",
"grid2"};
442 interp_fields[0].coordinates_idx = SIZE_MAX;
443 interp_fields[0].masks_idx = SIZE_MAX;
457 malloc(strlen(argv[1]) + 32), argv[1]),
"instance_test_1_6.yaml");
466 MPI_Barrier(MPI_COMM_WORLD);
471 PUT_ERR(
"weight file is missing\n");
492 size_t num_vertices[2] = {2,2};
496 yac_int global_cell_ids [3][1] = {{0},{1},{0}};
497 yac_int global_corner_ids[3][4] = {{0,1,3,4},{1,2,4,5},{0,1,2,3}};
507 char * grid_name[2] = {
"grid1",
"grid2"};
513 interp_fields[0].coordinates_idx = SIZE_MAX;
514 interp_fields[0].masks_idx = SIZE_MAX;
516 char * field_name[3] = {
"field_1",
"field_2",
"field_3"};
519 {NULL,
"test_instance_parallel1_weight_file_1.nc",
520 "test_instance_parallel1_weight_file_2.nc"};
525 malloc(strlen(argv[1]) + 32), argv[1]),
"instance_test_1_7.yaml");
532 for (
unsigned i = 0;
i < 3; ++
i) {
545 MPI_Barrier(MPI_COMM_WORLD);
549 for (
unsigned i = 0;
i < 3; ++
i) {
552 PUT_ERR(
"weight file is missing\n");
573 size_t num_vertices[2] = {2,2};
577 yac_int global_cell_ids [3][1] = {{0},{1},{2}};
578 yac_int global_corner_ids[3][4] = {{0,1,4,5},{1,2,5,6},{2,3,6,7}};
588 char * grid_name[1] = {
"grid1"};
594 interp_fields[0].coordinates_idx = SIZE_MAX;
595 interp_fields[0].masks_idx = SIZE_MAX;
597 char * field_name[3] = {
"field_1",
"field_2",
"field_3"};
599 for (
unsigned i = 0;
i < 3; ++
i)
607 malloc(strlen(argv[1]) + 32), argv[1]),
"instance_test_1_8.yaml");
627 int comp_idx =
rank >> 1;
635 size_t local_start[3][2] = {{0,0},{2,0}, {0,0}};
636 size_t local_count[3][2] = {{2,4},{2,4}, {4,4}};
644 local_start[rank], local_count[rank],
with_halo);
646 char * grid_name[2] = {
"grid1",
"grid2"};
653 for (
size_t j = 0; j < 3; ++j) cell_middle_points[i][j] = 0.0;
655 for (
size_t k = 0; k < 3; ++k)
656 cell_middle_points[i][k] +=
659 grid_data.cell_to_vertex_offsets[i] + j]][k];
665 interp_fields[0].coordinates_idx = SIZE_MAX;
666 interp_fields[0].masks_idx = SIZE_MAX;
668 interp_fields[1].coordinates_idx =
671 interp_fields[1].masks_idx = SIZE_MAX;
672 free(cell_middle_points);
677 int src_indices[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
678 int tgt_indices[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
679 double weights[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
680 size_t num_links = 16;
683 unsigned num_src_fields = 1;
684 int num_links_per_field[1] = {num_links};
685 int * tgt_id_fixed = NULL;
686 size_t num_fixed_tgt = 0;
687 double * fixed_values = NULL;
688 int * num_tgt_per_fixed_value = NULL;
689 size_t num_fixed_values = 0;
693 src_locations, num_src_fields, num_links_per_field, tgt_id_fixed,
694 num_fixed_tgt, fixed_values, num_tgt_per_fixed_value,
695 num_fixed_values, tgt_location, grid_name[0], grid_name[1]);
703 char * field_name[] = {
"AVG_ARITHMETIC",
719 size_t const field_count = 16;
721 for (
size_t i = 0;
i < 9; ++
i)
725 for (
size_t i = 9;
i < 15; ++
i)
732 for (
size_t i = 15;
i < field_count; ++
i)
737 for (
size_t i = 15;
i < field_count; ++
i)
746 malloc(strlen(argv[1]) + 32), argv[1]),
"instance_test_1_9.yaml");
767 size_t num_vertices[2] = {2,2};
771 yac_int global_cell_ids [3][1] = {{0},{1},{0}};
772 yac_int global_corner_ids[3][4] = {{0,1,3,4},{1,2,4,5},{0,1,2,3}};
782 char * grid_name[2] = {
"grid1",
"grid2"};
787 for (
int i = 0;
i < 2; ++
i) {
796 if ((rank >> 1) == i) {
800 interp_fields[0].coordinates_idx = SIZE_MAX;
801 interp_fields[0].masks_idx = SIZE_MAX;
811 malloc(strlen(argv[1]) + 32), argv[1]),
"instance_test_1_10.yaml");
828 size_t num_vertices[2] = {2,2};
832 yac_int global_cell_ids [1] = {0};
833 yac_int global_corner_ids[4] = {0,1,2,3};
859 char * src_component_name =
"src_comp";
860 char tgt_component_name[32];
861 char const *
component_names[2] = {src_component_name, tgt_component_name};
862 sprintf(tgt_component_name,
"tgt_comp_%d", rank);
867 .coordinates_idx = SIZE_MAX,
868 .masks_idx = SIZE_MAX}};
870 char const * src_field_name =
"src_field";
871 char tgt_field_name[32];
872 sprintf(tgt_field_name,
"tgt_field_%d", rank);
875 instance, src_field_name, src_component_name, src_grid,
879 instance, tgt_field_name, tgt_component_name, tgt_grid,
883 instance,
"2008-03-09T16:05:07",
"2008-03-10T16:05:07");
887 int do_search_count = 0;
901 NULL, NULL, NULL, NULL, 0);
903 free(coupling_period);
909 if (do_search_count != 1)
PUT_ERR(
"ERROR in yac_instance_setup");
911 for (
unsigned put_idx = 0;
914 double *** send_field =
916 for (
int i = 0;
i < 4; ++
i) send_field[0][0][i] = (
double)
i;
919 src_field, put_idx), send_field);
923 double recv_field_data[4] = {-1.0, -1.0, -1.0, -1.0};
924 double * recv_field = recv_field_data;
928 for (
int i = 0;
i < 4;++
i)
929 if (recv_field[i] != (
double)i)
930 PUT_ERR(
"ERROR in yac_instance_setup");
941 size_t num_vertices[2] = {2,2};
945 yac_int global_cell_ids [1] = {0};
946 yac_int global_corner_ids[4] = {0,1,2,3};
972 char src_component_name[32];
973 char tgt_component_name[32];
974 char const *
component_names[2] = {src_component_name, tgt_component_name};
975 sprintf(src_component_name,
"src_comp_%d", rank);
976 sprintf(tgt_component_name,
"tgt_comp_%d", rank);
981 .coordinates_idx = SIZE_MAX,
982 .masks_idx = SIZE_MAX}};
984 char const * src_field_name =
"src_field";
985 char const * tgt_field_name =
"tgt_field";
988 instance, src_field_name, src_component_name, src_grid,
992 instance, tgt_field_name, tgt_component_name, tgt_grid,
996 instance,
"2008-03-09T16:05:07",
"2008-03-10T16:05:07");
1000 int do_search_count = 0;
1010 instance, src_component_name,
src_grid_name, src_field_name,
1014 NULL, NULL, NULL, NULL, 0);
1016 free(coupling_period);
1022 if (do_search_count != 1)
PUT_ERR(
"ERROR in yac_instance_setup");
1024 for (
unsigned put_idx = 0;
1027 double *** send_field =
1029 for (
int i = 0;
i < 4; ++
i)
1033 src_field, put_idx), send_field);
1037 double recv_field_data[4] = {-1.0, -1.0, -1.0, -1.0};
1038 double * recv_field = recv_field_data;
1043 for (
int i = 0;
i < 4;++
i)
1044 if (recv_field[i] != (
double)(i + rank *
NUM_PROCS))
1045 PUT_ERR(
"ERROR in yac_instance_setup");
1058 enum {SRC_COLLECTION_SIZE = 4, SRC_RANK = 0, TGT_RANK = 1};
1059 int is_src = (
rank == SRC_RANK);
1060 int is_tgt = (
rank == TGT_RANK);
1063 size_t num_vertices[2] = {2, 2};
1067 yac_int global_cell_ids[1] = {0};
1068 yac_int global_corner_ids[4] = {0, 1, 2, 3};
1081 if (is_src || is_tgt) {
1091 char const *
component_names[3] = {
"src_comp",
"tgt_comp",
"dummy_comp"};
1097 .coordinates_idx = SIZE_MAX,
1098 .masks_idx = SIZE_MAX}};
1128 collection_selection_all), timestep_iso8601);
1134 collection_selection_first), timestep_iso8601);
1140 collection_selection_last), timestep_iso8601);
1144 instance,
"2008-03-09T16:05:07",
"2008-03-10T16:05:07");
1159 NULL, NULL, NULL, collection_selection_all, 0);
1165 NULL, NULL, NULL, collection_selection_first, 0);
1171 NULL, NULL, NULL, collection_selection_last, 0);
1177 free(coupling_period);
1186 for (
unsigned put_idx = 0;
1188 double ***send_field =
1190 for (
size_t i = 0;
i < SRC_COLLECTION_SIZE; ++
i) {
1191 for (
size_t j = 0; j < 4; ++j) {
1192 send_field[
i][0][j] = (double)(i * 4 + j);
1204 double recv_field_all[SRC_COLLECTION_SIZE][4];
1205 double *recv_ptr_all[SRC_COLLECTION_SIZE];
1206 for (
size_t i = 0;
i < SRC_COLLECTION_SIZE; ++
i) {
1207 for (
size_t j = 0; j < 4; ++j) {
1208 recv_field_all[
i][j] = -1.0;
1210 recv_ptr_all[
i] = recv_field_all[
i];
1215 for (
size_t i = 0;
i < SRC_COLLECTION_SIZE; ++
i) {
1216 for (
int j = 0; j < 4; ++j) {
1217 if (recv_field_all[i][j] != (
double)(i * 4 + j))
1218 PUT_ERR(
"ERROR in tgt_field_all");
1223 double recv_field_first[4] = {-1.0, -1.0, -1.0, -1.0};
1224 double *recv_ptr_first = recv_field_first;
1228 for (
int i = 0;
i < 4; ++
i){
1229 if (recv_field_first[i] != (
double)i)
1230 PUT_ERR(
"ERROR in tgt_field_first");
1234 double recv_field_last[4] = {-1.0, -1.0, -1.0, -1.0};
1235 double *recv_ptr_last = recv_field_last;
1239 for (
int i = 0;
i < 4; ++
i) {
1240 if (recv_field_last[i] != (
double)((SRC_COLLECTION_SIZE - 1) * 4 + i))
1241 PUT_ERR(
"ERROR in tgt_field_last");
1254 char const *comp_names[3] = {
"comp_0",
"comp_1",
"comp_2"};
1255 char const *
grid_names[3] = {
"grid_0",
"grid_1",
"grid_2"};
1256 char const *
field_names[3] = {
"field_0",
"field_1",
"field_2"};
1263 size_t num_vertices[2] = {2, 2};
1267 yac_int global_cell_ids[1] = {0};
1268 yac_int global_corner_ids[4] = {0, 1, 2, 3};
1283 .coordinates_idx = SIZE_MAX,
1284 .masks_idx = SIZE_MAX}};
1287 instance,
field_names[rank], comp_names[rank], grid,
1290 for (
int test_idx = 0; test_idx < 3; ++test_idx) {
1321 for (
size_t i = 0;
i < 3; ++
i) {
1332 PUT_ERR(
"ERROR in yac_instance_sync_def_comps");
1338 PUT_ERR(
"ERROR in yac_instance_sync_def_comps");
1345 int ref_found_field[3][3][3] = {{{1,0,0},{0,1,0},{0,0,1}},
1346 {{1,1,0},{1,1,0},{0,0,1}},
1347 {{1,1,0},{1,1,1},{1,1,1}}};
1348 for (
size_t i = 0;
i < 3; ++
i) {
1349 if (ref_found_field[test_idx][rank][i] != found_field[i]) {
1350 PUT_ERR(
"ERROR in yac_instance_def_sync_comps");
1369 double const tgt_coords[3],
int src_cell_id,
size_t src_cell_idx,
1370 int const ** global_results_points,
double ** result_weights,
1371 size_t * result_count,
void *
user_data) {
1378 for (
size_t i = 0; i < 2; ++i) {
1379 global_results_points[i] = NULL;
1380 result_weights[i] = NULL;
1381 result_count[i] = 0;
1386 yac_int const * global_ids,
double const (*coordinates_xyz)[3],
char const * grid_names[]
char const * component_names[]
char const * field_names[8]
struct yac_basic_grid * yac_basic_grid_new(char const *name, struct yac_basic_grid_data grid_data)
size_t yac_basic_grid_add_coordinates(struct yac_basic_grid *grid, enum yac_location location, yac_coordinate_pointer coordinates, size_t count)
void yac_basic_grid_delete(struct yac_basic_grid *grid)
struct yac_basic_grid_data yac_generate_basic_grid_data_reg_2d_deg(size_t nbr_vertices[2], int cyclic[2], double *lon_vertices, double *lat_vertices)
void yac_yaml_read_coupling(struct yac_couple_config *couple_config, const char *yaml_filename, int parse_flags)
int const YAC_YAML_PARSER_DEFAULT
default parse flags (YAML format)
char const * yac_time_to_ISO(char const *time, enum yac_time_unit_type time_unit)
void yac_couple_config_set_grid_output_filename(struct yac_couple_config *couple_config, char const *grid_name, const char *output_filename)
size_t yac_couple_config_get_component_idx(struct yac_couple_config const *couple_config, char const *component_name)
char const * yac_couple_config_get_field_name(struct yac_couple_config const *couple_config, size_t component_idx, size_t field_idx)
size_t yac_couple_config_get_num_fields(struct yac_couple_config const *couple_config, size_t component_idx)
struct yac_couple_config * yac_couple_config_new()
struct yac_basic_grid_data yac_generate_basic_grid_data_reg2d(double const *global_coords_x, double const *global_coords_y, size_t const num_global_cells_[2], size_t const local_start[2], size_t const local_count[2], int with_halo)
unsigned yac_get_coupling_field_num_puts(struct coupling_field *field)
struct yac_interpolation * yac_get_coupling_field_put_op_interpolation(struct coupling_field *field, unsigned put_idx)
struct yac_interpolation * yac_get_coupling_field_get_op_interpolation(struct coupling_field *field)
double *** yac_get_coupling_field_put_op_send_field_acc(struct coupling_field *field, unsigned put_idx)
static void normalise_vector(double v[])
void check_grid_file(char const *filename, char const *grid_name, size_t ref_num_cells, size_t ref_num_corners_per_cell, double *ref_cla, double *ref_clo, double *ref_lat, double *ref_lon, int *ref_cell_global_ids, int *ref_core_cell_mask, int *ref_vertex_global_ids, int *ref_core_vertex_mask, int *ref_edge_global_ids, int *ref_core_edge_mask)
size_t yac_collection_selection_get_collection_size(struct yac_collection_selection const *collection_selection)
Get the size of the collection selection.
void yac_collection_selection_delete(struct yac_collection_selection *collection_selection)
Delete a collection selection object.
struct yac_collection_selection * yac_collection_selection_new(size_t collection_size, size_t const *selection_indices)
Create a new collection selection.
void yac_instance_delete(struct yac_instance *instance)
void yac_instance_def_datetime(struct yac_instance *instance, const char *start_datetime, const char *end_datetime)
void yac_instance_setup(struct yac_instance *instance, struct yac_basic_grid **grids, size_t num_grids)
struct yac_instance * yac_instance_new(MPI_Comm comm)
MPI_Comm yac_instance_get_comm(struct yac_instance *instance)
struct coupling_field * yac_instance_add_field(struct yac_instance *instance, char const *field_name, char const *comp_name, struct yac_basic_grid *grid, struct yac_interp_field *interp_fields, size_t num_interp_fields, int collection_size, char const *timestep)
void yac_instance_set_couple_config(struct yac_instance *instance, struct yac_couple_config *couple_config)
void yac_instance_def_components(struct yac_instance *instance, char const **comp_names, size_t num_comps)
struct yac_couple_config * yac_instance_get_couple_config(struct yac_instance *instance)
void yac_instance_def_couple(struct yac_instance *instance, 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_period, int time_reduction, struct yac_interp_stack_config *interp_stack_config, int src_lag, int tgt_lag, const char *weight_file_name, int weight_file_on_existing, int mapping_on_source, double scale_factor, double scale_summand, size_t num_src_mask_names, char const *const *src_mask_names, char const *tgt_mask_name, char const *yaxt_exchanger_name, struct yac_collection_selection const *collection_selection, int use_raw_exchange)
void yac_instance_sync_def_comps(struct yac_instance *instance, char const **comp_names, size_t num_comp_names)
void yac_interp_method_check_add_do_search_callback(func_do_search do_search_callback, void *user_data, char const *key)
#define YAC_INTERP_NNN_WEIGHTED_DEFAULT
#define YAC_INTERP_NNN_MAX_SEARCH_DISTANCE_DEFAULT
#define YAC_INTERP_NNN_GAUSS_SCALE_DEFAULT
#define YAC_INTERP_NNN_N_DEFAULT
void yac_interp_stack_config_add_check(struct yac_interp_stack_config *interp_stack_config, char const *constructor_key, char const *do_search_key)
void yac_interp_stack_config_add_fixed(struct yac_interp_stack_config *interp_stack_config, double value)
void yac_interp_stack_config_add_nnn(struct yac_interp_stack_config *interp_stack_config, enum yac_interp_nnn_weight_type type, size_t n, double max_search_distance, double scale)
void yac_interp_stack_config_delete(struct yac_interp_stack_config *interp_stack_config)
Free an interpolation stack configuration object.
struct yac_interp_stack_config * yac_interp_stack_config_new()
Allocate a new empty interpolation stack configuration object.
#define YAC_WEIGHT_FILE_ON_EXISTING_DEFAULT_VALUE
void yac_interpolation_execute_get(struct yac_interpolation *interp, double **tgt_field)
Complete interpolation and write results to the target field (get phase).
void yac_interpolation_execute_put(struct yac_interpolation *interp, double ***src_fields)
Provide source field data and start asynchronous execution of interpolation (put phase).
struct yac_basic_grid * grid
struct yac_interp_field * interp_fields
int * num_vertices_per_cell
enum yac_location location
char const * weight_file_name
static void compute_weights_callback(double const tgt_coords[3], int src_cell_id, size_t src_cell_idx, int const **global_results_points, double **result_weights, size_t *result_count, void *user_data)
static void do_search_callback(yac_int const *global_ids, double const (*coordinates_xyz)[3], size_t count, void *user_data)
char const src_grid_name[]
char const tgt_grid_name[]
void write_weight_file(char const *file_name, int const *src_id, int const *tgt_id, double const *weights, unsigned num_links, enum yac_location const *src_locations, unsigned num_src_fields, int const *num_links_per_src_field, int *tgt_id_fixed, unsigned num_fixed_tgt, double *fixed_values, int *num_tgt_per_fixed_value, unsigned num_fixed_values, enum yac_location tgt_location, char const *src_grid_name, char const *tgt_grid_name)
void yac_cadd_compute_weights_callback(yac_func_compute_weights compute_weights_callback, void *user_data, char const *key)
void yac_cdef_calendar(int calendar)
int const YAC_PROLEPTIC_GREGORIAN
int const YAC_REDUCTION_TIME_NONE
double(* yac_coordinate_pointer)[3]