YAC 3.13.0
Yet Another Coupler
Loading...
Searching...
No Matches
test_generate_cubed_sphere.c
Go to the documentation of this file.
1// Copyright (c) 2024 The YAC Authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#include <unistd.h>
6#include <string.h>
7
8#include "tests.h"
10#include "grid2vtk.h"
11#include "read_icon_grid.h"
12
18int main(void) {
19
20 {
21 unsigned n = 20;
22
23 struct yac_basic_grid_data cube_grid =
25
26 if (cube_grid.num_cells != n * n * 6)
27 PUT_ERR("ERROR: wrong number of cells\n");
28
29 if (cube_grid.num_vertices != n * n * 6 + 2)
30 PUT_ERR("ERROR: wrong number of grid vertices\n")
31
32// #define WRITE_VTK_GRID_FILE
33#ifdef WRITE_VTK_GRID_FILE
34 yac_write_basic_grid_data_to_file(&cube_grid, "cubed_sphere");
35#endif // WRITE_VTK_GRID_FILE
36
37 yac_basic_grid_data_free(cube_grid);
38 }
39
40 {
41 unsigned n = 10;
42
43 struct yac_basic_grid * cube_grid =
45
46 if (yac_basic_grid_get_data_size(cube_grid, YAC_LOC_CELL) != n * n * 6)
47 PUT_ERR("ERROR: wrong number of cells\n");
48
49 if (yac_basic_grid_get_data_size(cube_grid, YAC_LOC_CORNER) != n * n * 6 + 2)
50 PUT_ERR("ERROR: wrong number of grid vertices\n")
51
52 if (strcmp(yac_basic_grid_get_name(cube_grid), "cube_10"))
53 PUT_ERR("ERROR: wrong name\n");
54
55 yac_basic_grid_delete(cube_grid);
56 }
57
58 {
59 unsigned n = 32;
60 unsigned ref_num_core_cells = n * n * 6;
61 int sizes[] = {1,3,6,11};
62 for (size_t i = 0; i < (sizeof(sizes)/sizeof(sizes[0])); ++i) {
63
64 unsigned num_core_cells = 0;
65
66 for (int rank = 0, size = sizes[i]; rank < size; ++rank) {
67
68 unsigned nbr_vertices;
69 unsigned nbr_cells;
70 unsigned * num_vertices_per_cell;
71 unsigned * cell_to_vertex;
72 double * x_vertices;
73 double * y_vertices;
74 double * x_cells;
75 double * y_cells;
76 int * global_cell_id;
77 int * cell_core_mask;
78 int * global_corner_id;
79 int * corner_core_mask;
80
82 n, &nbr_vertices, &nbr_cells, &num_vertices_per_cell, &cell_to_vertex,
83 &x_vertices, &y_vertices, &x_cells, &y_cells,
84 &global_cell_id, &cell_core_mask, &global_corner_id, &corner_core_mask,
85 rank, size);
86
87 for (unsigned j = 0; j < nbr_cells; ++j)
88 if (cell_core_mask[j]) ++num_core_cells;
89
90 free(num_vertices_per_cell);
91 free(cell_to_vertex);
92 free(x_vertices);
93 free(y_vertices);
94 free(x_cells);
95 free(y_cells);
96 free(global_cell_id);
97 free(cell_core_mask);
98 free(global_corner_id);
99 free(corner_core_mask);
100 }
101 if (ref_num_core_cells != num_core_cells)
102 PUT_ERR("wrong number of cells");
103 }
104 }
105
106 {
107 char const * grid_filename = "test_generate_cubed_sphere.nc";
108
109 unsigned n = 20;
110
111 yac_write_cubed_sphere_grid(n, grid_filename);
112
113 struct yac_basic_grid_data cube_grid =
114 yac_read_icon_basic_grid_data(grid_filename);
115
116 if (cube_grid.num_cells != n * n * 6)
117 PUT_ERR("ERROR: wrong number of cells\n");
118
119 if (cube_grid.num_vertices != n * n * 6 + 2)
120 PUT_ERR("ERROR: wrong number of grid vertices\n")
121
122// #define WRITE_VTK_GRID_FILE
123#ifdef WRITE_VTK_GRID_FILE
124 yac_write_basic_grid_data_to_file(&cube_grid, "cube");
125#endif // WRITE_VTK_GRID_FILE
126
127 yac_basic_grid_data_free(cube_grid);
128
129 unlink(grid_filename);
130 }
131
132 return TEST_EXIT_CODE;
133}
134
char const * yac_basic_grid_get_name(struct yac_basic_grid *grid)
Definition basic_grid.c:131
size_t yac_basic_grid_get_data_size(struct yac_basic_grid *grid, enum yac_location location)
Definition basic_grid.c:150
void yac_basic_grid_delete(struct yac_basic_grid *grid)
Definition basic_grid.c:73
void yac_basic_grid_data_free(struct yac_basic_grid_data grid)
void yac_generate_part_cube_grid_information(unsigned n, unsigned *nbr_vertices, unsigned *nbr_cells, unsigned **num_vertices_per_cell, unsigned **cell_to_vertex, double **x_vertices, double **y_vertices, double **x_cells, double **y_cells, int **global_cell_id, int **cell_core_mask, int **global_corner_id, int **corner_core_mask, int rank, int size)
void yac_write_cubed_sphere_grid(unsigned n, char const *filename)
struct yac_basic_grid * yac_generate_cubed_sphere_basic_grid(char const *name, size_t n)
struct yac_basic_grid_data yac_generate_cubed_sphere_grid(unsigned n)
void yac_write_basic_grid_data_to_file(struct yac_basic_grid_data *grid, char const *name)
Definition grid2vtk.c:54
@ YAC_LOC_CORNER
Definition location.h:15
@ YAC_LOC_CELL
Definition location.h:14
struct yac_basic_grid_data yac_read_icon_basic_grid_data(char const *filename)
int * cell_to_vertex
#define TEST_EXIT_CODE
Definition tests.h:14
#define PUT_ERR(string)
Definition tests.h:10
int * cell_core_mask
char const * name
Definition toy_scrip.c:114