YetAnotherCoupler 3.5.2
Loading...
Searching...
No Matches
test_dummy_coupling9_c.c

This test checks the setting and usage of named masks.

// Copyright (c) 2024 The YAC Authors
//
// SPDX-License-Identifier: BSD-3-Clause
#include <mpi.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <float.h>
#include "tests.h"
#include "test_common.h"
#include "yac.h"
enum {
COLLECTION_SIZE = 3,
NUM_POINTSETS = 1,
NUM_POINTS = 9
};
static char const * mask_types[3] =
{"even", "odd", "none"};
typedef int (*func_check_src_ptr)(
double value, int idx, int collection_idx, int with_field_mask);
typedef int (*func_check_tgt_ptr)(
double value, int idx, int collection_idx, int with_field_mask,
func_check_src_ptr check_src);
static int check_src_no_mask(
double value, int idx, int collection_idx, int with_field_mask);
static int check_src_even_mask(
double value, int idx, int collection_idx, int with_field_mask);
static int check_src_odd_mask(
double value, int idx, int collection_idx, int with_field_mask);
static int check_tgt_no_mask(
double value, int idx, int collection_idx, int with_field_mask,
func_check_src_ptr check_src);
static int check_tgt_even_mask(
double value, int idx, int collection_idx, int with_field_mask,
func_check_src_ptr check_src);
static int check_tgt_odd_mask(
double value, int idx, int collection_idx, int with_field_mask,
func_check_src_ptr check_src);
func_check_src_ptr check_src[3] = {
check_src_even_mask, check_src_odd_mask, check_src_no_mask};
func_check_tgt_ptr check_tgt[3] = {
check_tgt_even_mask, check_tgt_odd_mask, check_tgt_no_mask};
int main(int argc, char** argv) {
if (argc != 2) {
PUT_ERR("ERROR: missing config file directory");
MPI_Finalize();
return TEST_EXIT_CODE;
}
char * yaml_filename =
strcat(
strcpy(
malloc(strlen(argv[1]) + 32), argv[1]), "coupling_test9.yaml");
yac_cread_config_yaml(yaml_filename);
free(yaml_filename);
int size, rank;
MPI_Comm_rank ( MPI_COMM_WORLD, &rank );
MPI_Comm_size ( MPI_COMM_WORLD, &size );
if (size != 2) {
fputs("wrong number of processes (has to be 2)\n", stderr);
exit(EXIT_FAILURE);
}
int is_target = rank == 1;
// define local component
int comp_id;
char const * src_comp_name = "source_comp";
char const * tgt_comp_name = "target_comp";
yac_cdef_comp((is_target)?tgt_comp_name:src_comp_name, &comp_id);
// define grid (both components use an identical grid)
int grid_id;
char const * src_grid_name = "source_grid";
char const * tgt_grid_name = "target_grid";
(is_target)?tgt_grid_name:src_grid_name, (int[2]){3,3}, (int[2]){0,0},
(double[]){0,1,2}, (double[]){0,1,2}, &grid_id);
// define points at the vertices of the grid
int point_id;
grid_id, (int[2]){3,3}, YAC_LOCATION_CORNER,
(double[]){0,1,2}, (double[]){0,1,2}, &point_id);
// define masks for vertices
int default_mask_id, dummy_mask_id;
grid_id, 3*3, YAC_LOCATION_CORNER,
(int[3*3]){1,0,0, 0,0,0, 0,0,0}, &default_mask_id);
char const * even_mask_name = "even_mask";
grid_id, 3*3, YAC_LOCATION_CORNER,
(int[3*3]){1,0,1, 0,1,0, 1,0,1}, even_mask_name, &dummy_mask_id);
char const * odd_mask_name = "odd_mask";
grid_id, 3*3, YAC_LOCATION_CORNER,
(int[3*3]){0,1,0, 1,0,1, 0,1,0}, odd_mask_name, &dummy_mask_id);
// define field
int field_ids[2][2][3][3];
for (int config_from_file = 0; config_from_file < 2; ++config_from_file) {
for (int with_field_mask = 0; with_field_mask < 2; ++with_field_mask) {
for (int source_mask_type = 0; source_mask_type < 3; ++source_mask_type) {
for (int target_mask_type = 0; target_mask_type < 3; ++target_mask_type) {
char field_name[128];
sprintf(
field_name, "src2tgt_%s_%s_field_mask_%s_src_mask_%s_tgt_mask",
config_from_file?"yaml":"manual",
with_field_mask?"with":"without",
mask_types[source_mask_type],
mask_types[target_mask_type]);
if (with_field_mask) {
field_name, comp_id, &point_id, &default_mask_id, NUM_POINTSETS,
COLLECTION_SIZE, "1", YAC_TIME_UNIT_SECOND,
&field_ids[config_from_file]
[with_field_mask]
[source_mask_type]
[target_mask_type]);
} else {
field_name, comp_id, &point_id, NUM_POINTSETS,
COLLECTION_SIZE, "1", YAC_TIME_UNIT_SECOND,
&field_ids[config_from_file]
[with_field_mask]
[source_mask_type]
[target_mask_type]);
}
}
}
}
}
// define manual couples
int interp_stack_config;
yac_cget_interp_stack_config(&interp_stack_config);
interp_stack_config, YAC_NNN_AVG, 1, 0.0, 0.0);
int ext_couple_config;
yac_cget_ext_couple_config(&ext_couple_config);
for (int with_field_mask = 0; with_field_mask < 2; ++with_field_mask) {
for (int source_mask_type = 0; source_mask_type < 3; ++source_mask_type) {
for (int target_mask_type = 0; target_mask_type < 3; ++target_mask_type) {
if (source_mask_type != 2)
ext_couple_config, 1, source_mask_type?&odd_mask_name:&even_mask_name);
else
yac_cset_ext_couple_config_src_mask_names(ext_couple_config, 0, NULL);
if (target_mask_type != 2)
ext_couple_config, target_mask_type?odd_mask_name:even_mask_name);
else
yac_cset_ext_couple_config_tgt_mask_name(ext_couple_config, NULL);
size_t num_src_maks_names;
char const * const * src_mask_names;
ext_couple_config, &num_src_maks_names, &src_mask_names);
if ((num_src_maks_names != (source_mask_type != 2)) ||
((source_mask_type == 2) && (src_mask_names != NULL)) ||
((source_mask_type != 2) &&
strcmp(src_mask_names[0],
source_mask_type?odd_mask_name:even_mask_name)))
PUT_ERR("ERROR in yac_cget_ext_couple_config_src_mask_names");
char const * tgt_mask_name;
yac_cget_ext_couple_config_tgt_mask_name(ext_couple_config, &tgt_mask_name);
if (((target_mask_type == 2) && (tgt_mask_name != NULL)) ||
((target_mask_type != 2) &&
strcmp(tgt_mask_name, target_mask_type?odd_mask_name:even_mask_name)))
PUT_ERR("ERROR in yac_cget_ext_couple_config_tgt_mask_name");
char field_name[128];
sprintf(
field_name, "src2tgt_manual_%s_field_mask_%s_src_mask_%s_tgt_mask",
with_field_mask?"with":"without",
mask_types[source_mask_type],
mask_types[target_mask_type]);
src_comp_name, src_grid_name, field_name,
tgt_comp_name, tgt_grid_name, field_name,
interp_stack_config, 0, 0, ext_couple_config);
}
}
}
char const * dummy_mask_name = "dummy_src_mask";
ext_couple_config, 1, &dummy_mask_name);
yac_cfree_ext_couple_config(ext_couple_config);
yac_cfree_interp_stack_config(interp_stack_config);
double send_field[COLLECTION_SIZE][NUM_POINTSETS][NUM_POINTS] =
{{{ 0, 1, 2, 3, 4, 5, 6, 7, 8}},
{{10,11,12,13,14,15,16,17,18}},
{{20,21,22,23,24,25,26,27,28}}};
// do time steps
for (int t = 0; t < 4; ++t) {
if (!is_target) {
for (int config_from_file = 0; config_from_file < 2; ++config_from_file) {
for (int with_field_mask = 0; with_field_mask < 2; ++with_field_mask) {
for (int source_mask_type = 0; source_mask_type < 3; ++source_mask_type) {
for (int target_mask_type = 0; target_mask_type < 3; ++target_mask_type) {
int info, ierror;
field_ids[config_from_file]
[with_field_mask]
[source_mask_type]
[target_mask_type],
COLLECTION_SIZE, &send_field[0][0][0], &info, &ierror);
field_ids[config_from_file]
[with_field_mask]
[source_mask_type]
[target_mask_type]);
if (info != YAC_ACTION_COUPLING)
PUT_ERR("error in yac_cput_: wrong info");
if (ierror) PUT_ERR("error in yac_cput_: wrong ierror");
}
}
}
}
} else {
for (int config_from_file = 0; config_from_file < 2; ++config_from_file) {
for (int with_field_mask = 0; with_field_mask < 2; ++with_field_mask) {
for (int source_mask_type = 0; source_mask_type < 3; ++source_mask_type) {
for (int target_mask_type = 0; target_mask_type < 3; ++target_mask_type) {
// initialise recv_field
double recv_field[COLLECTION_SIZE][NUM_POINTS];
for (int j = 0; j < COLLECTION_SIZE; ++j)
for (int k = 0; k < NUM_POINTS; ++k)
recv_field[j][k] = -1;
int info, ierror;
if (t & 1) {
field_ids[config_from_file]
[with_field_mask]
[source_mask_type]
[target_mask_type],
COLLECTION_SIZE, &recv_field[0][0], &info, &ierror);
} else {
field_ids[config_from_file]
[with_field_mask]
[source_mask_type]
[target_mask_type],
COLLECTION_SIZE, &recv_field[0][0], &info, &ierror);
yac_cwait(field_ids[config_from_file]
[with_field_mask]
[source_mask_type]
[target_mask_type]);
}
if (info != YAC_ACTION_COUPLING)
PUT_ERR("error in yac_cget_: wrong info");
if (ierror) PUT_ERR("error in yac_cget_: wrong ierror");
for (int j = 0; j < COLLECTION_SIZE; ++j)
for (int k = 0; k < NUM_POINTS; ++k)
if (check_tgt[target_mask_type](
recv_field[j][k], k, j, with_field_mask,
check_src[source_mask_type]))
PUT_ERR("error in yac_cget_: wrong recv_field");
}
}
}
}
}
}
return TEST_EXIT_CODE;
}
static int check_src_even_mask(
double value, int idx, int collection_idx, int with_field_mask) {
UNUSED(idx);
UNUSED(collection_idx);
UNUSED(with_field_mask);
return (int)value & 1;
}
static int check_src_odd_mask(
double value, int idx, int collection_idx, int with_field_mask) {
UNUSED(idx);
UNUSED(collection_idx);
UNUSED(with_field_mask);
return !((int)value & 1);
}
static int check_src_no_mask(
double value, int idx, int collection_idx, int with_field_mask) {
return
with_field_mask?
((int)value != (10 * collection_idx)):
((int)value != idx + 10 * collection_idx);
}
static int check_tgt_even_mask(
double value, int idx, int collection_idx, int with_field_mask,
func_check_src_ptr check_src) {
return
(idx&1)?
(value != -1.0):check_src(value, idx, collection_idx, with_field_mask);
}
static int check_tgt_odd_mask(
double value, int idx, int collection_idx, int with_field_mask,
func_check_src_ptr check_src) {
return
(idx&1)?
check_src(value, idx, collection_idx, with_field_mask):(value != -1.0);
}
static int check_tgt_no_mask(
double value, int idx, int collection_idx, int with_field_mask,
func_check_src_ptr check_src) {
return
(with_field_mask && idx)?
(value != -1.0):check_src(value, idx, collection_idx, with_field_mask);
}
#define UNUSED(x)
Definition core.h:73
int main(int argc, char **argv)
struct @7::@8 value
void yac_cenddef(void)
Definition yac.c:3000
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)
Definition yac.c:1143
void yac_cget_(int const field_id, int const collection_size, double *recv_field, int *info, int *ierr)
Definition yac.c:1989
void yac_cfree_ext_couple_config(int ext_couple_config_id)
Definition yac.c:1373
void yac_cset_ext_couple_config_tgt_mask_name(int ext_couple_config_id, char const *tgt_mask_name)
Definition yac.c:1520
void yac_cinit(void)
Definition yac.c:419
void yac_cfinalize()
Definition yac.c:619
void yac_cset_ext_couple_config_src_mask_names(int ext_couple_config_id, size_t num_src_mask_names, char const *const *src_mask_names)
Definition yac.c:1495
void yac_cget_ext_couple_config(int *ext_couple_config_id)
Definition yac.c:1365
int const YAC_LOCATION_CORNER
Definition yac.c:28
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)
Definition yac.c:1600
void yac_cget_ext_couple_config_tgt_mask_name(int ext_couple_config_id, char const **tgt_mask_name)
Definition yac.c:1527
void yac_cget_ext_couple_config_src_mask_names(int ext_couple_config_id, size_t *num_src_mask_names, char const *const **src_mask_names)
Definition yac.c:1503
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)
Definition yac.c:3416
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)
Definition yac.c:976
int const YAC_TIME_UNIT_SECOND
Definition yac.c:52
void yac_cread_config_yaml(const char *yaml_filename)
Definition yac.c:474
void yac_cdef_calendar(int calendar)
Definition yac.c:648
void yac_cwait(int field_id)
Definition yac.c:2247
void yac_cput_(int const field_id, int const collection_size, double *send_field, int *info, int *ierr)
Definition yac.c:2074
int const YAC_PROLEPTIC_GREGORIAN
Definition yac.c:61
void yac_cget_async_(int const field_id, int const collection_size, double *recv_field, int *info, int *ierr)
Definition yac.c:1998
int const YAC_ACTION_COUPLING
data exchange
Definition yac.c:37
void yac_cdef_mask(int const grid_id, int const nbr_points, int const located, int const *is_valid, int *mask_id)
Definition yac.c:1115
void yac_cdef_mask_named(int const grid_id, int const nbr_points, int const located, int const *is_valid, char const *name, int *mask_id)
Definition yac.c:1096
void yac_cfree_interp_stack_config(int interp_stack_config_id)
Definition yac.c:3681
int const YAC_NNN_AVG
Definition yac.c:72
void yac_cadd_interp_stack_config_nnn(int interp_stack_config_id, int type, size_t n, double max_search_distance, double scale)
Definition yac.c:3738
void yac_cget_interp_stack_config(int *interp_stack_config_id)
Definition yac.c:3667
void yac_cdef_comp(char const *comp_name, int *comp_id)
Definition yac.c:886
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)
Definition yac.c:1216
int const YAC_REDUCTION_TIME_NONE
Definition yac.c:45