This test checks the frac mask feature.
#include <mpi.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <yaxt.h>
#include "tests.h"
#define YAC_RAD (0.01745329251994329576923690768489)
static void run_comp_a(int with_field_mask, int exchange_type);
static void run_comp_b(int with_field_mask, int exchange_type);
MPI_Init(NULL, NULL);
xt_initialize(MPI_COMM_WORLD);
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
for (int exchange_type = 0; exchange_type < 2; ++exchange_type) {
for (int with_field_mask = 0; with_field_mask < 2; ++with_field_mask) {
switch(rank) {
case(0): {
MPI_Comm yac_comm;
const char* group_name = "yac";
MPI_Comm_free(&yac_comm);
break;
}
case(1):
run_comp_a(with_field_mask, exchange_type);
break;
case(2):
run_comp_b(with_field_mask, exchange_type);
break;
default:
PUT_ERR("wrong number of processes (has to be 3)");
break;
}
}
}
xt_finalize();
MPI_Finalize();
return TEST_EXIT_CODE;
}
static void run_comp_a(int with_field_mask, int exchange_type) {
int comp_id;
MPI_Comm pair_comm;
{
char * sendbuf = "A";
char recvbuf[2];
MPI_Allgather(sendbuf, 1, MPI_CHAR, recvbuf, 1, MPI_CHAR, pair_comm);
if ((recvbuf[0] != 'A') || (recvbuf[1] != 'B'))
PUT_ERR("ERROR in yac_cget_comps_instance");
}
MPI_Comm_free(&pair_comm);
int nbr_vertices = 4;
int nbr_cells = 2;
int nbr_vertices_per_cell[2] = {3,3};
double x_vertices[4] =
double y_vertices[4] =
int cell_to_vertex[6] = {0,1,2, 1,3,2};
int grid_id;
"grid_A", nbr_vertices, nbr_cells, nbr_vertices_per_cell,
x_vertices, y_vertices, cell_to_vertex, &grid_id);
int cell_point_id, vertex_point_id;
&vertex_point_id);
int cell_mask_id, vertex_mask_id;
int cell_mask[2] = {1, 0};
int vertex_mask[4] = {1, 1, 1, 1};
int field_id, multi_field_id, dummy_field_id;
double frac_mask_fallback_value = -1.0;
double frac_mask_fallback_value_multi = strtod("inf", NULL);
if (with_field_mask) {
"A_to_B_src", comp_id, &cell_point_id, &cell_mask_id, 1,
} else {
"A_to_B_src", comp_id, &cell_point_id, 1,
}
"comp_A", "grid_A", "A_to_B_src", frac_mask_fallback_value);
int multi_field_point_ids[2], multi_field_mask_ids[2];
multi_field_point_ids[0] = cell_point_id;
multi_field_point_ids[1] = vertex_point_id;
multi_field_mask_ids[0] = cell_mask_id;
multi_field_mask_ids[1] = vertex_mask_id;
if (with_field_mask) {
"A_to_B_multi", comp_id, multi_field_point_ids, multi_field_mask_ids,
} else {
"A_to_B_multi", comp_id, multi_field_point_ids,
}
"comp_A", "grid_A", "A_to_B_multi", frac_mask_fallback_value_multi);
"dummy_field", comp_id, &cell_point_id, 1,
int ierror;
"comp_A", "grid_A", "A_to_B_multi") != frac_mask_fallback_value_multi)
PUT_ERR("ERROR in yac_cget_field_frac_mask_fallback_value");
{
double send_field_data[2] = {3.0, 4.0};
double * send_field_[1] = {&send_field_data[0]};
double ** send_field[1] = {&send_field_[0]};
double send_frac_mask_data[2] = {1.0, 1.0};
double * send_frac_mask_[1] = {&send_frac_mask_data[0]};
double ** send_frac_mask[1] = {&send_frac_mask_[0]};
int info;
if (exchange_type) {
field_id, collection_size, send_field, send_frac_mask, &info, &ierror);
yac_cget(dummy_field_id, collection_size, NULL, &info, &ierror);
} else {
field_id, dummy_field_id, collection_size,
send_field, send_frac_mask, NULL, &info, &info, &ierror);
}
}
{
double send_cell_field_data[2] = {3.0, 4.0};
double send_vertex_field_data[4] = {3.0, 4.0, 5.0, 6.0};
double * send_field_[2] =
{&send_cell_field_data[0], &send_vertex_field_data[0]};
double ** send_field[1] = {&send_field_[0]};
double send_cell_frac_mask_data[2] = {1.0, 1.0};
double send_vertex_frac_mask_data[4] = {1.0, 1.0, 1.0, 1.0};
double * send_frac_mask_[2] =
{&send_cell_frac_mask_data[0], &send_vertex_frac_mask_data[0]};
double ** send_frac_mask[1] = {&send_frac_mask_[0]};
int info;
multi_field_id, collection_size, send_field, send_frac_mask,
&info, &ierror);
}
}
static void run_comp_b(int with_field_mask, int exchange_type) {
double frac_mask_fallback_value = strtod("inf", NULL);
int comp_id;
MPI_Comm pair_comm;
{
char * sendbuf = "B";
char recvbuf[2];
MPI_Allgather(sendbuf, 1, MPI_CHAR, recvbuf, 1, MPI_CHAR, pair_comm);
if ((recvbuf[0] != 'A') || (recvbuf[1] != 'B'))
PUT_ERR("ERROR in yac_cget_comps_comm");
}
MPI_Comm_free(&pair_comm);
int nbr_vertices[2] = {2,3};
int cyclic[2] = {0,0};
int grid_id_B;
"grid_B", nbr_vertices, cyclic, x_vertices, y_vertices, &grid_id_B);
int nbr_cells[2] = {1,2};
double x_cells[1] = {0.0 *
YAC_RAD};
int point_id_B;
int field_id, multi_field_id, dummy_field_id;
"A_to_B_tgt", comp_id, &point_id_B, 1, collection_size, "1",
"A_to_B_multi", comp_id, &point_id_B, 1, collection_size, "1",
"dummy_field", comp_id, &point_id_B, 1, collection_size, "1",
int interp_stack_nnn, interp_stack_fixed;
"- nnn:\n"
" n: 1", &interp_stack_nnn);
"[{\"fixed\": {\"user_value\": -2}}]", &interp_stack_fixed);
"comp_A", "grid_A", "A_to_B_src",
"comp_B", "grid_B", "A_to_B_tgt",
interp_stack_nnn, 0, 0);
"comp_A", "grid_A", "A_to_B_multi",
"comp_B", "grid_B", "A_to_B_multi",
interp_stack_fixed, 0, 0);
int ierror;
frac_mask_fallback_value)
PUT_ERR("ERROR in yac_cget_field_frac_mask_fallback_value_instance");
double recv_field_data[2] = {-1.0, -1.0};
double * recv_field[1] = {&recv_field_data[0]};
int info;
yac_cget(multi_field_id, collection_size, recv_field, &info, &ierror);
if ((recv_field_data[0] != -2.0) || (recv_field_data[1] != -2.0))
PUT_ERR("ERROR: wrong results from multi field exchange");
if (exchange_type) {
dummy_field_id, collection_size, NULL, &info, &ierror);
dummy_field_id, field_id, collection_size, NULL, recv_field,
&info, &info, &ierror);
} else {
yac_cget(field_id, collection_size, recv_field, &info, &ierror);
}
{
MPI_Comm internal_comm;
int internal_instance_id;
internal_instance_id, "2000-01-01T00:00:00", "2000-01-01T00:00:12");
int internal_comp_id;
int nbr_vertices = 2*3;
int grid_id_C;
"grid_C", nbr_vertices, x_vertices, y_vertices, &grid_id_C);
int point_id_C;
x_vertices, y_vertices, &point_id_C);
int field_id_src, field_id_tgt;
"B_to_C", internal_comp_id, &point_id_B, 1,
internal_instance_id, "comp_B", "grid_B", "B_to_C",
frac_mask_fallback_value);
"B_to_C", internal_comp_id, &point_id_C, 1, 1, "1",
int interp_stack_nnn;
int ext_couple_config;
double const scale_factor = 2.0;
double const scale_summand = 0.5;
ext_couple_config, scale_factor);
ext_couple_config, scale_summand);
internal_instance_id,
"comp_B", "grid_B", "B_to_C",
"comp_B", "grid_C", "B_to_C",
interp_stack_nnn, 0, 0, ext_couple_config);
int ierror;
int send_info, recv_info;
double * send_field_[1] = {&recv_field_data[0]};
double ** send_field[1] = {&send_field_[0]};
double send_frac_mask_data[2] = {1.0, 0.0};
double * send_frac_mask_[1] = {send_frac_mask_data};
double ** send_frac_mask[1] = {&send_frac_mask_[0]};
double recv_field_data_C[6] = {-1.0, -1.0, -1.0, -1.0, -1.0, -1.0};
double * recv_field[1] = {&recv_field_data_C[0]};
if (exchange_type)
field_id_src, field_id_tgt, collection_size,
send_field, send_frac_mask, recv_field,
&send_info, &recv_info, &ierror);
else
field_id_src, field_id_tgt, collection_size,
send_field_, send_frac_mask_, recv_field,
&send_info, &recv_info, &ierror);
double ref_recv_field_data_C[2][6] =
{{4.0, 4.0, 4.0, 4.0,
frac_mask_fallback_value, frac_mask_fallback_value},
{3.0, 3.0, 3.0, 3.0,
frac_mask_fallback_value, frac_mask_fallback_value}};
for (int i = 0; i < 6; ++i)
if (recv_field_data_C[i] !=
scale_factor * ref_recv_field_data_C[with_field_mask][i] +
scale_summand)
PUT_ERR("data missmatch");
MPI_Comm_free(&internal_comm);
}
}
int main(int argc, char **argv)
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)
void yac_cenddef_instance(int yac_instance_id)
void yac_cget_ext_couple_config(int *ext_couple_config_id)
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)
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