18#define YAC_RAD (0.01745329251994329576923690768489)
20static void utest_run_comp_a(
int with_field_mask,
int exchange_type);
21static void utest_run_comp_b(
int with_field_mask,
int exchange_type);
26 xt_initialize(MPI_COMM_WORLD);
29 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
31 for (
int exchange_type = 0; exchange_type < 2; ++exchange_type) {
32 for (
int with_field_mask = 0; with_field_mask < 2; ++with_field_mask) {
39 MPI_Comm_free(&yac_comm);
43 utest_run_comp_a(with_field_mask, exchange_type);
46 utest_run_comp_b(with_field_mask, exchange_type);
49 PUT_ERR(
"wrong number of processes (has to be 3)");
60static void utest_run_comp_a(
int with_field_mask,
int exchange_type) {
79 MPI_Allgather(sendbuf, 1, MPI_CHAR, recvbuf, 1, MPI_CHAR, pair_comm);
81 if ((recvbuf[0] !=
'A') || (recvbuf[1] !=
'B'))
82 PUT_ERR(
"ERROR in yac_cget_comps_instance");
84 MPI_Comm_free(&pair_comm);
89 double x_vertices[4] =
91 double y_vertices[4] =
126 int cell_mask_id, vertex_mask_id;
135 int field_id, multi_field_id, dummy_field_id;
136 double frac_mask_fallback_value = -1.0;
137 double frac_mask_fallback_value_multi = strtod(
"inf", NULL);
139 if (with_field_mask) {
149 "comp_A",
"grid_A",
"A_to_B_src", frac_mask_fallback_value);
150 int multi_field_point_ids[2], multi_field_mask_ids[2];
153 multi_field_mask_ids[0] = cell_mask_id;
154 multi_field_mask_ids[1] = vertex_mask_id;
155 if (with_field_mask) {
157 "A_to_B_multi",
comp_id, multi_field_point_ids, multi_field_mask_ids,
161 "A_to_B_multi",
comp_id, multi_field_point_ids,
165 "comp_A",
"grid_A",
"A_to_B_multi", frac_mask_fallback_value_multi);
175 "comp_A",
"grid_A",
"A_to_B_multi") != frac_mask_fallback_value_multi)
176 PUT_ERR(
"ERROR in yac_cget_field_frac_mask_fallback_value");
180 double send_field_data[2] = {3.0, 4.0};
181 double * send_field_[1] = {&send_field_data[0]};
182 double ** send_field[1] = {&send_field_[0]};
183 double send_frac_mask_data[2] = {1.0, 1.0};
184 double * send_frac_mask_[1] = {&send_frac_mask_data[0]};
185 double ** send_frac_mask[1] = {&send_frac_mask_[0]};
198 double send_cell_field_data[2] = {3.0, 4.0};
199 double send_vertex_field_data[4] = {3.0, 4.0, 5.0, 6.0};
200 double * send_field_[2] =
201 {&send_cell_field_data[0], &send_vertex_field_data[0]};
202 double ** send_field[1] = {&send_field_[0]};
203 double send_cell_frac_mask_data[2] = {1.0, 1.0};
204 double send_vertex_frac_mask_data[4] = {1.0, 1.0, 1.0, 1.0};
205 double * send_frac_mask_[2] =
206 {&send_cell_frac_mask_data[0], &send_vertex_frac_mask_data[0]};
207 double ** send_frac_mask[1] = {&send_frac_mask_[0]};
218static void utest_run_comp_b(
int with_field_mask,
int exchange_type) {
220 double frac_mask_fallback_value = strtod(
"inf", NULL);
240 char * sendbuf =
"B";
242 MPI_Allgather(sendbuf, 1, MPI_CHAR, recvbuf, 1, MPI_CHAR, pair_comm);
243 if ((recvbuf[0] !=
'A') || (recvbuf[1] !=
'B'))
244 PUT_ERR(
"ERROR in yac_cget_comps_comm");
246 MPI_Comm_free(&pair_comm);
248 int nbr_vertices[2] = {2,3};
268 "grid_B", nbr_vertices,
cyclic, x_vertices, y_vertices, &grid_id_B);
270 int nbr_cells[2] = {1,2};
271 double x_cells[1] = {0.0 *
YAC_RAD};
280 int field_id, multi_field_id, dummy_field_id;
293 int interp_stack_nnn, interp_stack_fixed;
296 " n: 1", &interp_stack_nnn);
298 "[{\"fixed\": {\"user_value\": -2}}]", &interp_stack_fixed);
303 "comp_A",
"grid_A",
"A_to_B_src",
304 "comp_B",
"grid_B",
"A_to_B_tgt",
306 interp_stack_nnn, 0, 0);
309 "comp_A",
"grid_A",
"A_to_B_multi",
310 "comp_B",
"grid_B",
"A_to_B_multi",
312 interp_stack_fixed, 0, 0);
322 frac_mask_fallback_value)
323 PUT_ERR(
"ERROR in yac_cget_field_frac_mask_fallback_value_instance");
326 double recv_field_data[2] = {-1.0, -1.0};
327 double * recv_field[1] = {&recv_field_data[0]};
330 if ((recv_field_data[0] != -2.0) || (recv_field_data[1] != -2.0))
331 PUT_ERR(
"ERROR: wrong results from multi field exchange");
344 MPI_Comm internal_comm;
348 int internal_instance_id;
351 internal_instance_id,
"2000-01-01T00:00:00",
"2000-01-01T00:00:12");
354 int internal_comp_id;
357 int nbr_vertices = 2*3;
380 "grid_C", nbr_vertices, x_vertices, y_vertices, &grid_id_C);
386 x_vertices, y_vertices, &point_id_C);
389 int field_id_src, field_id_tgt;
391 "B_to_C", internal_comp_id, &point_id_B, 1,
394 internal_instance_id,
"comp_B",
"grid_B",
"B_to_C",
395 frac_mask_fallback_value);
397 "B_to_C", internal_comp_id, &point_id_C, 1, 1,
"1",
401 int interp_stack_nnn;
407 int ext_couple_config;
408 double const scale_factor = 2.0;
409 double const scale_summand = 0.5;
412 ext_couple_config, scale_factor);
414 ext_couple_config, scale_summand);
416 internal_instance_id,
417 "comp_B",
"grid_B",
"B_to_C",
418 "comp_B",
"grid_C",
"B_to_C",
420 interp_stack_nnn, 0, 0, ext_couple_config);
431 double * send_field_[1] = {&recv_field_data[0]};
432 double ** send_field[1] = {&send_field_[0]};
433 double send_frac_mask_data[2] = {1.0, 0.0};
434 double * send_frac_mask_[1] = {send_frac_mask_data};
435 double ** send_frac_mask[1] = {&send_frac_mask_[0]};
436 double recv_field_data_C[6] = {-1.0, -1.0, -1.0, -1.0, -1.0, -1.0};
437 double * recv_field[1] = {&recv_field_data_C[0]};
442 send_field, send_frac_mask, recv_field,
443 &send_info, &recv_info, &
ierror);
447 send_field_, send_frac_mask_, recv_field,
448 &send_info, &recv_info, &
ierror);
450 double ref_recv_field_data_C[2][6] =
451 {{4.0, 4.0, 4.0, 4.0,
452 frac_mask_fallback_value, frac_mask_fallback_value},
454 frac_mask_fallback_value, frac_mask_fallback_value}};
455 for (
int i = 0;
i < 6; ++
i)
456 if (recv_field_data_C[i] !=
457 scale_factor * ref_recv_field_data_C[with_field_mask][i] +
463 MPI_Comm_free(&internal_comm);
int nbr_vertices_per_cell[NBR_CELLS]
void yac_cinit_comm_dummy(MPI_Comm comm)
void yac_cput_frac(int const field_id, int const collection_size, double ***const send_field, double ***const send_frac_mask, int *info, int *ierr)
void yac_cenable_field_frac_mask(const char *comp_name, const char *grid_name, const char *field_name, double frac_mask_fallback_value)
void yac_cdef_field_mask(char const *name, int const comp_id, int const *point_ids, int const *mask_ids, int const num_pointsets, int collection_size, const char *timestep, int time_unit, int *field_id)
void yac_cdef_datetime_instance(int yac_instance_id, const char *start_datetime, const char *end_datetime)
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
void yac_cset_ext_couple_config_scale_factor(int ext_couple_config_id, double scale_factor)
void yac_cmpi_handshake(MPI_Comm comm, size_t n, char const **group_names, MPI_Comm *group_comms)
void yac_cexchange_frac(int const send_field_id, int const recv_field_id, int const collection_size, double ***const send_field, double ***const send_frac_mask, double **recv_field, int *send_info, int *recv_info, int *ierr)
void yac_cget_interp_stack_config_from_string_json(char const *interp_stack_config, int *interp_stack_config_id)
void yac_cfinalize_instance(int yac_instance_id)
Finalises YAC.
void yac_cfinalize()
Finalises YAC.
void yac_cenddef_instance(int yac_instance_id)
void yac_cget_ext_couple_config(int *ext_couple_config_id)
const char * yac_cget_mpi_handshake_group_name(void)
Retrieve the MPI handshake group name used by YAC.
int const YAC_LOCATION_CORNER
void yac_cset_ext_couple_config_scale_summand(int ext_couple_config_id, double scale_summand)
void yac_cget_comp_comm(int comp_id, MPI_Comm *comp_comm)
void yac_cget(int const field_id, int collection_size, double **recv_field, int *info, int *ierr)
void yac_cdef_comp_instance(int yac_instance_id, char const *comp_name, int *comp_id)
void yac_cdef_grid_reg2d(const char *grid_name, int nbr_vertices[2], int cyclic[2], double *x_vertices, double *y_vertices, int *grid_id)
void yac_cdef_couple_custom_instance(int yac_instance_id, 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)
void yac_cdef_points_reg2d(int const grid_id, int const *nbr_points, int const located, double const *x_points, double const *y_points, int *point_id)
void yac_cget_comps_comm(const char **comp_names, int num_comps, MPI_Comm *comps_comm)
void yac_cinit_comm_instance(MPI_Comm comm, int *yac_instance_id)
void yac_cenable_field_frac_mask_instance(int yac_instance_id, const char *comp_name, const char *grid_name, const char *field_name, double frac_mask_fallback_value)
void yac_cget_interp_stack_config_from_string_yaml(char const *interp_stack_config, int *interp_stack_config_id)
int const YAC_TIME_UNIT_SECOND
void yac_cdef_grid_cloud(const char *grid_name, int nbr_points, double *x_points, double *y_points, int *grid_id)
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_cexchange(int const send_field_id, int const recv_field_id, int const collection_size, double ***const send_field, double **recv_field, int *send_info, int *recv_info, int *ierr)
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_cexchange_frac_ptr_(int const send_field_id, int const recv_field_id, int const collection_size, double **send_field, double **send_frac_mask, double **recv_field, int *send_info, int *recv_info, int *ierr)
void yac_cdef_calendar(int calendar)
int const YAC_PROLEPTIC_GREGORIAN
double yac_cget_field_frac_mask_fallback_value(const char *comp_name, const char *grid_name, const char *field_name)
void yac_cget_comps_comm_instance(int yac_instance_id, char const **comp_names, int num_comps, MPI_Comm *comps_comm)
double yac_cget_field_frac_mask_fallback_value_instance(int yac_instance_id, const char *comp_name, const char *grid_name, const char *field_name)
int const YAC_TIME_UNIT_ISO_FORMAT
void yac_cdef_mask(int const grid_id, int const nbr_points, int const located, int const *is_valid, int *mask_id)
void yac_ccleanup_instance(int yac_instance_id)
Clean-up a YAC instance (see Restarting YAC)
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_cinit_instance(int *yac_instance_id)
void yac_cget_interp_stack_config(int *interp_stack_config_id)
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)
void yac_cdef_couple_instance(int yac_instance_id, 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)
static int default_instance_id
int const YAC_REDUCTION_TIME_NONE