28 double const tgt_coords[3],
int src_cell_id,
size_t src_cell_idx,
29 int const ** global_results_points,
double ** result_weights,
31static inline void LLtoXYZ(
double lon,
double lat,
double p_out[]);
32static inline void XYZtoLL (
double const p_in[],
double * lon,
double * lat);
34#define STR_USAGE "Usage: %s -c configFilename -g gridFilename\n"
35#define YAC_ASSERT_ARGS(exp, msg) \
38 fprintf(stderr, "ERROR: %s\n" STR_USAGE, msg, argv[0]); \
44 int argc,
char ** argv,
45 char const ** configFilename,
char const ** gridFilename);
47int main (
int argc,
char *argv[]) {
52 xt_initialize(MPI_COMM_WORLD);
54 char const * configFilename =
"toy_callback.yaml";
55 char const * gridFilename =
"icon_grid_0043_R02B04_G.nc";
61 char * comp_name =
"ICON";
69 MPI_Comm_rank(local_comm,&rank);
70 MPI_Comm_size(local_comm,&size);
72 MPI_Comm_free(&local_comm);
85 int * num_vertices_per_cell;
87 int * cell_to_vertex_offset;
96 int * global_corner_id;
97 int * corner_core_mask;
101 &x_vertices, &y_vertices, &x_cells,
102 &y_cells, &global_cell_id,
105 &corner_core_mask, rank, size);
107 cell_to_vertex_offset = malloc(
num_cells *
sizeof(*cell_to_vertex_offset));
108 for (
int i = 0, accu = 0; i <
num_cells; ++i) {
109 cell_to_vertex_offset[i] = accu;
110 accu += num_vertices_per_cell[i];
113 double * x_points, * y_points;
115 x_points = x_vertices;
116 y_points = y_vertices;
118 double * x_center, * y_center;
124 "icon_grid", num_vertices,
num_cells, num_vertices_per_cell,
158 double * cell_out = malloc(
num_cells *
sizeof(*cell_out));
159 double * corner_out = malloc(num_vertices *
sizeof(*corner_out));
165 double middle_point[3] = {0, 0, 0};
169 double curr_point[3];
175 middle_point[0] += curr_point[0];
176 middle_point[1] += curr_point[1];
177 middle_point[2] += curr_point[2];
180 double scale = 1.0 / sqrt(middle_point[0] * middle_point[0] +
181 middle_point[1] * middle_point[1] +
182 middle_point[2] * middle_point[2]);
184 middle_point[0] *= scale;
185 middle_point[1] *= scale;
186 middle_point[2] *= scale;
190 XYZtoLL(middle_point, &lon, &lat);
194 for (
int i = 0;
i < num_vertices; ++
i)
198 double *point_set_data[2];
199 double **collection_data[1] = {point_set_data};
201 point_set_data[0] = cell_out;
202 point_set_data[1] = corner_out;
211 char vtk_filename[32];
213 sprintf(vtk_filename,
"toy_icon_callback_%d.vtk", rank);
217 vtk_file, x_vertices, y_vertices, num_vertices);
221 vtk_file, corner_core_mask, num_vertices,
"corner_core_mask");
231 vtk_file, corner_out, num_vertices,
"corner_out");
254 free(corner_core_mask);
262 double const tgt_coords[3],
int src_cell_id,
size_t src_cell_idx,
263 int const ** global_results_points,
double ** result_weights,
264 size_t * result_count,
void *
user_data) {
270 for (
size_t i = 0; i < 2; ++i) {
271 global_results_points[i] = NULL;
272 result_weights[i] = NULL;
277 if ((info->global_cell_id[src_cell_idx] != src_cell_id) ||
278 (!info->cell_core_mask[src_cell_idx])) {
279 fputs(
"ERROR(compute_weights_callback): inconsistent data\n", stderr);
283 static double cell_weight[1] = {0.5};
284 static double vertex_weights[4] = {0.125, 0.125, 0.125, 0.125};
286 static int cell_result_points[1];
287 static int vertex_result_points[4];
289 for (
int i = 0; i < info->num_vertices_per_cell[src_cell_idx]; ++i)
290 vertex_result_points[i] =
291 (
int)(info->global_corner_id[
292 info->cell_to_vertex[
293 info->cell_to_vertex_offset[src_cell_idx] + i]]);
294 cell_result_points[0] = (int)src_cell_id;
296 global_results_points[0] = cell_result_points;
297 global_results_points[1] = vertex_result_points;
298 result_weights[0] = cell_weight;
299 result_weights[1] = vertex_weights;
305 int argc,
char ** argv,
306 char const ** configFilename,
char const ** gridFilename) {
309 while ((opt = getopt(argc, argv,
"c:g:")) != -1) {
310 YAC_ASSERT_ARGS((opt ==
'c') || (opt ==
'g'),
"invalid command argument")
314 *configFilename = optarg;
317 *gridFilename = optarg;
323static inline void LLtoXYZ(
double lon,
double lat,
double p_out[]) {
325 while (lon < -M_PI) lon += 2.0 * M_PI;
326 while (lon >= M_PI) lon -= 2.0 * M_PI;
328 double cos_lat = cos(lat);
329 p_out[0] = cos_lat * cos(lon);
330 p_out[1] = cos_lat * sin(lon);
334static inline void XYZtoLL (
double const p_in[],
double * lon,
double * lat) {
336 *lon = atan2(p_in[1] , p_in[0]);
337 *lat = M_PI_2 - acos(p_in[2]);
void yac_read_part_icon_grid_information(const char *filename, int *nbr_vertices, int *nbr_cells, int **num_vertices_per_cell, int **cell_to_vertex, double **x_vertices, double **y_vertices, double **x_cells, double **y_cells, int **global_cell_id, int **cell_mask, int **cell_core_mask, int **global_corner_id, int **corner_core_mask, int rank, int size)
int * num_vertices_per_cell
int * cell_to_vertex_offset
double yac_test_func(double lon, double lat)
static void parse_arguments(int argc, char **argv, char const **configFilename, char const **gridFilename)
#define YAC_ASSERT_ARGS(exp, msg)
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 LLtoXYZ(double lon, double lat, double p_out[])
static void XYZtoLL(double const p_in[], double *lon, double *lat)
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_ll(YAC_VTK_FILE *vtk_file, double *point_data_lon, double *point_data_lat, unsigned num_points)
void yac_vtk_write_point_scalars_double(YAC_VTK_FILE *vtk_file, double *scalars, unsigned num_points, char *name)
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)
int const YAC_LOCATION_CELL
void yac_cadd_compute_weights_callback(yac_func_compute_weights compute_weights_callback, void *user_data, char const *key)
void yac_cfinalize()
Finalises YAC.
int const YAC_LOCATION_CORNER
void yac_cget_comp_comm(int comp_id, MPI_Comm *comp_comm)
int const YAC_TIME_UNIT_SECOND
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_cread_config_yaml(const char *yaml_filename)
void yac_cset_core_mask(int const *is_core, int location, int grid_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)