YAC 3.12.0
Yet Another Coupler
Loading...
Searching...
No Matches
test_basic_grid_data.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 <stdlib.h>
6#include <stdio.h>
7#include <math.h>
8#include <string.h>
9
10#include "tests.h"
12#include "geometry.h"
13#include "ensure_array_size.h"
14#include "area.h"
15#include "test_common.h"
16
28
29static void utest_test_grid_data__1x1(
30 struct yac_basic_grid_data grid, char * grid_name, enum grid_type type) {
31
32 double ref_coords_x[4] = {0.5,1.5,0.5,1.5};
33 double ref_coords_y[4] = {0.5,0.5,1.5,1.5};
34 double vertex_coordinates[4][3];
35 for (size_t i = 0; i < 4; ++i)
36 LLtoXYZ_deg(ref_coords_x[i], ref_coords_y[i], vertex_coordinates[i]);
37
38 enum yac_edge_type reg2d_edge_type[] =
40 enum yac_edge_type unstruct_edge_type[] =
42 enum yac_edge_type * ref_edge_type =
43 (type == REG2D)?reg2d_edge_type:unstruct_edge_type;
44
45 struct yac_basic_grid_data ref_grid_data = {
47 .cell_ids = NULL,
48 .vertex_ids = NULL,
49 .edge_ids = NULL,
50 .num_cells = 1,
51 .num_vertices = 4,
52 .num_edges = 4,
53 .core_cell_mask = NULL,
54 .core_vertex_mask = NULL,
55 .core_edge_mask = NULL,
56 .num_vertices_per_cell = (int[]){4},
57 .num_cells_per_vertex = (int[]){1,1,1,1},
58 .cell_to_vertex = (size_t[]){0,1,3,2},
59 .cell_to_vertex_offsets = (size_t[]){0},
60 .cell_to_edge = (size_t[]){0,2,3,1},
61 .cell_to_edge_offsets = (size_t[]){0},
62 .vertex_to_cell = (size_t[]){0,0,0,0},
63 .vertex_to_cell_offsets = (size_t[]){0,1,2,3},
64 .edge_to_vertex = (size_t[][2]){{0,1},{0,2},{1,3},{2,3}},
65 .edge_type = ref_edge_type,
66 .num_total_cells = 1,
67 .num_total_vertices = 4,
68 .num_total_edges = 4};
69
70 check_basic_grid_data(grid, ref_grid_data, grid_name);
71}
72
73static void utest_test_grid_data__2x2(
74 struct yac_basic_grid_data grid, char * grid_name, enum grid_type type) {
75
76 double ref_coords_x[9] = {0,1,2,0,1,2,0,1,2};
77 double ref_coords_y[9] = {0,0,0,1,1,1,2,2,2};
78 double vertex_coordinates[9][3];
79 for (size_t i = 0; i < 9; ++i)
80 LLtoXYZ_deg(ref_coords_x[i], ref_coords_y[i], vertex_coordinates[i]);
81
82 enum yac_edge_type reg2d_edge_type[] =
86 enum yac_edge_type unstruct_edge_type[] =
90 enum yac_edge_type * ref_edge_type =
91 (type == REG2D)?reg2d_edge_type:unstruct_edge_type;
92
93 struct yac_basic_grid_data ref_grid_data = {
95 .cell_ids = NULL,
96 .vertex_ids = NULL,
97 .edge_ids = NULL,
98 .num_cells = 4,
99 .num_vertices = 9,
100 .num_edges = 12,
101 .core_cell_mask = NULL,
102 .core_vertex_mask = NULL,
103 .core_edge_mask = NULL,
104 .num_vertices_per_cell = (int[]){4,4,4,4},
105 .num_cells_per_vertex = (int[]){1,2,1, 2,4,2, 1,2,1},
106 .cell_to_vertex = (size_t[]){0,1,4,3, 1,2,5,4, 3,4,7,6, 4,5,8,7},
107 .cell_to_vertex_offsets = (size_t[]){0,4,8,12},
108 .cell_to_edge = (size_t[]){0,3,5,1, 2,4,7,3, 5,8,10,6, 7,9,11,8},
109 .cell_to_edge_offsets = (size_t[]){0,4,8,12},
110 .vertex_to_cell = (size_t[]){0, 0,1, 1, 0,2, 0,1,2,3, 1,3, 2, 2,3, 3},
111 .vertex_to_cell_offsets = (size_t[]){0, 1, 3, 4, 6, 10, 12, 13, 15, 16},
112 .edge_to_vertex = (size_t[][2]){{0,1},{0,3},{1,2},{1,4},{2,5},
113 {3,4},{3,6},{4,5},{4,7},{5,8},
114 {6,7},{7,8}},
115 .edge_type = ref_edge_type,
116 .num_total_cells = 4,
117 .num_total_vertices = 9,
118 .num_total_edges = 12};
119
120 double ref_cell_areas[4];
121 {
122 double cell_coords_x[2][4] = {{0,1,1,0},{1,2,2,1}};
123 double cell_coords_y[2][4] = {{0,0,1,1},{1,1,2,2}};
124 enum yac_edge_type edge_types[2][4] =
129 for (size_t i = 0, k = 0; i < 2; ++i) {
130 for (size_t j = 0; j < 2; ++j, ++k) {
131 struct yac_grid_cell cell =
133 cell_coords_x[j], cell_coords_y[i], edge_types[type == REG2D], 4);
134 ref_cell_areas[k] = yac_huiliers_area(cell);
135 yac_free_grid_cell(&cell);
136 }
137 }
138 }
139
140 double cell_areas[4];
142
143 for (size_t i = 0; i < 4; ++i)
144 if (fabs(ref_cell_areas[i] - cell_areas[i]) > YAC_AREA_TOL)
145 PUT_ERR("ERROR in yac_basic_grid_data_compute_cell_areas");
146
147 check_basic_grid_data(grid, ref_grid_data, grid_name);
148}
149
150static void utest_test_grid_data__2x3(
151 struct yac_basic_grid_data grid, char * grid_name, enum grid_type type) {
152
153 double ref_coords_x[12] = {0,1,2,0,1,2,0,1,2,0,1,2};
154 double ref_coords_y[12] = {0,0,0,1,1,1,2,2,2,3,3,3};
155 double vertex_coordinates[12][3];
156 for (size_t i = 0; i < 12; ++i)
157 LLtoXYZ_deg(ref_coords_x[i], ref_coords_y[i], vertex_coordinates[i]);
158
159 enum yac_edge_type reg2d_edge_type[] =
165 enum yac_edge_type unstruct_edge_type[] =
171 enum yac_edge_type * ref_edge_type =
172 (type == REG2D)?reg2d_edge_type:unstruct_edge_type;
173
174 struct yac_basic_grid_data ref_grid_data = {
176 .cell_ids = NULL,
177 .vertex_ids = NULL,
178 .edge_ids = NULL,
179 .num_cells = 6,
180 .num_vertices = 12,
181 .num_edges = 17,
182 .core_cell_mask = NULL,
183 .core_vertex_mask = NULL,
184 .core_edge_mask = NULL,
185 .num_vertices_per_cell = (int[]){4,4,4,4,4,4},
186 .num_cells_per_vertex = (int[]){1,2,1, 2,4,2, 2,4,2, 1,2,1},
187 .cell_to_vertex = (size_t[]){0,1,4,3, 1,2,5,4, 3,4,7,6, 4,5,8,7,
188 6,7,10,9, 7,8,11,10},
189 .cell_to_vertex_offsets = (size_t[]){0,4,8,12,16,20},
190 .cell_to_edge = (size_t[]){0,3,5,1, 2,4,7,3, 5,8,10,6,
191 7,9,12,8, 10,13,15,11, 12,14,16,13},
192 .cell_to_edge_offsets = (size_t[]){0,4,8,12,16,20},
193 .vertex_to_cell = (size_t[]){0, 0,1, 1, 0,2, 0,1,2,3, 1,3,
194 2,4, 2,3,4,5, 3,5, 4, 4,5, 5},
195 .vertex_to_cell_offsets = (size_t[]){0,1,3,4,6,10,12,14,18,20,21,23,24},
196 .edge_to_vertex = (size_t[][2]){{0,1},{0,3},{1,2},{1,4},{2,5},
197 {3,4},{3,6},{4,5},{4,7},{5,8},
198 {6,7},{6,9},{7,8},{7,10},{8,11},
199 {9,10},{10,11}},
200 .edge_type = ref_edge_type,
201 .num_total_cells = 6,
202 .num_total_vertices = 12,
203 .num_total_edges = 17};
204
205 check_basic_grid_data(grid, ref_grid_data, grid_name);
206}
207
208static void utest_test_grid_data__3x3(
209 struct yac_basic_grid_data grid, char * grid_name, enum grid_type type) {
210
211 double ref_coords_x[16] = {0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3};
212 double ref_coords_y[16] = {0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3};
213 double vertex_coordinates[16][3];
214 for (size_t i = 0; i < 16; ++i)
215 LLtoXYZ_deg(ref_coords_x[i], ref_coords_y[i], vertex_coordinates[i]);
216
217 enum yac_edge_type reg2d_edge_type[] =
224 enum yac_edge_type unstruct_edge_type[] =
231 enum yac_edge_type * ref_edge_type =
232 (type == REG2D)?reg2d_edge_type:unstruct_edge_type;
233
234 struct yac_basic_grid_data ref_grid_data = {
236 .cell_ids = NULL,
237 .vertex_ids = NULL,
238 .edge_ids = NULL,
239 .num_cells = 9,
240 .num_vertices = 16,
241 .num_edges = 24,
242 .core_cell_mask = NULL,
243 .core_vertex_mask = NULL,
244 .core_edge_mask = NULL,
245 .num_vertices_per_cell = (int[]){4,4,4,4,4,4,4,4,4},
246 .num_cells_per_vertex = (int[]){1,2,2,1, 2,4,4,2, 2,4,4,2, 1,2,2,1},
247 .cell_to_vertex = (size_t[]){0,1,5,4, 1,2,6,5, 2,3,7,6,
248 4,5,9,8, 5,6,10,9, 6,7,11,10,
249 8,9,13,12, 9,10,14,13, 10,11,15,14},
250 .cell_to_vertex_offsets = (size_t[]){0,4,8,12,16,20,24,28,32},
251 .cell_to_edge = (size_t[]){0,3,7,1, 2,5,9,3, 4,6,11,5,
252 7,10,14,8, 9,12,16,10, 11,13,18,12,
253 14,17,21,15, 16,19,22,17, 18,20,23,19},
254 .cell_to_edge_offsets = (size_t[]){0,4,8, 12,16,20, 24,28,32},
255 .vertex_to_cell = (size_t[]){0, 0,1, 1,2, 2,
256 0,3, 0,1,3,4, 1,2,4,5, 2,5,
257 3,6, 3,4,6,7, 4,5,7,8, 5,8,
258 6, 6,7, 7,8, 8},
259 .vertex_to_cell_offsets = (size_t[]){0,1,3,5,
260 6,8,12,16,
261 18,20,24,28,
262 30,31,33,35},
263 .edge_to_vertex = (size_t[][2]){{0,1},{0,4},{1,2},{1,5},{2,3},{2,6},{3,7},
264 {4,5},{4,8},{5,6},{5,9},{6,7},{6,10},{7,11},
265 {8,9},{8,12},{9,10},{9,13},{10,11},{10,14},{11,15},
266 {12,13},{13,14},{14,15}},
267 .edge_type = ref_edge_type,
268 .num_total_cells = 9,
269 .num_total_vertices = 16,
270 .num_total_edges = 24};
271
272 check_basic_grid_data(grid, ref_grid_data, grid_name);
273}
274
275static void utest_test_grid_data__3x3_cloud(
276 struct yac_basic_grid_data grid, char * grid_name) {
277
278 double ref_coords_x[16] = {0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3};
279 double ref_coords_y[16] = {0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3};
280 double vertex_coordinates[16][3];
281 for (size_t i = 0; i < 16; ++i)
282 LLtoXYZ_deg(ref_coords_x[i], ref_coords_y[i], vertex_coordinates[i]);
283
284 struct yac_basic_grid_data ref_grid_data = {
286 .cell_ids = NULL,
287 .vertex_ids = NULL,
288 .edge_ids = NULL,
289 .num_cells = 0,
290 .num_vertices = 16,
291 .num_edges = 0,
292 .core_cell_mask = NULL,
293 .core_vertex_mask = NULL,
294 .core_edge_mask = NULL,
295 .num_vertices_per_cell = NULL,
296 .num_cells_per_vertex = (int[]){0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0},
297 .cell_to_vertex = NULL,
298 .cell_to_vertex_offsets = NULL,
299 .cell_to_edge = NULL,
300 .cell_to_edge_offsets = NULL,
301 .vertex_to_cell = NULL,
302 .vertex_to_cell_offsets = (size_t[]){0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0},
303 .edge_to_vertex = NULL,
304 .edge_type = NULL,
305 .num_total_cells = 0,
306 .num_total_vertices = 16,
307 .num_total_edges = 0};
308
309 check_basic_grid_data(grid, ref_grid_data, grid_name);
310}
311
312static void utest_test_grid_data__3x3_reg2d_rot(
313 struct yac_basic_grid_data grid, char * grid_name,
314 double rot_axis[3], struct sin_cos_angle rot_angle) {
315
316 double ref_coords_x[16] = {-1.5,-0.5,0.5,1.5,
317 -1.5,-0.5,0.5,1.5,
318 -1.5,-0.5,0.5,1.5,
319 -1.5,-0.5,0.5,1.5};
320 double ref_coords_y[16] = {-1.5,-1.5,-1.5,-1.5,
321 -0.5,-0.5,-0.5,-0.5,
322 0.5, 0.5, 0.5, 0.5,
323 1.5, 1.5, 1.5, 1.5};
324 double vertex_coordinates[16][3];
325 for (size_t i = 0; i < 16; ++i) {
326 double temp[3];
327 LLtoXYZ_deg(ref_coords_x[i], ref_coords_y[i], temp);
328 rotate_vector2(rot_axis, rot_angle, temp, vertex_coordinates[i]);
329 }
330
331 enum yac_edge_type unstruct_edge_type[] =
338
339 struct yac_basic_grid_data ref_grid_data = {
341 .cell_ids = NULL,
342 .vertex_ids = NULL,
343 .edge_ids = NULL,
344 .num_cells = 9,
345 .num_vertices = 16,
346 .num_edges = 24,
347 .core_cell_mask = NULL,
348 .core_vertex_mask = NULL,
349 .core_edge_mask = NULL,
350 .num_vertices_per_cell = (int[]){4,4,4,4,4,4,4,4,4},
351 .num_cells_per_vertex = (int[]){1,2,2,1, 2,4,4,2, 2,4,4,2, 1,2,2,1},
352 .cell_to_vertex = (size_t[]){0,1,5,4, 1,2,6,5, 2,3,7,6,
353 4,5,9,8, 5,6,10,9, 6,7,11,10,
354 8,9,13,12, 9,10,14,13, 10,11,15,14},
355 .cell_to_vertex_offsets = (size_t[]){0,4,8,12,16,20,24,28,32},
356 .cell_to_edge = (size_t[]){0,3,7,1, 2,5,9,3, 4,6,11,5,
357 7,10,14,8, 9,12,16,10, 11,13,18,12,
358 14,17,21,15, 16,19,22,17, 18,20,23,19},
359 .cell_to_edge_offsets = (size_t[]){0,4,8, 12,16,20, 24,28,32},
360 .vertex_to_cell = (size_t[]){0, 0,1, 1,2, 2,
361 0,3, 0,1,3,4, 1,2,4,5, 2,5,
362 3,6, 3,4,6,7, 4,5,7,8, 5,8,
363 6, 6,7, 7,8, 8},
364 .vertex_to_cell_offsets = (size_t[]){0,1,3,5,
365 6,8,12,16,
366 18,20,24,28,
367 30,31,33,35},
368 .edge_to_vertex = (size_t[][2]){{0,1},{0,4},{1,2},{1,5},{2,3},{2,6},{3,7},
369 {4,5},{4,8},{5,6},{5,9},{6,7},{6,10},{7,11},
370 {8,9},{8,12},{9,10},{9,13},{10,11},{10,14},{11,15},
371 {12,13},{13,14},{14,15}},
372 .edge_type = unstruct_edge_type,
373 .num_total_cells = 9,
374 .num_total_vertices = 16,
375 .num_total_edges = 24};
376
377 check_basic_grid_data(grid, ref_grid_data, grid_name);
378}
379
380static void utest_test_grid_data__3x2(
381 struct yac_basic_grid_data grid, char * grid_name, enum grid_type type) {
382
383 double ref_coords_x[12] = {0,1,2,3,0,1,2,3,0,1,2,3};
384 double ref_coords_y[12] = {0,0,0,0,1,1,1,1,2,2,2,2};
385 double vertex_coordinates[12][3];
386 for (size_t i = 0; i < 12; ++i)
387 LLtoXYZ_deg(ref_coords_x[i], ref_coords_y[i], vertex_coordinates[i]);
388
389 enum yac_edge_type reg2d_edge_type[] =
395 enum yac_edge_type unstruct_edge_type[] =
401 enum yac_edge_type * ref_edge_type =
402 (type == REG2D)?reg2d_edge_type:unstruct_edge_type;
403
404 struct yac_basic_grid_data ref_grid_data = {
406 .cell_ids = NULL,
407 .vertex_ids = NULL,
408 .edge_ids = NULL,
409 .num_cells = 6,
410 .num_vertices = 12,
411 .num_edges = 17,
412 .core_cell_mask = NULL,
413 .core_vertex_mask = NULL,
414 .core_edge_mask = NULL,
415 .num_vertices_per_cell = (int[]){4,4,4,4,4,4},
416 .num_cells_per_vertex = (int[]){1,2,2,1, 2,4,4,2, 1,2,2,1},
417 .cell_to_vertex = (size_t[]){0,1,5,4, 1,2,6,5, 2,3,7,6,
418 4,5,9,8, 5,6,10,9, 6,7,11,10},
419 .cell_to_vertex_offsets = (size_t[]){0,4,8,12,16,20},
420 .cell_to_edge = (size_t[]){0,3,7,1, 2,5,9,3, 4,6,11,5,
421 7,10,14,8, 9,12,15,10, 11,13,16,12},
422 .cell_to_edge_offsets = (size_t[]){0,4,8, 12,16,20},
423 .vertex_to_cell = (size_t[]){0, 0,1, 1,2, 2,
424 0,3, 0,1,3,4, 1,2,4,5, 2,5,
425 3, 3,4, 4,5, 5},
426 .vertex_to_cell_offsets = (size_t[]){0,1,3,5,
427 6,8,12,16,
428 18,19,21,23},
429 .edge_to_vertex = (size_t[][2]){{0,1},{0,4},{1,2},{1,5},{2,3},{2,6},{3,7},
430 {4,5},{4,8},{5,6},{5,9},{6,7},{6,10},{7,11},
431 {8,9},{9,10},{10,11}},
432 .edge_type = ref_edge_type,
433 .num_total_cells = 6,
434 .num_total_vertices = 12,
435 .num_total_edges = 17};
436
437 check_basic_grid_data(grid, ref_grid_data, grid_name);
438}
439
440static void utest_test_grid_data__1x4(
441 struct yac_basic_grid_data grid, char * grid_name, enum grid_type type) {
442
443 double ref_coords_x[10] = {0,1,0,1,0,1,0,1,0,1};
444 double ref_coords_y[10] = {0,0,1,1,2,2,3,3,4,4};
445 double vertex_coordinates[10][3];
446 for (size_t i = 0; i < 10; ++i)
447 LLtoXYZ_deg(ref_coords_x[i], ref_coords_y[i], vertex_coordinates[i]);
448
449 enum yac_edge_type reg2d_edge_type[] =
455 enum yac_edge_type unstruct_edge_type[] =
461 enum yac_edge_type * ref_edge_type =
462 (type == REG2D)?reg2d_edge_type:unstruct_edge_type;
463
464 struct yac_basic_grid_data ref_grid_data = {
466 .cell_ids = NULL,
467 .vertex_ids = NULL,
468 .edge_ids = NULL,
469 .num_cells = 4,
470 .num_vertices = 10,
471 .num_edges = 13,
472 .core_cell_mask = NULL,
473 .core_vertex_mask = NULL,
474 .core_edge_mask = NULL,
475 .num_vertices_per_cell = (int[]){4,4,4,4},
476 .num_cells_per_vertex = (int[]){1,1, 2,2, 2,2, 2,2, 1,1},
477 .cell_to_vertex = (size_t[]){0,1,3,2, 2,3,5,4, 4,5,7,6, 6,7,9,8},
478 .cell_to_vertex_offsets = (size_t[]){0,4,8,12},
479 .cell_to_edge = (size_t[]){0,2,3,1, 3,5,6,4, 6,8,9,7, 9,11,12,10},
480 .cell_to_edge_offsets = (size_t[]){0,4,8,12},
481 .vertex_to_cell = (size_t[]){0, 0, 0,1, 0,1, 1,2, 1,2, 2,3, 2,3, 3, 3},
482 .vertex_to_cell_offsets = (size_t[]){0,1,2,4,6,8,10,12,14,15},
483 .edge_to_vertex = (size_t[][2]){{0,1},{0,2},{1,3},
484 {2,3},{2,4},{3,5},
485 {4,5},{4,6},{5,7},
486 {6,7},{6,8},{7,9},
487 {8,9}},
488 .edge_type = ref_edge_type,
489 .num_total_cells = 4,
490 .num_total_vertices = 10,
491 .num_total_edges = 13};
492
493 check_basic_grid_data(grid, ref_grid_data, grid_name);
494}
495
496static void utest_test_grid_data__4x1(
497 struct yac_basic_grid_data grid, char * grid_name, enum grid_type type) {
498
499 double ref_coords_x[10] = {0,1,2,3,4,0,1,2,3,4};
500 double ref_coords_y[10] = {0,0,0,0,0,1,1,1,1,1};
501 double vertex_coordinates[10][3];
502 for (size_t i = 0; i < 10; ++i)
503 LLtoXYZ_deg(ref_coords_x[i], ref_coords_y[i], vertex_coordinates[i]);
504
505 enum yac_edge_type reg2d_edge_type[] =
510 enum yac_edge_type unstruct_edge_type[] =
515 enum yac_edge_type * ref_edge_type =
516 (type == REG2D)?reg2d_edge_type:unstruct_edge_type;
517
518 struct yac_basic_grid_data ref_grid_data = {
520 .cell_ids = NULL,
521 .vertex_ids = NULL,
522 .edge_ids = NULL,
523 .num_cells = 4,
524 .num_vertices = 10,
525 .num_edges = 13,
526 .core_cell_mask = NULL,
527 .core_vertex_mask = NULL,
528 .core_edge_mask = NULL,
529 .num_vertices_per_cell = (int[]){4,4,4,4},
530 .num_cells_per_vertex = (int[]){1,2,2,2,1, 1,2,2,2,1},
531 .cell_to_vertex = (size_t[]){0,1,6,5, 1,2,7,6, 2,3,8,7, 3,4,9,8},
532 .cell_to_vertex_offsets = (size_t[]){0,4,8,12},
533 .cell_to_edge = (size_t[]){0,3,9,1, 2,5,10,3, 4,7,11,5, 6,8,12,7},
534 .cell_to_edge_offsets = (size_t[]){0,4,8,12},
535 .vertex_to_cell = (size_t[]){0, 0,1, 1,2, 2,3, 3,
536 0, 0,1, 1,2, 2,3, 3},
537 .vertex_to_cell_offsets = (size_t[]){0,1,3,5,7, 8,9,11,13,15},
538 .edge_to_vertex = (size_t[][2]){{0,1},{0,5},{1,2},{1,6},{2,3},{2,7},{3,4},{3,8},{4,9},
539 {5,6},{6,7},{7,8},{8,9}},
540 .edge_type = ref_edge_type,
541 .num_total_cells = 4,
542 .num_total_vertices = 10,
543 .num_total_edges = 13};
544
545 check_basic_grid_data(grid, ref_grid_data, grid_name);
546}
547
548static void utest_test_grid_data__6x4_cyclic(
549 struct yac_basic_grid_data grid, char * grid_name) {
550
551 double ref_coords_x[6] = {0,60,120,180,240,300};
552 double ref_coords_y[5] = {-89,-45,0,45,89};
553 double vertex_coordinates[30][3];
554 for (size_t i = 0, k = 0; i < 5; ++i)
555 for (size_t j = 0; j < 6; ++j, ++k)
556 LLtoXYZ_deg(ref_coords_x[j], ref_coords_y[i], vertex_coordinates[k]);
557
558 enum yac_edge_type ref_edge_type[] =
573 size_t cell_to_vertex_offsets[24];
574 for (size_t i = 0; i < 24; ++i) cell_to_vertex_offsets[i] = 4 * i;
575 size_t vertex_to_cell_offsets[30];
576 for (size_t i = 0; i < 6; ++i) vertex_to_cell_offsets[i] = 2 * i;
577 for (size_t i = 6; i < 24; ++i) vertex_to_cell_offsets[i] = 4 * (i - 6) + 6 * 2;
578 for (size_t i = 24; i < 30; ++i) vertex_to_cell_offsets[i] = 2 * (i - 24) + 6 * 2 + 18 * 4 ;
579
580 struct yac_basic_grid_data ref_grid_data = {
582 .cell_ids = NULL,
583 .vertex_ids = NULL,
584 .edge_ids = NULL,
585 .num_cells = 24,
586 .num_vertices = 30,
587 .num_edges = 54,
588 .core_cell_mask = NULL,
589 .core_vertex_mask = NULL,
590 .core_edge_mask = NULL,
591 .num_vertices_per_cell = (int[]){4,4,4,4,4,4,
592 4,4,4,4,4,4,
593 4,4,4,4,4,4,
594 4,4,4,4,4,4},
595 .num_cells_per_vertex = (int[]){2,2,2,2,2,2,
596 4,4,4,4,4,4,
597 4,4,4,4,4,4,
598 4,4,4,4,4,4,
599 2,2,2,2,2,2},
600 .cell_to_vertex = (size_t[]){0,1,7,6, 1,2,8,7, 2,3,9,8, 3,4,10,9, 4,5,11,10, 5,0,6,11,
601 6,7,13,12, 7,8,14,13, 8,9,15,14, 9,10,16,15, 10,11,17,16, 11,6,12,17,
602 12,13,19,18, 13,14,20,19, 14,15,21,20, 15,16,22,21, 16,17,23,22, 17,12,18,23,
603 18,19,25,24, 19,20,26,25, 20,21,27,26, 21,22,28,27, 22,23,29,28, 23,18,24,29},
604 .cell_to_vertex_offsets = cell_to_vertex_offsets,
605 .cell_to_edge = (size_t[]){0,4,12,2, 3,6,15,4, 5,8,17,6, 7,10,19,8, 9,11,21,10, 1,2,13,11,
606 12,16,24,14, 15,18,27,16, 17,20,29,18, 19,22,31,20, 21,23,33,22, 13,14,25,23,
607 24,28,36,26, 27,30,39,28, 29,32,41,30, 31,34,43,32, 33,35,45,34, 25,26,37,35,
608 36,40,48,38, 39,42,50,40, 41,44,51,42, 43,46,52,44, 45,47,53,46, 37,38,49,47},
609 .cell_to_edge_offsets = cell_to_vertex_offsets,
610 .vertex_to_cell = (size_t[]){0,5, 0,1, 1,2, 2,3, 3,4, 4,5,
611 0,6,11,5, 0,1,7,6, 1,2,8,7, 2,3,9,8, 3,4,10,9, 4,5,11,10,
612 6,12,17,11, 6,7,13,12, 7,8,14,13, 8,9,15,14, 9,10,16,15, 10,11,17,16,
613 12,18,23,17, 12,13,19,18, 13,14,20,19, 14,15,21,20, 15,16,22,21, 16,17,23,22,
614 18,23, 18,19, 19,20, 20,21, 21,22, 22,23},
615 .vertex_to_cell_offsets = vertex_to_cell_offsets,
616 .edge_to_vertex = (size_t[][2]){{0,1},{0,5},{0,6},{1,2},{1,7},{2,3},{2,8},{3,4},{3,9},{4,5},{4,10},{5,11},
617 {6,7},{6,11},{6,12},{7,8},{7,13},{8,9},{8,14},{9,10},{9,15},{10,11},{10,16},{11,17},
618 {12,13},{12,17},{12,18},{13,14},{13,19},{14,15},{14,20},{15,16},{15,21},{16,17},{16,22},{17,23},
619 {18,19},{18,23},{18,24},{19,20},{19,25},{20,21},{20,26},{21,22},{21,27},{22,23},{22,28},{23,29},
620 {24,25},{24,29},{25,26},{26,27},{27,28},{28,29}},
621 .edge_type = ref_edge_type,
622 .num_total_cells = 24,
623 .num_total_vertices = 30,
624 .num_total_edges = 54};
625
626 check_basic_grid_data(grid, ref_grid_data, grid_name);
627}
628
630 double * coordinates_x, double * coordinates_y, size_t num_corners) {
631
632 enum yac_edge_type tmp_edge_type[num_corners];
633 double tmp_coordinates_xyz[num_corners][3];
634 for (size_t i = 0; i < num_corners; ++i)
635 tmp_edge_type[i] = YAC_GREAT_CIRCLE_EDGE;
636
637 struct yac_grid_cell cell =
639 coordinates_x, coordinates_y, tmp_edge_type, num_corners);
640
641 double cell_area = yac_huiliers_area(cell);
642
643 struct yac_grid_cell triangles[num_corners-2];
644 size_t triangle_indices[num_corners-2][3];
645 for (size_t j = 0; j < num_corners-2; ++j)
646 yac_init_grid_cell(&(triangles[j]));
647
648 struct yac_grid_cell tmp_cell =
649 {.coordinates_xyz = tmp_coordinates_xyz,
650 .edge_type = tmp_edge_type,
651 .num_corners = num_corners,
652 .array_size = num_corners};
653 size_t corner_indices[num_corners];
654
655 // check both directions
656 for (int order = -1; order < 2; order += 2) {
657
658 // for all start corners
659 for (int j = 0; j < (int)num_corners; ++j) {
660
661 for (int k = 0; k < (int)num_corners; ++k) {
662 int idx = (order*k+j+((int)num_corners))%((int)num_corners);
663 tmp_cell.coordinates_xyz[k][0] = cell.coordinates_xyz[idx][0];
664 tmp_cell.coordinates_xyz[k][1] = cell.coordinates_xyz[idx][1];
665 tmp_cell.coordinates_xyz[k][2] = cell.coordinates_xyz[idx][2];
666 corner_indices[k] = (size_t)idx;
667 }
668
669 // for all start corners of the triangulation
670 for (size_t k = 0; k < num_corners; ++k) {
671
672 // compute triangulation
673 yac_triangulate_cell(tmp_cell, k, triangles);
675 corner_indices, num_corners, k, triangle_indices);
676
677 for (size_t l = 0; l < num_corners - 2; ++l)
678 for (size_t m = 0; m < 3; ++m)
679 if (memcmp(
680 cell.coordinates_xyz[triangle_indices[l][m]],
681 triangles[l].coordinates_xyz[m], 3 * sizeof(double)))
682 PUT_ERR("error in yac_triangulate_cell_indices");
683
684 double total_area = 0.0;
685
686 // for all triangles
687 for (size_t l = 0; l < num_corners - 2; ++l) {
688
689 if (triangles[l].num_corners != 3)
690 PUT_ERR("wrong number of corners in triangle\n");
691
692 total_area += yac_huiliers_area(triangles[l]);
693 }
694
695 if (fabs(total_area - cell_area) > 1e-9)
696 PUT_ERR("error in cell triangulation\n");
697 }
698 }
699 }
700
701 yac_free_grid_cell(&cell);
702 for (size_t j = 0; j < num_corners-2; ++j)
703 yac_free_grid_cell(&(triangles[j]));
704}
705
706int main (void) {
707
708 { // test setting up of 2d regular 1x1 grids
709
710 double coord_x[2] = {0.5,1.5};
711 double coord_y[2] = {0.5,1.5};
712
713 size_t num_vertices[2] = {2,2};
714 int cyclic[2] = {0,0};
715
718 num_vertices, cyclic, coord_x, coord_y);
719
720 utest_test_grid_data__1x1(reg_grid, "regular 2d grid", REG2D);
721
722 yac_basic_grid_data_free(reg_grid);
723 }
724
725 { // test setting up of 2d unstructured 1x1 grids
726
727 size_t num_vertices = 4;
728 size_t num_cells = 1;
729 double coord_x[4] = {0.5,1.5,0.5,1.5};
730 double coord_y[4] = {0.5,0.5,1.5,1.5};
731 int num_vertices_per_cell[] = {4};
732 int cell_to_vertex[] = {0,1,3,2};
733
734 struct yac_basic_grid_data unstruct_grid =
737 coord_x, coord_y, cell_to_vertex);
738
739 utest_test_grid_data__1x1(unstruct_grid, "unstructured 2d grid", UNSTRUCT);
740
741 yac_basic_grid_data_free(unstruct_grid);
742 }
743
744 { // test setting up of 2d curvilinear 1x1 grids
745
746 double coord_x[4] = {0.5,1.5,0.5,1.5};
747 double coord_y[4] = {0.5,0.5,1.5,1.5};
748
749 size_t num_vertices[2] = {2,2};
750 int cyclic[2] = {0,0};
751
752 struct yac_basic_grid_data curvi_grid =
754 num_vertices, cyclic, coord_x, coord_y);
755
756 utest_test_grid_data__1x1(curvi_grid, "curvilinear 2d grid", CURVE2D);
757
758 yac_basic_grid_data_free(curvi_grid);
759 }
760
761 { // test setting up of 2d unstructured lonlat 1x1 grids
762
763 size_t num_vertices = 4;
764 size_t num_cells = 1;
765 double coord_x[4] = {0.5,1.5,0.5,1.5};
766 double coord_y[4] = {0.5,0.5,1.5,1.5};
767 int num_vertices_per_cell[] = {4};
768 int cell_to_vertex[] = {0,1,3,2};
769
770 struct yac_basic_grid_data unstruct_grid =
773 coord_x, coord_y, cell_to_vertex);
774
775 utest_test_grid_data__1x1(unstruct_grid, "unstructured lonlat 2d grid", REG2D);
776
777 yac_basic_grid_data_free(unstruct_grid);
778 }
779
780 { // test setting up of 2d unstructured 1x1 grids
781 // with explicit edge definition
782
783 size_t num_vertices = 4;
784 size_t num_edges = 4;
785 size_t num_cells = 1;
786 double coord_x[4] = {0.5,1.5,0.5,1.5};
787 double coord_y[4] = {0.5,0.5,1.5,1.5};
788 int num_edges_per_cell[] = {4};
789 int cell_to_edge[] = {0,2,3,1};
790 int edge_to_vertex[] = {0,1, 0,2, 1,3, 2,3};
791
792 struct yac_basic_grid_data unstruct_edge_grid =
794 num_vertices, num_cells, num_edges, num_edges_per_cell,
795 coord_x, coord_y, cell_to_edge, edge_to_vertex);
796
797 utest_test_grid_data__1x1(
798 unstruct_edge_grid, "unstructured edge 2d grid", UNSTRUCT);
799
800 yac_basic_grid_data_free(unstruct_edge_grid);
801 }
802
803 { // test setting up of 2d unstructured lonlat 1x1 grids
804 // with explicit edge definition
805
806 size_t num_vertices = 4;
807 size_t num_edges = 4;
808 size_t num_cells = 1;
809 double coord_x[4] = {0.5,1.5,0.5,1.5};
810 double coord_y[4] = {0.5,0.5,1.5,1.5};
811 int num_edges_per_cell[] = {4};
812 int cell_to_edge[] = {0,2,3,1};
813 int edge_to_vertex[] = {0,1, 0,2, 1,3, 2,3};
814
815 struct yac_basic_grid_data unstruct_edge_grid =
817 num_vertices, num_cells, num_edges, num_edges_per_cell,
818 coord_x, coord_y, cell_to_edge, edge_to_vertex);
819
820 utest_test_grid_data__1x1(
821 unstruct_edge_grid, "unstructured edge 2d grid", REG2D);
822
823 yac_basic_grid_data_free(unstruct_edge_grid);
824 }
825
826 { // test setting up of 2d regular 2x2 grids
827
828 double coord_x[3] = {0,1,2};
829 double coord_y[3] = {0,1,2};
830
831 size_t num_vertices[2] = {3,3};
832 int cyclic[2] = {0,0};
833
836 num_vertices, cyclic, coord_x, coord_y);
837
838 utest_test_grid_data__2x2(reg_grid, "regular 2d grid", REG2D);
839
840 yac_basic_grid_data_free(reg_grid);
841 }
842
843 { // test setting up of unstructured 2x2 grids
844
845 size_t num_vertices = 9;
846 size_t num_cells = 4;
847 double coord_x[9] = {0,1,2,0,1,2,0,1,2};
848 double coord_y[9] = {0,0,0,1,1,1,2,2,2};
849 int num_vertices_per_cell[4] = {4,4,4,4};
850 int cell_to_vertex[16] = {0,1,4,3, 1,2,5,4, 3,4,7,6, 4,5,8,7};
851
852 struct yac_basic_grid_data unstruct_grid =
855 coord_x, coord_y, cell_to_vertex);
856
857 utest_test_grid_data__2x2(unstruct_grid, "unstructured 2d grid", UNSTRUCT);
858
859 yac_basic_grid_data_free(unstruct_grid);
860 }
861
862 { // test setting up of curvilinear 2x2 grids
863
864 double coord_x[9] = {0,1,2,0,1,2,0,1,2};
865 double coord_y[9] = {0,0,0,1,1,1,2,2,2};
866
867 size_t num_vertices[2] = {3,3};
868 int cyclic[2] = {0,0};
869
870 struct yac_basic_grid_data curvi_grid =
872 num_vertices, cyclic, coord_x, coord_y);
873
874 utest_test_grid_data__2x2(curvi_grid, "curvilinear 2d grid", CURVE2D);
875
876 yac_basic_grid_data_free(curvi_grid);
877 }
878
879 { // test setting up of unstructured lonlat 2x2 grids
880
881 size_t num_vertices = 9;
882 size_t num_cells = 4;
883 double coord_x[9] = {0,1,2,0,1,2,0,1,2};
884 double coord_y[9] = {0,0,0,1,1,1,2,2,2};
885 int num_vertices_per_cell[4] = {4,4,4,4};
886 int cell_to_vertex[16] = {0,1,4,3, 1,2,5,4, 3,4,7,6, 4,5,8,7};
887
888 struct yac_basic_grid_data unstruct_grid =
891 coord_x, coord_y, cell_to_vertex);
892
893 utest_test_grid_data__2x2(
894 unstruct_grid, "unstructured lonlat 2d grid", REG2D);
895
896 yac_basic_grid_data_free(unstruct_grid);
897 }
898
899 { // test setting up of unstructured 2x2 grids
900 // with explicit edge definition
901
902 size_t num_vertices = 9;
903 size_t num_edges = 12;
904 size_t num_cells = 4;
905 double coord_x[9] = {0,1,2,0,1,2,0,1,2};
906 double coord_y[9] = {0,0,0,1,1,1,2,2,2};
907 int num_edges_per_cell[4] = {4,4,4,4};
908 int cell_to_edge[] = {0,3,5,1, 2,4,7,3, 5,8,10,6, 7,9,11,8};
909 int edge_to_vertex[] = {0,1, 0,3, 1,2, 1,4, 2,5,
910 3,4, 3,6, 4,5, 4,7, 5,8,
911 6,7, 7,8};
912
913 struct yac_basic_grid_data unstruct_edge_grid =
915 num_vertices, num_cells, num_edges, num_edges_per_cell,
916 coord_x, coord_y, cell_to_edge, edge_to_vertex);
917
918 utest_test_grid_data__2x2(
919 unstruct_edge_grid, "unstructured edge 2d grid", UNSTRUCT);
920
921 yac_basic_grid_data_free(unstruct_edge_grid);
922 }
923
924 { // test setting up of unstructured lonlat 2x2 grids
925 // with explicit edge definition
926
927 size_t num_vertices = 9;
928 size_t num_edges = 12;
929 size_t num_cells = 4;
930 double coord_x[9] = {0,1,2,0,1,2,0,1,2};
931 double coord_y[9] = {0,0,0,1,1,1,2,2,2};
932 int num_edges_per_cell[4] = {4,4,4,4};
933 int cell_to_edge[] = {0,3,5,1, 2,4,7,3, 5,8,10,6, 7,9,11,8};
934 int edge_to_vertex[] = {0,1, 0,3, 1,2, 1,4, 2,5,
935 3,4, 3,6, 4,5, 4,7, 5,8,
936 6,7, 7,8};
937
938 struct yac_basic_grid_data unstruct_edge_grid =
940 num_vertices, num_cells, num_edges, num_edges_per_cell,
941 coord_x, coord_y, cell_to_edge, edge_to_vertex);
942
943 utest_test_grid_data__2x2(
944 unstruct_edge_grid, "unstructured edge lonlat 2d grid", REG2D);
945
946 yac_basic_grid_data_free(unstruct_edge_grid);
947 }
948
949 { // test setting up of 2d regular 2x3 grids
950
951 double coord_x[3] = {0,1,2};
952 double coord_y[4] = {0,1,2,3};
953
954 size_t num_vertices[2] = {3,4};
955 int cyclic[2] = {0,0};
956
959 num_vertices, cyclic, coord_x, coord_y);
960
961 utest_test_grid_data__2x3(reg_grid, "regular 2d grid", REG2D);
962
963 yac_basic_grid_data_free(reg_grid);
964 }
965
966 { // test setting up of unstructured 2x3 grids
967
968 size_t num_vertices = 12;
969 size_t num_cells = 6;
970 double coord_x[12] = {0,1,2,0,1,2,0,1,2,0,1,2};
971 double coord_y[12] = {0,0,0,1,1,1,2,2,2,3,3,3};
972 int num_vertices_per_cell[6] = {4,4,4,4,4,4};
973 int cell_to_vertex[24] = {0,1,4,3, 1,2,5,4,
974 3,4,7,6, 4,5,8,7,
975 6,7,10,9, 7,8,11,10};
976
977 struct yac_basic_grid_data unstruct_grid =
980 coord_x, coord_y, cell_to_vertex);
981
982 utest_test_grid_data__2x3(unstruct_grid, "unstructured 2d grid", UNSTRUCT);
983
984 yac_basic_grid_data_free(unstruct_grid);
985 }
986
987 { // test setting up of curvilinear 2x3 grids
988
989 double coord_x[12] = {0,1,2,0,1,2,0,1,2,0,1,2};
990 double coord_y[12] = {0,0,0,1,1,1,2,2,2,3,3,3};
991
992 size_t num_vertices[2] = {3,4};
993 int cyclic[2] = {0,0};
994
995 struct yac_basic_grid_data curvi_grid =
997 num_vertices, cyclic, coord_x, coord_y);
998
999 utest_test_grid_data__2x3(curvi_grid, "curvilinear 2d grid", CURVE2D);
1000
1001 yac_basic_grid_data_free(curvi_grid);
1002 }
1003
1004 { // test setting up of unstructured lonlat 2x3 grids
1005
1006 size_t num_vertices = 12;
1007 size_t num_cells = 6;
1008 double coord_x[12] = {0,1,2,0,1,2,0,1,2,0,1,2};
1009 double coord_y[12] = {0,0,0,1,1,1,2,2,2,3,3,3};
1010 int num_vertices_per_cell[6] = {4,4,4,4,4,4};
1011 int cell_to_vertex[24] = {0,1,4,3, 1,2,5,4,
1012 3,4,7,6, 4,5,8,7,
1013 6,7,10,9, 7,8,11,10};
1014
1015 struct yac_basic_grid_data unstruct_grid =
1018 coord_x, coord_y, cell_to_vertex);
1019
1020 utest_test_grid_data__2x3(unstruct_grid, "unstructured lonlat 2d grid", REG2D);
1021
1022 yac_basic_grid_data_free(unstruct_grid);
1023 }
1024
1025 { // test setting up of unstructured 2x3 grids
1026 // with explicit edge definition
1027
1028 size_t num_vertices = 12;
1029 size_t num_cells = 6;
1030 size_t num_edges = 17;
1031 double coord_x[12] = {0,1,2,0,1,2,0,1,2,0,1,2};
1032 double coord_y[12] = {0,0,0,1,1,1,2,2,2,3,3,3};
1033 int num_edges_per_cell[6] = {4,4,4,4,4,4};
1034 int cell_to_edge[] = {0,3,5,1, 2,4,7,3,
1035 5,8,10,6, 7,9,12,8,
1036 10,13,15,11, 12,14,16,13};
1037 int edge_to_vertex[] = {0,1, 0,3, 1,2, 1,4, 2,5,
1038 3,4, 3,6, 4,5, 4,7, 5,8,
1039 6,7, 6,9, 7,8, 7,10, 8,11,
1040 9,10, 10,11};
1041
1042 struct yac_basic_grid_data unstruct_edge_grid =
1044 num_vertices, num_cells, num_edges, num_edges_per_cell,
1045 coord_x, coord_y, cell_to_edge, edge_to_vertex);
1046
1047 utest_test_grid_data__2x3(
1048 unstruct_edge_grid, "unstructured edge 2d grid", UNSTRUCT);
1049
1050 yac_basic_grid_data_free(unstruct_edge_grid);
1051 }
1052
1053 { // test setting up of unstructured lonlat 2x3 grids
1054 // with explicit edge definition
1055
1056 size_t num_vertices = 12;
1057 size_t num_cells = 6;
1058 size_t num_edges = 17;
1059 double coord_x[12] = {0,1,2,0,1,2,0,1,2,0,1,2};
1060 double coord_y[12] = {0,0,0,1,1,1,2,2,2,3,3,3};
1061 int num_edges_per_cell[6] = {4,4,4,4,4,4};
1062 int cell_to_edge[] = {0,3,5,1, 2,4,7,3,
1063 5,8,10,6, 7,9,12,8,
1064 10,13,15,11, 12,14,16,13};
1065 int edge_to_vertex[] = {0,1, 0,3, 1,2, 1,4, 2,5,
1066 3,4, 3,6, 4,5, 4,7, 5,8,
1067 6,7, 6,9, 7,8, 7,10, 8,11,
1068 9,10, 10,11};
1069
1070 struct yac_basic_grid_data unstruct_edge_grid =
1072 num_vertices, num_cells, num_edges, num_edges_per_cell,
1073 coord_x, coord_y, cell_to_edge, edge_to_vertex);
1074
1075 utest_test_grid_data__2x3(
1076 unstruct_edge_grid, "unstructured edge lonlat 2d grid", REG2D);
1077
1078 yac_basic_grid_data_free(unstruct_edge_grid);
1079 }
1080
1081 { // test setting up of 2d regular 3x3 grids
1082
1083 double coord_x[] = {0,1,2,3};
1084 double coord_y[] = {0,1,2,3};
1085
1086 size_t num_vertices[2] = {4,4};
1087 int cyclic[2] = {0,0};
1088
1091 num_vertices, cyclic, coord_x, coord_y);
1092
1093 utest_test_grid_data__3x3(reg_grid, "regular 2d grid", REG2D);
1094
1095 yac_basic_grid_data_free(reg_grid);
1096 }
1097
1098 { // test setting up of unstructured 3x3 grids
1099
1100 size_t num_vertices = 16;
1101 size_t num_cells = 9;
1102 double coord_x[] = {0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3};
1103 double coord_y[] = {0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3};
1104 int num_vertices_per_cell[] = {4,4,4, 4,4,4, 4,4,4};
1105 int cell_to_vertex[] = {0,1,5,4, 1,2,6,5, 2,3,7,6,
1106 4,5,9,8, 5,6,10,9, 6,7,11,10,
1107 8,9,13,12, 9,10,14,13, 10,11,15,14};
1108
1109 struct yac_basic_grid_data unstruct_grid =
1112 coord_x, coord_y, cell_to_vertex);
1113
1114 utest_test_grid_data__3x3(unstruct_grid, "unstructured 2d grid", UNSTRUCT);
1115
1116 yac_basic_grid_data_free(unstruct_grid);
1117 }
1118
1119 { // test setting up of curvilinear 3x3 grids
1120
1121 double coord_x[] = {0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3};
1122 double coord_y[] = {0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3};
1123
1124 size_t num_vertices[2] = {4,4};
1125 int cyclic[2] = {0,0};
1126
1127 struct yac_basic_grid_data curvi_grid =
1129 num_vertices, cyclic, coord_x, coord_y);
1130
1131 utest_test_grid_data__3x3(curvi_grid, "curvilinear 2d grid", CURVE2D);
1132
1133 yac_basic_grid_data_free(curvi_grid);
1134 }
1135
1136 { // test setting up of unstructured lonlat 3x3 grids
1137
1138 size_t num_vertices = 16;
1139 size_t num_cells = 9;
1140 double coord_x[] = {0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3};
1141 double coord_y[] = {0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3};
1142 int num_vertices_per_cell[] = {4,4,4, 4,4,4, 4,4,4};
1143 int cell_to_vertex[] = {0,1,5,4, 1,2,6,5, 2,3,7,6,
1144 4,5,9,8, 5,6,10,9, 6,7,11,10,
1145 8,9,13,12, 9,10,14,13, 10,11,15,14};
1146
1147 struct yac_basic_grid_data unstruct_grid =
1150 coord_x, coord_y, cell_to_vertex);
1151
1152 utest_test_grid_data__3x3(unstruct_grid, "unstructured lonlat 2d grid", REG2D);
1153
1154 yac_basic_grid_data_free(unstruct_grid);
1155 }
1156
1157 { // test setting up of unstructured 3x3 grids
1158 // with explicit edge definition
1159
1160 size_t num_vertices = 16;
1161 size_t num_cells = 9;
1162 size_t num_edges = 24;
1163 double coord_x[] = {0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3};
1164 double coord_y[] = {0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3};
1165 int num_edges_per_cell[] = {4,4,4, 4,4,4, 4,4,4};
1166 int cell_to_edge[] = {0,3,7,1, 2,5,9,3, 4,6,11,5,
1167 7,10,14,8, 9,12,16,10, 11,13,18,12,
1168 14,17,21,15, 16,19,22,17, 18,20,23,19};
1169 int edge_to_vertex[] = {0,1, 0,4, 1,2, 1,5, 2,3, 2,6, 3,7,
1170 4,5, 4,8, 5,6, 5,9, 6,7, 6,10, 7,11,
1171 8,9, 8,12, 9,10, 9,13, 10,11, 10,14, 11,15,
1172 12,13, 13,14, 14,15};
1173
1174 struct yac_basic_grid_data unstruct_edge_grid =
1176 num_vertices, num_cells, num_edges, num_edges_per_cell,
1177 coord_x, coord_y, cell_to_edge, edge_to_vertex);
1178
1179 utest_test_grid_data__3x3(
1180 unstruct_edge_grid, "unstructured edge 2d grid", UNSTRUCT);
1181
1182 yac_basic_grid_data_free(unstruct_edge_grid);
1183 }
1184
1185 { // test setting up of unstructured lonlat 3x3 grids
1186 // with explicit edge definition
1187
1188 size_t num_vertices = 16;
1189 size_t num_cells = 9;
1190 size_t num_edges = 24;
1191 double coord_x[] = {0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3};
1192 double coord_y[] = {0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3};
1193 int num_edges_per_cell[] = {4,4,4, 4,4,4, 4,4,4};
1194 int cell_to_edge[] = {0,3,7,1, 2,5,9,3, 4,6,11,5,
1195 7,10,14,8, 9,12,16,10, 11,13,18,12,
1196 14,17,21,15, 16,19,22,17, 18,20,23,19};
1197 int edge_to_vertex[] = {0,1, 0,4, 1,2, 1,5, 2,3, 2,6, 3,7,
1198 4,5, 4,8, 5,6, 5,9, 6,7, 6,10, 7,11,
1199 8,9, 8,12, 9,10, 9,13, 10,11, 10,14, 11,15,
1200 12,13, 13,14, 14,15};
1201
1202 struct yac_basic_grid_data unstruct_edge_grid =
1204 num_vertices, num_cells, num_edges, num_edges_per_cell,
1205 coord_x, coord_y, cell_to_edge, edge_to_vertex);
1206
1207 utest_test_grid_data__3x3(
1208 unstruct_edge_grid, "unstructured edge lonlat 2d grid", REG2D);
1209
1210 yac_basic_grid_data_free(unstruct_edge_grid);
1211 }
1212
1213 { // test setting up of 2d regular 3x2 grids
1214
1215 double coord_x[] = {0,1,2,3};
1216 double coord_y[] = {0,1,2};
1217
1218 size_t num_vertices[2] = {4,3};
1219 int cyclic[2] = {0,0};
1220
1223 num_vertices, cyclic, coord_x, coord_y);
1224
1225 utest_test_grid_data__3x2(reg_grid, "regular 2d grid", REG2D);
1226
1227 yac_basic_grid_data_free(reg_grid);
1228 }
1229
1230 { // test setting up of unstructured 3x2 grids
1231
1232 size_t num_vertices = 12;
1233 size_t num_cells = 6;
1234 double coord_x[] = {0,1,2,3,0,1,2,3,0,1,2,3};
1235 double coord_y[] = {0,0,0,0,1,1,1,1,2,2,2,2};
1236 int num_vertices_per_cell[] = {4,4,4, 4,4,4};
1237 int cell_to_vertex[] = {0,1,5,4, 1,2,6,5, 2,3,7,6,
1238 4,5,9,8, 5,6,10,9, 6,7,11,10};
1239
1240 struct yac_basic_grid_data unstruct_grid =
1243 coord_x, coord_y, cell_to_vertex);
1244
1245 utest_test_grid_data__3x2(unstruct_grid, "unstructured 2d grid", UNSTRUCT);
1246
1247 yac_basic_grid_data_free(unstruct_grid);
1248 }
1249
1250 { // test setting up of curvilinear 3x2 grids
1251
1252 double coord_x[] = {0,1,2,3,0,1,2,3,0,1,2,3};
1253 double coord_y[] = {0,0,0,0,1,1,1,1,2,2,2,2};
1254
1255 size_t num_vertices[2] = {4,3};
1256 int cyclic[2] = {0,0};
1257
1258 struct yac_basic_grid_data curvi_grid =
1260 num_vertices, cyclic, coord_x, coord_y);
1261
1262 utest_test_grid_data__3x2(curvi_grid, "curvilinear 2d grid", CURVE2D);
1263
1264 yac_basic_grid_data_free(curvi_grid);
1265 }
1266
1267 { // test setting up of unstructured lonlat 3x2 grids
1268
1269 size_t num_vertices = 12;
1270 size_t num_cells = 6;
1271 double coord_x[] = {0,1,2,3,0,1,2,3,0,1,2,3};
1272 double coord_y[] = {0,0,0,0,1,1,1,1,2,2,2,2};
1273 int num_vertices_per_cell[] = {4,4,4, 4,4,4};
1274 int cell_to_vertex[] = {0,1,5,4, 1,2,6,5, 2,3,7,6,
1275 4,5,9,8, 5,6,10,9, 6,7,11,10};
1276
1277 struct yac_basic_grid_data unstruct_grid =
1280 coord_x, coord_y, cell_to_vertex);
1281
1282 utest_test_grid_data__3x2(unstruct_grid, "unstructured lonlat 2d grid", REG2D);
1283
1284 yac_basic_grid_data_free(unstruct_grid);
1285 }
1286
1287 { // test setting up of unstructured 3x2 grids
1288 // with explicit edge definition
1289
1290 size_t num_vertices = 12;
1291 size_t num_cells = 6;
1292 size_t num_edges = 17;
1293 double coord_x[] = {0,1,2,3,0,1,2,3,0,1,2,3};
1294 double coord_y[] = {0,0,0,0,1,1,1,1,2,2,2,2};
1295 int num_edges_per_cell[] = {4,4,4, 4,4,4};
1296 int cell_to_edge[] = {0,3,7,1, 2,5,9,3, 4,6,11,5,
1297 7,10,14,8, 9,12,15,10, 11,13,16,12};
1298 int edge_to_vertex[] = {0,1, 0,4, 1,2, 1,5, 2,3, 2,6, 3,7,
1299 4,5, 4,8, 5,6, 5,9, 6,7, 6,10, 7,11,
1300 8,9, 9,10, 10,11};
1301
1302 struct yac_basic_grid_data unstruct_edge_grid =
1304 num_vertices, num_cells, num_edges, num_edges_per_cell,
1305 coord_x, coord_y, cell_to_edge, edge_to_vertex);
1306
1307 utest_test_grid_data__3x2(
1308 unstruct_edge_grid, "unstructured edge 2d grid", UNSTRUCT);
1309
1310 yac_basic_grid_data_free(unstruct_edge_grid);
1311 }
1312
1313 { // test setting up of unstructured lonlat 3x2 grids
1314 // with explicit edge definition
1315
1316 size_t num_vertices = 12;
1317 size_t num_cells = 6;
1318 size_t num_edges = 17;
1319 double coord_x[] = {0,1,2,3,0,1,2,3,0,1,2,3};
1320 double coord_y[] = {0,0,0,0,1,1,1,1,2,2,2,2};
1321 int num_edges_per_cell[] = {4,4,4, 4,4,4};
1322 int cell_to_edge[] = {0,3,7,1, 2,5,9,3, 4,6,11,5,
1323 7,10,14,8, 9,12,15,10, 11,13,16,12};
1324 int edge_to_vertex[] = {0,1, 0,4, 1,2, 1,5, 2,3, 2,6, 3,7,
1325 4,5, 4,8, 5,6, 5,9, 6,7, 6,10, 7,11,
1326 8,9, 9,10, 10,11};
1327
1328 struct yac_basic_grid_data unstruct_edge_grid =
1330 num_vertices, num_cells, num_edges, num_edges_per_cell,
1331 coord_x, coord_y, cell_to_edge, edge_to_vertex);
1332
1333 utest_test_grid_data__3x2(
1334 unstruct_edge_grid, "unstructured edge lonlat 2d grid", REG2D);
1335
1336 yac_basic_grid_data_free(unstruct_edge_grid);
1337 }
1338
1339 { // test setting up of 2d regular 1x4 grids
1340
1341 double coord_x[] = {0,1};
1342 double coord_y[] = {0,1,2,3,4};
1343
1344 size_t num_vertices[2] = {2,5};
1345 int cyclic[2] = {0,0};
1346
1349 num_vertices, cyclic, coord_x, coord_y);
1350
1351 utest_test_grid_data__1x4(reg_grid, "regular 2d grid", REG2D);
1352
1353 yac_basic_grid_data_free(reg_grid);
1354 }
1355
1356 { // test setting up of unstructured 1x4 grids
1357
1358 size_t num_vertices = 10;
1359 size_t num_cells = 4;
1360 double coord_x[] = {0,1,0,1,0,1,0,1,0,1};
1361 double coord_y[] = {0,0,1,1,2,2,3,3,4,4};
1362 int num_vertices_per_cell[] = {4,4,4,4};
1363 int cell_to_vertex[] = {0,1,3,2, 2,3,5,4, 4,5,7,6, 6,7,9,8};
1364
1365 struct yac_basic_grid_data unstruct_grid =
1368 coord_x, coord_y, cell_to_vertex);
1369
1370 utest_test_grid_data__1x4(unstruct_grid, "unstructured 2d grid", UNSTRUCT);
1371
1372 yac_basic_grid_data_free(unstruct_grid);
1373 }
1374
1375 { // test setting up of curvilinear 1x4 grids
1376
1377 double coord_x[] = {0,1,0,1,0,1,0,1,0,1};
1378 double coord_y[] = {0,0,1,1,2,2,3,3,4,4};
1379
1380 size_t num_vertices[2] = {2,5};
1381 int cyclic[2] = {0,0};
1382
1383 struct yac_basic_grid_data curvi_grid =
1385 num_vertices, cyclic, coord_x, coord_y);
1386
1387 utest_test_grid_data__1x4(curvi_grid, "curvilinear 2d grid", CURVE2D);
1388
1389 yac_basic_grid_data_free(curvi_grid);
1390 }
1391
1392 { // test setting up of unstructured lonlat 1x4 grids
1393
1394 size_t num_vertices = 10;
1395 size_t num_cells = 4;
1396 double coord_x[] = {0,1,0,1,0,1,0,1,0,1};
1397 double coord_y[] = {0,0,1,1,2,2,3,3,4,4};
1398 int num_vertices_per_cell[] = {4,4,4,4};
1399 int cell_to_vertex[] = {0,1,3,2, 2,3,5,4, 4,5,7,6, 6,7,9,8};
1400
1401 struct yac_basic_grid_data unstruct_grid =
1404 coord_x, coord_y, cell_to_vertex);
1405
1406 utest_test_grid_data__1x4(unstruct_grid, "unstructured lonlat 2d grid", REG2D);
1407
1408 yac_basic_grid_data_free(unstruct_grid);
1409 }
1410
1411 { // test setting up of unstructured 1x4 grids
1412 // with explicit edge definition
1413
1414 size_t num_vertices = 10;
1415 size_t num_cells = 4;
1416 size_t num_edges = 13;
1417 double coord_x[] = {0,1,0,1,0,1,0,1,0,1};
1418 double coord_y[] = {0,0,1,1,2,2,3,3,4,4};
1419 int num_edges_per_cell[] = {4,4,4,4};
1420 int cell_to_edge[] = {0,2,3,1, 3,5,6,4, 6,8,9,7, 9,11,12,10};
1421 int edge_to_vertex[] = {0,1, 0,2, 1,3, 2,3, 2,4, 3,5, 4,5,
1422 4,6, 5,7, 6,7, 6,8, 7,9, 8,9};
1423
1424 struct yac_basic_grid_data unstruct_edge_grid =
1426 num_vertices, num_cells, num_edges, num_edges_per_cell,
1427 coord_x, coord_y, cell_to_edge, edge_to_vertex);
1428
1429 utest_test_grid_data__1x4(
1430 unstruct_edge_grid, "unstructured edge 2d grid", UNSTRUCT);
1431
1432 yac_basic_grid_data_free(unstruct_edge_grid);
1433 }
1434
1435 { // test setting up of unstructured lonlat 1x4 grids
1436 // with explicit edge definition
1437
1438 size_t num_vertices = 10;
1439 size_t num_cells = 4;
1440 size_t num_edges = 13;
1441 double coord_x[] = {0,1,0,1,0,1,0,1,0,1};
1442 double coord_y[] = {0,0,1,1,2,2,3,3,4,4};
1443 int num_edges_per_cell[] = {4,4,4,4};
1444 int cell_to_edge[] = {0,2,3,1, 3,5,6,4, 6,8,9,7, 9,11,12,10};
1445 int edge_to_vertex[] = {0,1, 0,2, 1,3, 2,3, 2,4, 3,5, 4,5,
1446 4,6, 5,7, 6,7, 6,8, 7,9, 8,9};
1447
1448 struct yac_basic_grid_data unstruct_edge_grid =
1450 num_vertices, num_cells, num_edges, num_edges_per_cell,
1451 coord_x, coord_y, cell_to_edge, edge_to_vertex);
1452
1453 utest_test_grid_data__1x4(
1454 unstruct_edge_grid, "unstructured edge 2d grid", REG2D);
1455
1456 yac_basic_grid_data_free(unstruct_edge_grid);
1457 }
1458
1459 { // test setting up of 2d regular 4x1 grids
1460
1461 double coord_x[] = {0,1,2,3,4};
1462 double coord_y[] = {0,1};
1463
1464 size_t num_vertices[2] = {5,2};
1465 int cyclic[2] = {0,0};
1466
1469 num_vertices, cyclic, coord_x, coord_y);
1470
1471 utest_test_grid_data__4x1(reg_grid, "regular 2d grid", REG2D);
1472
1473 yac_basic_grid_data_free(reg_grid);
1474 }
1475
1476 { // test setting up of cyclic 2d regular 6x4 grids
1477
1478 double coord_x[] = {0,60,120,180,240,300};
1479 double coord_y[] = {-89,-45,0,45,89};
1480
1481 size_t num_vertices[2] = {6,5};
1482 int cyclic[2] = {1,0};
1483
1486 num_vertices, cyclic, coord_x, coord_y);
1487
1488 utest_test_grid_data__6x4_cyclic(reg_grid, "regular 2d grid");
1489
1490 yac_basic_grid_data_free(reg_grid);
1491 }
1492
1493 { // test setting up of unstructured 4x1 grids
1494
1495 size_t num_vertices = 10;
1496 size_t num_cells = 4;
1497 double coord_x[] = {0,1,2,3,4, 0,1,2,3,4};
1498 double coord_y[] = {0,0,0,0,0, 1,1,1,1,1};
1499 int num_vertices_per_cell[] = {4,4,4,4};
1500 int cell_to_vertex[] = {0,1,6,5, 1,2,7,6, 2,3,8,7, 3,4,9,8};
1501
1502 struct yac_basic_grid_data unstruct_grid =
1505 coord_x, coord_y, cell_to_vertex);
1506
1507 utest_test_grid_data__4x1(unstruct_grid, "unstructured 2d grid", UNSTRUCT);
1508
1509 yac_basic_grid_data_free(unstruct_grid);
1510 }
1511
1512 { // test setting up of curvilinear 4x1 grids
1513
1514 double coord_x[] = {0,1,2,3,4, 0,1,2,3,4};
1515 double coord_y[] = {0,0,0,0,0, 1,1,1,1,1};
1516
1517 size_t num_vertices[2] = {5,2};
1518 int cyclic[2] = {0,0};
1519
1520 struct yac_basic_grid_data curvi_grid =
1522 num_vertices, cyclic, coord_x, coord_y);
1523
1524 utest_test_grid_data__4x1(curvi_grid, "curvilinear 2d grid", CURVE2D);
1525
1526 yac_basic_grid_data_free(curvi_grid);
1527 }
1528
1529 { // test setting up of unstructured lonlat 4x1 grids
1530
1531 size_t num_vertices = 10;
1532 size_t num_cells = 4;
1533 double coord_x[] = {0,1,2,3,4, 0,1,2,3,4};
1534 double coord_y[] = {0,0,0,0,0, 1,1,1,1,1};
1535 int num_vertices_per_cell[] = {4,4,4,4};
1536 int cell_to_vertex[] = {0,1,6,5, 1,2,7,6, 2,3,8,7, 3,4,9,8};
1537
1538 struct yac_basic_grid_data unstruct_grid =
1541 coord_x, coord_y, cell_to_vertex);
1542
1543 utest_test_grid_data__4x1(unstruct_grid, "unstructured lonlat 2d grid", REG2D);
1544
1545 yac_basic_grid_data_free(unstruct_grid);
1546 }
1547
1548 { // test setting up of unstructured 4x1 grids
1549 // with explicit edge definition
1550
1551 size_t num_vertices = 10;
1552 size_t num_cells = 4;
1553 size_t num_edges = 13;
1554 double coord_x[] = {0,1,2,3,4, 0,1,2,3,4};
1555 double coord_y[] = {0,0,0,0,0, 1,1,1,1,1};
1556 int num_edges_per_cell[] = {4,4,4,4};
1557 int cell_to_edge[] = {0,3,9,1, 2,5,10,3, 4,7,11,5, 6,8,12,7};
1558 int edge_to_vertex [] = {0,1, 0,5, 1,2, 1,6, 2,3, 2,7, 3,4, 3,8, 4,9,
1559 5,6, 6,7, 7,8, 8,9};
1560
1561 struct yac_basic_grid_data unstruct_edge_grid =
1563 num_vertices, num_cells, num_edges, num_edges_per_cell,
1564 coord_x, coord_y, cell_to_edge, edge_to_vertex);
1565
1566 utest_test_grid_data__4x1(
1567 unstruct_edge_grid, "unstructured edge 2d grid", UNSTRUCT);
1568
1569 yac_basic_grid_data_free(unstruct_edge_grid);
1570 }
1571
1572 { // test setting up of unstructured lonlat 4x1 grids
1573 // with explicit edge definition
1574
1575 size_t num_vertices = 10;
1576 size_t num_cells = 4;
1577 size_t num_edges = 13;
1578 double coord_x[] = {0,1,2,3,4, 0,1,2,3,4};
1579 double coord_y[] = {0,0,0,0,0, 1,1,1,1,1};
1580 int num_edges_per_cell[] = {4,4,4,4};
1581 int cell_to_edge[] = {0,3,9,1, 2,5,10,3, 4,7,11,5, 6,8,12,7};
1582 int edge_to_vertex [] = {0,1, 0,5, 1,2, 1,6, 2,3, 2,7, 3,4, 3,8, 4,9,
1583 5,6, 6,7, 7,8, 8,9};
1584
1585 struct yac_basic_grid_data unstruct_edge_grid =
1587 num_vertices, num_cells, num_edges, num_edges_per_cell,
1588 coord_x, coord_y, cell_to_edge, edge_to_vertex);
1589
1590 utest_test_grid_data__4x1(
1591 unstruct_edge_grid, "unstructured edge lonlat 2d grid", REG2D);
1592
1593 yac_basic_grid_data_free(unstruct_edge_grid);
1594 }
1595
1596 { // test periodic coordinates
1597
1598 size_t num_vertices = 9;
1599 size_t num_cells = 4;
1600 double coord_x[9] = {0,1,2, 0+360,1-360,2+2*360, 0,1,2};
1601 double coord_y[9] = { 0,0,0, 1,1,1, 2,2,2};
1602 int num_vertices_per_cell[4] = {4,4,4,4};
1603 int cell_to_vertex[16] = {0,1,4,3, 1,2,5,4, 3,4,7,6, 4,5,8,7};
1604
1605 struct yac_basic_grid_data unstruct_grid =
1608 coord_x, coord_y, cell_to_vertex);
1609
1610 utest_test_grid_data__2x2(
1611 unstruct_grid, "periodic unstructured lonlat 2d grid", REG2D);
1612
1613 yac_basic_grid_data_free(unstruct_grid);
1614 }
1615
1616 { // test triangulation of cells
1617
1618 check_cell_triangulation((double[]){0,1,0}, (double[]){0,0,1}, 3);
1619 check_cell_triangulation((double[]){0,1,1,0}, (double[]){0,0,1,1}, 4);
1621 (double[]){0,1,1,0.5,0}, (double[]){0,0,1,1.5,1}, 5);
1623 (double[]){0,0.5,1,1,0.5,0}, (double[]){0,-0.5,0,1,1.5,1}, 6);
1625 (double[]){-0.25,0, 0.5,1,1.25,1,0},
1626 (double[]){ 0.5 ,0,-0.5,0,0.5 ,1,1}, 7);
1628 (double[]){-0.25,0, 0.5,1,1.25,1,0.5,0},
1629 (double[]){ 0.5 ,0,-0.5,0,0.5 ,1,1.5,1}, 8);
1630 }
1631
1632 { // test setting up of unstructured 3x3 grids without cells
1633
1634 size_t num_vertices = 16;
1635 size_t num_cells = 0;
1636 double coord_x[] = {0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3};
1637 double coord_y[] = {0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3};
1638 int * num_vertices_per_cell = NULL;
1639 int * cell_to_vertex = NULL;
1640
1641 struct yac_basic_grid_data unstruct_grid =
1644 coord_x, coord_y, cell_to_vertex);
1645
1646 utest_test_grid_data__3x3_cloud(unstruct_grid, "unstructured 2d grid cloud");
1647
1648 yac_basic_grid_data_free(unstruct_grid);
1649 }
1650
1651 { // test setting up of unstructured 3x3 grids without cells
1652
1653 size_t num_coords = 16;
1654 double coord_x[] = {0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3};
1655 double coord_y[] = {0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3};
1656
1657 struct yac_basic_grid_data cloud_grid =
1658 yac_generate_basic_grid_data_cloud_deg(num_coords, coord_x, coord_y);
1659
1660 utest_test_grid_data__3x3_cloud(cloud_grid, "cloud 2d grid");
1661
1662 yac_basic_grid_data_free(cloud_grid);
1663 }
1664
1665 { // test setting up of regular 3x3 grids rotated by 45 degree
1666
1667 double coord_x[] = {-1.5,-0.5,0.5,1.5};
1668 double coord_y[] = {-1.5,-0.5,0.5,1.5};
1669 double north_pole[] = {180.0, 45.0};
1670
1671 size_t num_vertices[2] = {4,4};
1672 int cyclic[2] = {0,0};
1673
1674 struct yac_basic_grid_data reg_rot_grid =
1676 num_vertices, cyclic, coord_x, coord_y,
1677 north_pole[0], north_pole[1]);
1678
1679 double rot_axis[] = {0.0, -1.0, 0.0};
1680 struct sin_cos_angle rot_angle =
1681 (struct sin_cos_angle){.sin = 1.0 / sqrt(2.0), .cos = 1.0 / sqrt(2.0)};
1682 utest_test_grid_data__3x3_reg2d_rot(
1683 reg_rot_grid, "reg rot 2d grid", rot_axis, rot_angle);
1684
1685 yac_basic_grid_data_free(reg_rot_grid);
1686 }
1687
1688#ifdef NOT_YET_SUPPORTED
1689 { // test setting up of cyclic 2d regular 6x4 grids (that cover the pole)
1690
1691 double coord_x[] = {0,60,120,180,240};
1692 double coord_y[] = {-90,45,0,45,90};
1693
1694 size_t num_vertices[2] = {5,4};
1695 int cyclic[2] = {1,0};
1696
1699 num_vertices, cyclic, coord_x, coord_y);
1700
1701 // utest_test_grid_data__6x4_cyclic_pole(reg_grid, "regular 2d grid", REG2D);
1702
1703 yac_basic_grid_data_free(reg_grid);
1704 }
1705#endif
1706
1707 return TEST_EXIT_CODE;
1708}
1709
double yac_huiliers_area(struct yac_grid_cell cell)
Area calculation on a unit sphere taken from ESMF based on L'Huilier's Theorem.
Definition area.c:449
Structs and interfaces for area calculations.
#define YAC_AREA_TOL
Definition area.h:18
void yac_basic_grid_data_compute_cell_areas(struct yac_basic_grid_data grid, double *cell_areas)
void yac_basic_grid_data_free(struct yac_basic_grid_data grid)
struct yac_basic_grid_data yac_generate_basic_grid_data_unstruct_deg(size_t nbr_vertices, size_t nbr_cells, int *num_vertices_per_cell, double *x_vertices, double *y_vertices, int *cell_to_vertex)
struct yac_basic_grid_data yac_generate_basic_grid_data_unstruct_edge_deg(size_t nbr_vertices, size_t nbr_cells, size_t nbr_edges, int *num_edges_per_cell, double *x_vertices, double *y_vertices, int *cell_to_edge, int *edge_to_vertex)
struct yac_basic_grid_data yac_generate_basic_grid_data_reg_2d_rot_deg(size_t nbr_vertices[2], int cyclic[2], double *lon_vertices, double *lat_vertices, double north_pole_lon, double north_pole_lat)
struct yac_basic_grid_data yac_generate_basic_grid_data_unstruct_edge_ll_deg(size_t nbr_vertices, size_t nbr_cells, size_t nbr_edges, int *num_edges_per_cell, double *x_vertices, double *y_vertices, int *cell_to_edge, int *edge_to_vertex)
struct yac_basic_grid_data yac_generate_basic_grid_data_cloud_deg(size_t nbr_points, double *x_points, double *y_points)
Definition grid_cloud.c:58
struct yac_basic_grid_data yac_generate_basic_grid_data_curve_2d_deg(size_t nbr_vertices[2], int cyclic[2], double *lon_vertices, double *lat_vertices)
struct yac_basic_grid_data yac_generate_basic_grid_data_reg_2d_deg(size_t nbr_vertices[2], int cyclic[2], double *lon_vertices, double *lat_vertices)
Definition grid_reg2d.c:74
struct yac_basic_grid_data yac_generate_basic_grid_data_unstruct_ll_deg(size_t nbr_vertices, size_t nbr_cells, int *num_vertices_per_cell, double *x_vertices, double *y_vertices, int *cell_to_vertex)
void yac_triangulate_cell_indices(size_t const *corner_indices, size_t num_corners, size_t start_corner, size_t(*triangle_indices)[3])
Definition grid_cell.c:144
static void rotate_vector2(double axis[], struct sin_cos_angle angle, double v_in[], double v_out[])
Definition geometry.h:650
void yac_triangulate_cell(struct yac_grid_cell cell, size_t start_corner, struct yac_grid_cell *triangles)
Definition grid_cell.c:66
static void LLtoXYZ_deg(double lon, double lat, double p_out[])
Definition geometry.h:269
void yac_init_grid_cell(struct yac_grid_cell *cell)
Definition grid_cell.c:14
void yac_free_grid_cell(struct yac_grid_cell *cell)
Definition grid_cell.c:44
yac_edge_type
Definition grid_cell.h:12
@ YAC_GREAT_CIRCLE_EDGE
great circle
Definition grid_cell.h:13
@ YAC_LAT_CIRCLE_EDGE
latitude circle
Definition grid_cell.h:14
@ YAC_LON_CIRCLE_EDGE
longitude circle
Definition grid_cell.h:15
enum callback_type type
double sin
Definition geometry.h:33
yac_coordinate_pointer vertex_coordinates
size_t * vertex_to_cell_offsets
yac_size_t_2_pointer edge_to_vertex
size_t * cell_to_vertex_offsets
size_t num_corners
Definition grid_cell.h:21
double(* coordinates_xyz)[3]
Definition grid_cell.h:19
static void check_cell_triangulation(double *coordinates_x, double *coordinates_y, size_t num_corners)
struct yac_grid_cell generate_cell_deg(double *lon, double *lat, enum yac_edge_type *edge_type, size_t num_corners)
Definition test_common.c:36
void check_basic_grid_data(struct yac_basic_grid_data grid_a, struct yac_basic_grid_data grid_b, char const *grid_name)
int * cell_to_vertex
double coordinates_x[]
size_t num_cells[2]
double coordinates_y[]
unsigned cyclic[2]
#define TEST_EXIT_CODE
Definition tests.h:14
#define PUT_ERR(string)
Definition tests.h:10