YAC 3.12.0
Yet Another Coupler
Loading...
Searching...
No Matches
test_couple_config.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 <stdio.h>
6#include <stdlib.h>
7#include <string.h>
8#include <ctype.h>
9#include <unistd.h>
10#include <mpi.h>
11
12#include "tests.h"
13#include "yac.h"
14#include "config_yaml.h"
15#include "instance.h"
16#include "event.h"
17#include "geometry.h"
18#include "io_utils.h"
22
28char const * ref_start_datetime ="2008-03-09T16:05:07.000";
29char const * ref_end_datetime = "2008-03-10T16:05:07.000";
30
31static void utest_check_couple_config(
32 struct yac_couple_config * couple_config);
33static void utest_check_couple_config_no_delete(
34 struct yac_couple_config * couple_config);
35static struct yac_couple_config *
36 utest_generate_couple_config_from_YAML_parallel(
37 char const * config_filename, int parse_flags);
38static struct yac_couple_config * utest_generate_couple_config_from_YAML(
39 char const * config_filename, int parse_flags);
40static void utest_write_couple_config_to_YAML(
41 struct yac_couple_config * couple_config, char const * config_filename,
42 int emit_flags);
43static int utest_compare_string(char const * a, char const * b);
44
45#define DEF_INTERP_STACK(IDX, ...) \
46 { \
47 struct yac_interp_stack_config * interp_stack = \
48 ((ref_field_couple_data[IDX].interp_stack_config = \
49 yac_interp_stack_config_new())); \
50 __VA_ARGS__ \
51 }
52#define ADD_INTERP(NAME, ...) \
53 yac_interp_stack_config_add_ ## NAME( \
54 interp_stack, __VA_ARGS__);
55#define ADD_INTERP_NO_PARAM(NAME) \
56 yac_interp_stack_config_add_ ## NAME(interp_stack);
57
58int main(int argc, char** argv) {
59
60 MPI_Init(NULL, NULL);
61
62 int size, rank;
63 MPI_Comm_rank ( MPI_COMM_WORLD, &rank );
64 MPI_Comm_size ( MPI_COMM_WORLD, &size );
65
66 if (size != 2) {
67 fputs("ERROR wrong number of processes (has to be 2)", stderr);
68 exit(EXIT_FAILURE);
69 }
70
71 if (argc != 2) {
72 PUT_ERR("ERROR: missing config file directory");
73 xt_finalize();
74 MPI_Finalize();
75 return TEST_EXIT_CODE;
76 }
77
79
80 char const * filename = "couple_config_test.yaml";
81 char * config_filename = malloc(strlen(argv[1]) + 32);
82
83 struct yac_couple_config * couple_config =
84 utest_generate_couple_config_from_YAML_parallel(
85 strcat(strcpy(config_filename, argv[1]), filename),
87
88 utest_check_couple_config_no_delete(couple_config);
89
90 // check the emitting of coupling configurations (on rank zero only)
91 {
92
93 struct {
94 int emit_flags;
95 int parse_flags;
96 enum yac_text_filetype filetype;
97 char const * ext;
98 } formats[] =
99 {{.emit_flags = YAC_YAML_EMITTER_DEFAULT,
100 .parse_flags = YAC_YAML_PARSER_DEFAULT,
101 .filetype = YAC_TEXT_FILETYPE_YAML,
102 .ext = "yaml"},
103 {.emit_flags = YAC_YAML_EMITTER_JSON,
104 .parse_flags = YAC_YAML_PARSER_JSON_FORCE,
105 .filetype = YAC_TEXT_FILETYPE_JSON,
106 .ext = "json"}};
107 enum {NUM_FORMATS = sizeof(formats) / sizeof(formats[0])};
108
109 for (int i = 0; i < NUM_FORMATS; ++i) {
110
111 sprintf(
112 config_filename, "temp_couple_config_test.%s", formats[i].ext);
113
114 if (rank == 0) {
115 utest_write_couple_config_to_YAML(
116 couple_config, config_filename, formats[i].emit_flags);
117
118 utest_check_couple_config(
119 utest_generate_couple_config_from_YAML(
120 config_filename, formats[i].parse_flags));
121
122 unlink(config_filename);
123 }
124
125 MPI_Barrier(MPI_COMM_WORLD);
126
127 char const * debug_global_config_file_def_comp = "test_couple_config_def_comp.yaml";
128 char const * debug_global_config_file_sync_def = "test_couple_config_sync_def.json";
129 char const * debug_global_config_file_enddef = "test_couple_config_enddef.yaml";
130
132 PUT_ERR("ERROR config file should not exist");
133 if (yac_file_exists(debug_global_config_file_def_comp))
134 PUT_ERR("ERROR config file should not exist");
135 if (yac_file_exists(debug_global_config_file_sync_def))
136 PUT_ERR("ERROR config file should not exist");
137 if (yac_file_exists(debug_global_config_file_enddef))
138 PUT_ERR("ERROR config file should not exist");
139
140 char test_reference[32];
141 sprintf(test_reference, "test_ref_%s", formats[i].ext);
142 int include_definitions = 0;
144 couple_config, config_filename, formats[i].filetype, test_reference,
145 include_definitions);
147 couple_config, debug_global_config_file_def_comp,
149 include_definitions);
150 yac_couple_config_sync(couple_config, MPI_COMM_WORLD, test_reference);
151
152 if (rank == 0) {
153
155 PUT_ERR("ERROR config file should not exist");
156 if (yac_file_exists(debug_global_config_file_def_comp))
157 PUT_ERR("ERROR config file should not exist");
158 if (yac_file_exists(debug_global_config_file_sync_def))
159 PUT_ERR("ERROR config file should not exist");
160 if (yac_file_exists(debug_global_config_file_enddef))
161 PUT_ERR("ERROR config file should not exist");
162
163 utest_check_couple_config(
164 utest_generate_couple_config_from_YAML(
166
167 unlink(config_filename);
168 }
169
171 couple_config, MPI_COMM_WORLD, YAC_INSTANCE_CONFIG_OUTPUT_REF_SYNC);
172
173 if (rank == 0) {
174
176 PUT_ERR("ERROR config file should not exist");
177 if (yac_file_exists(debug_global_config_file_def_comp))
178 PUT_ERR("ERROR config file should not exist");
179 if (!yac_file_exists(debug_global_config_file_sync_def))
180 PUT_ERR("ERROR config file should not exist");
181 if (yac_file_exists(debug_global_config_file_enddef))
182 PUT_ERR("ERROR config file should not exist");
183
184 utest_check_couple_config(
185 utest_generate_couple_config_from_YAML(
186 debug_global_config_file_sync_def, YAC_TEXT_FILETYPE_JSON));
187
188 unlink(debug_global_config_file_sync_def);
189 }
190
192 couple_config, MPI_COMM_WORLD, YAC_INSTANCE_CONFIG_OUTPUT_REF_ENDDEF);
193
194 if (rank == 0) {
195
197 PUT_ERR("ERROR config file should not exist");
198 if (yac_file_exists(debug_global_config_file_def_comp))
199 PUT_ERR("ERROR config file should not exist");
200 if (yac_file_exists(debug_global_config_file_sync_def))
201 PUT_ERR("ERROR config file should not exist");
202 if (!yac_file_exists(debug_global_config_file_enddef))
203 PUT_ERR("ERROR config file should not exist");
204
205 utest_check_couple_config(
206 utest_generate_couple_config_from_YAML(
207 debug_global_config_file_enddef, YAC_TEXT_FILETYPE_YAML));
208
209 unlink(debug_global_config_file_enddef);
210 }
211 }
212 }
213
214 free(config_filename);
215
216 utest_check_couple_config(couple_config);
217
218 { // reproduces a bug in routine dist_merge
219 struct yac_couple_config * couple_config = yac_couple_config_new();
220 struct yac_interp_stack_config * interp_stack_config =
222 yac_interp_stack_config_add_fixed(interp_stack_config, -1.0);
223 struct yac_collection_selection * collection_selection = NULL;
225 couple_config, "comp_a", "grid_a", "field_a",
226 "comp_b", "grid_b", "field_b", "1", YAC_REDUCTION_TIME_NONE,
227 interp_stack_config, 0, 0, NULL,
229 NULL, NULL, NULL, collection_selection, 0);
230 yac_interp_stack_config_delete(interp_stack_config);
232 couple_config, (rank == 0)?"comp_c":"comp_d");
233 yac_couple_config_sync(couple_config, MPI_COMM_WORLD, NULL);
234 yac_couple_config_delete(couple_config);
235 }
236
237 {
238 char const * str_interp_stack_config =
239 "- conservative:\n"
240 " enforced_conservation: false\n"
241 " normalisation: fracarea\n"
242 " partial_coverage: false\n"
243 "- fixed:\n"
244 " user_value: -999.0\n";
245 struct yac_interp_stack_config * interp_stack_config =
247 str_interp_stack_config, YAC_YAML_PARSER_DEFAULT);
248
249 struct yac_interp_stack_config * ref_interp_stack_config =
252 ref_interp_stack_config, 1, 0, 0, YAC_INTERP_CONSERV_FRACAREA);
254 ref_interp_stack_config, -999.0);
255
257 ref_interp_stack_config, interp_stack_config))
258 PUT_ERR("ERROR in yac_yaml_parse_interp_stack_config_string");
259
260 yac_interp_stack_config_delete(interp_stack_config);
261 yac_interp_stack_config_delete(ref_interp_stack_config);
262 }
263
264 { // reproduces a bug in routine merge_components
265 struct yac_couple_config * couple_config = yac_couple_config_new();
266 struct yac_interp_stack_config * interp_stack_config =
268 yac_interp_stack_config_add_fixed(interp_stack_config, -1.0);
270 couple_config, (rank == 0)?"comp_a":"comp_b");
272 couple_config, (rank == 0)?"comp_b":"comp_a");
273 struct yac_collection_selection * collection_selection = NULL;
275 couple_config, "comp_a", "grid_a", "field_a",
276 "comp_b", "grid_b", "field_b", "1", YAC_REDUCTION_TIME_NONE,
277 interp_stack_config, 0, 0, NULL,
279 NULL, NULL, NULL, collection_selection, 0);
280 yac_interp_stack_config_delete(interp_stack_config);
281 yac_couple_config_sync(couple_config, MPI_COMM_WORLD, NULL);
282 if (yac_couple_config_get_num_couples(couple_config) != 1)
283 PUT_ERR("ERROR in yac_couple_config_get_num_couples\n");
284 yac_couple_config_delete(couple_config);
285 }
286
287 MPI_Finalize();
288
289 return TEST_EXIT_CODE;
290}
291
292static void utest_check_couple_config_no_delete(
293 struct yac_couple_config * couple_config) {
294
295 //---------------------------------------------------------------------------
296 // setting up reference data
297 //---------------------------------------------------------------------------
298
299 struct {
300 char const * name;
301 char const * metadata;
302 } ref_comp_data[] =
303 {{.name = "ICON-O",
304 .metadata = "a lot of water"},
305 {.name = "ICON-A",
306 .metadata = "a lot of hot air"},
307 {.name = "DUMMY",
308 .metadata = NULL},
309 {.name = "DUMMY_2",
310 .metadata = NULL},
311 {.name = "src_comp",
312 .metadata = NULL},
313 {.name = "tgt_comp",
314 .metadata = NULL}};
315 enum {REF_NUM_COMPS = sizeof(ref_comp_data) / sizeof(ref_comp_data[0])};
316
317 struct {
318 char const * name;
319 char const * output_filename;
320 char const * metadata;
321 } ref_grid_data[] =
322 {{.name = "grid1", .output_filename = "debug_grid.nc", .metadata = "grid1_meta"},
323 {.name = "grid2", .output_filename = NULL, .metadata = "grid2_meta"},
324 {.name = "grid3", .output_filename = NULL, .metadata = NULL},
325 {.name = "grid4", .output_filename = "debug_grid.nc", .metadata = NULL},
326 {.name = "src_grid_1", .output_filename = NULL, .metadata = NULL},
327 {.name = "src_grid_2", .output_filename = NULL, .metadata = NULL},
328 {.name = "tgt_grid_1", .output_filename = NULL, .metadata = NULL},
329 {.name = "tgt_grid_2", .output_filename = NULL, .metadata = NULL}};
330 enum {REF_NUM_GRIDS = sizeof(ref_grid_data) / sizeof(ref_grid_data[0])};
331
332 struct {
333 char const * name;
334 char const * metadata;
335 size_t ref_comp_data_idx;
336 size_t ref_grid_data_idx;
337 size_t ref_couple_data_idx;
338 double frac_mask_value;
339 char const * timestep;
340 size_t collection_size;
341 int role;
342 } ref_field_data[] =
343 // field_idx = 0
344 {{.name = "sea_surface_temperature",
345 .metadata = "T in C",
346 .ref_comp_data_idx = 0,
347 .ref_grid_data_idx = 0,
348 .ref_couple_data_idx = 0,
349 .frac_mask_value = YAC_FRAC_MASK_NO_VALUE,
350 .timestep = "1",
351 .collection_size = 3,
353 // field_idx = 1
354 {.name = "sea_surface_temperature",
355 .metadata = "T in K",
356 .ref_comp_data_idx = 1,
357 .ref_grid_data_idx = 2,
358 .ref_couple_data_idx = 0,
359 .frac_mask_value = YAC_FRAC_MASK_NO_VALUE,
360 .timestep = "10",
361 .collection_size = 1,
363 // field_idx = 2
364 {.name = "wind_speed",
365 .metadata = "v in km/h",
366 .ref_comp_data_idx = 0,
367 .ref_grid_data_idx = 0,
368 .ref_couple_data_idx = 0,
369 .frac_mask_value = 1.0,
370 .timestep = "20",
371 .collection_size = 3,
373 // field_idx = 3
374 {.name = "wind_speed",
375 .metadata = "v in m/s",
376 .ref_comp_data_idx = 1,
377 .ref_grid_data_idx = 2,
378 .ref_couple_data_idx = 0,
379 .frac_mask_value = NAN,
380 .timestep = "2",
381 .collection_size = 3,
383 // field_idx = 4
384 {.name = "water_flux_into_sea_water",
385 .metadata = NULL,
386 .ref_comp_data_idx = 0,
387 .ref_grid_data_idx = 0,
388 .ref_couple_data_idx = 0,
389 .frac_mask_value = 0.0,
390 .timestep = "3",
391 .collection_size = 4,
393 // field_idx = 5
394 {.name = "water_flux_into_sea_water",
395 .metadata = NULL,
396 .ref_comp_data_idx = 1,
397 .ref_grid_data_idx = 2,
398 .ref_couple_data_idx = 0,
399 .frac_mask_value = 0.0,
400 .timestep = "30",
401 .collection_size = 2,
403 // field_idx = 6
404 {.name = "grid_eastward_wind",
405 .metadata = NULL,
406 .ref_comp_data_idx = 0,
407 .ref_grid_data_idx = 1,
408 .ref_couple_data_idx = 0,
409 .frac_mask_value = YAC_FRAC_MASK_NO_VALUE,
410 .timestep = "40",
411 .collection_size = 4,
413 // field_idx = 7
414 {.name = "grid_eastward_wind",
415 .metadata = NULL,
416 .ref_comp_data_idx = 1,
417 .ref_grid_data_idx = 2,
418 .ref_couple_data_idx = 0,
419 .frac_mask_value = 0.0,
420 .timestep = "4",
421 .collection_size = 4,
423 // field_idx = 8
424 {.name = "grid_northward_wind",
425 .metadata = NULL,
426 .ref_comp_data_idx = 0,
427 .ref_grid_data_idx = 1,
428 .ref_couple_data_idx = 0,
429 .frac_mask_value = YAC_FRAC_MASK_NO_VALUE,
430 .timestep = "5",
431 .collection_size = 5,
433 // field_idx = 9
434 {.name = "grid_northward_wind",
435 .metadata = NULL,
436 .ref_comp_data_idx = 1,
437 .ref_grid_data_idx = 2,
438 .ref_couple_data_idx = 0,
439 .frac_mask_value = YAC_FRAC_MASK_NO_VALUE,
440 .timestep = "50",
441 .collection_size = 5,
443 // field_idx = 10
444 {.name = "grid_northward_wind",
445 .metadata = NULL,
446 .ref_comp_data_idx = 2,
447 .ref_grid_data_idx = 3,
448 .ref_couple_data_idx = 1,
449 .frac_mask_value = YAC_FRAC_MASK_NO_VALUE,
450 .timestep = "50",
451 .collection_size = 5,
453 // field_idx = 11
454 {.name = "manual_field",
455 .metadata = NULL,
456 .ref_comp_data_idx = 0,
457 .ref_grid_data_idx = 1,
458 .ref_couple_data_idx = 1,
459 .frac_mask_value = YAC_FRAC_MASK_NO_VALUE,
460 .timestep = "60",
461 .collection_size = 2,
463 // field_idx = 12
464 {.name = "manual_field",
465 .metadata = NULL,
466 .ref_comp_data_idx = 2,
467 .ref_grid_data_idx = 3,
468 .ref_couple_data_idx = 1,
469 .frac_mask_value = YAC_FRAC_MASK_NO_VALUE,
470 .timestep = "6",
471 .collection_size = 2,
473 // field_idx = 13
474 {.name = "manual_field_uncoupled_a",
475 .metadata = NULL,
476 .ref_comp_data_idx = 2,
477 .ref_grid_data_idx = 3,
478 .ref_couple_data_idx = 1,
479 .frac_mask_value = YAC_FRAC_MASK_NO_VALUE,
480 .timestep = "6",
481 .collection_size = 2,
482 .role = YAC_EXCHANGE_TYPE_NONE},
483 // field_idx = 14
484 {.name = "manual_field_uncoupled_b",
485 .metadata = NULL,
486 .ref_comp_data_idx = 2,
487 .ref_grid_data_idx = 3,
488 .ref_couple_data_idx = 1,
489 .frac_mask_value = YAC_FRAC_MASK_NO_VALUE,
490 .timestep = "6",
491 .collection_size = SIZE_MAX,
492 .role = YAC_EXCHANGE_TYPE_NONE},
493 // field_idx = 15
494 {.name = "manual_field_uncoupled_c",
495 .metadata = NULL,
496 .ref_comp_data_idx = 2,
497 .ref_grid_data_idx = 3,
498 .ref_couple_data_idx = 1,
499 .frac_mask_value = YAC_FRAC_MASK_NO_VALUE,
500 .timestep = NULL,
501 .collection_size = 2,
502 .role = YAC_EXCHANGE_TYPE_NONE},
503 // field_idx = 16
504 {.name = "multi_grid_field",
505 .metadata = NULL,
506 .ref_comp_data_idx = 4,
507 .ref_grid_data_idx = 4,
508 .ref_couple_data_idx = 2,
509 .frac_mask_value = YAC_FRAC_MASK_NO_VALUE,
510 .timestep = "1",
511 .collection_size = 1,
513 // field_idx = 17
514 {.name = "multi_grid_field",
515 .metadata = NULL,
516 .ref_comp_data_idx = 4,
517 .ref_grid_data_idx = 5,
518 .ref_couple_data_idx = 2,
519 .frac_mask_value = YAC_FRAC_MASK_NO_VALUE,
520 .timestep = "1",
521 .collection_size = 1,
523 // field_idx = 18
524 {.name = "multi_grid_field",
525 .metadata = NULL,
526 .ref_comp_data_idx = 5,
527 .ref_grid_data_idx = 6,
528 .ref_couple_data_idx = 2,
529 .frac_mask_value = YAC_FRAC_MASK_NO_VALUE,
530 .timestep = "1",
531 .collection_size = 1,
533 // field_idx = 18
534 {.name = "multi_grid_field",
535 .metadata = NULL,
536 .ref_comp_data_idx = 5,
537 .ref_grid_data_idx = 7,
538 .ref_couple_data_idx = 2,
539 .frac_mask_value = YAC_FRAC_MASK_NO_VALUE,
540 .timestep = "1",
541 .collection_size = 1,
543 // field_idx = 20
544 {.name = "manual_field_coll_sel",
545 .metadata = NULL,
546 .ref_comp_data_idx = 0,
547 .ref_grid_data_idx = 1,
548 .ref_couple_data_idx = 1,
549 .frac_mask_value = YAC_FRAC_MASK_NO_VALUE,
550 .timestep = "60",
551 .collection_size = 3,
553 // field_idx = 21
554 {.name = "manual_field_coll_sel",
555 .metadata = NULL,
556 .ref_comp_data_idx = 2,
557 .ref_grid_data_idx = 3,
558 .ref_couple_data_idx = 1,
559 .frac_mask_value = YAC_FRAC_MASK_NO_VALUE,
560 .timestep = "6",
561 .collection_size = 5,
562 .role = YAC_EXCHANGE_TYPE_SOURCE}};
563 enum {REF_NUM_FIELDS = sizeof(ref_field_data) / sizeof(ref_field_data[0])};
564
565 struct {
566 size_t ref_comp_data_idxs[2];
567 } ref_couple_data[] =
568 {{.ref_comp_data_idxs = {0, 1}},
569 {.ref_comp_data_idxs = {0, 2}},
570 {.ref_comp_data_idxs = {4, 5}}};
571 enum {REF_NUM_COUPLES = sizeof(ref_couple_data) / sizeof(ref_couple_data[0])};
572
573 struct {
574 size_t ref_src_field_data_idx;
575 size_t ref_tgt_field_data_idx;
576 struct yac_interp_stack_config * interp_stack_config;
577 int mapping_on_source;
578 int src_lag;
579 int tgt_lag;
580 char const * src_timestep;
581 char const * tgt_timestep;
582 char const * coupling_period;
583 enum yac_reduction_type coupling_period_operation;
584 int enforce_write_weight_file;
585 char const * weight_file_name;
586 enum yac_weight_file_on_existing weight_file_on_existing;
587 double scale_factor;
588 double scale_summand;
589 size_t num_src_mask_names;
590 char const * const * src_mask_names;
591 char const * tgt_mask_name;
592 char const * yaxt_exchanger_name;
595 } ref_field_couple_data[] =
596 {{.ref_src_field_data_idx = 0,
597 .ref_tgt_field_data_idx = 1,
598 .interp_stack_config = NULL,
599 .mapping_on_source = 1,
600 .src_lag = 0,
601 .tgt_lag = 4,
602 .src_timestep = "1",
603 .tgt_timestep = "10",
604 .coupling_period = "10",
605 .coupling_period_operation = TIME_NONE,
606 .enforce_write_weight_file = 1,
607 .weight_file_name = "weights1.nc",
608 .weight_file_on_existing = YAC_WEIGHT_FILE_ON_EXISTING_DEFAULT_VALUE,
609 .scale_factor = 1.0,
610 .scale_summand = 0.0,
611 .num_src_mask_names = 1,
612 .src_mask_names = (char const*[]){"src_sst_mask"},
613 .tgt_mask_name = "tgt_sst_mask",
614 .yaxt_exchanger_name = "irecv_send",
615 .collection_selection = yac_collection_selection_new(1, (size_t[]){1}),
616 .use_raw_exchange = 1},
617 {.ref_src_field_data_idx = 3,
618 .ref_tgt_field_data_idx = 2,
619 .interp_stack_config = NULL,
620 .mapping_on_source = 1,
621 .src_lag = 1,
622 .tgt_lag = 3,
623 .src_timestep = "2",
624 .tgt_timestep = "20",
625 .coupling_period = "20",
626 .coupling_period_operation = TIME_ACCUMULATE,
627 .enforce_write_weight_file = 0,
628 .weight_file_name = "\0",
629 .weight_file_on_existing = YAC_WEIGHT_FILE_ON_EXISTING_DEFAULT_VALUE,
630 .scale_factor = 10.0,
631 .scale_summand = 0.0,
632 .num_src_mask_names = 3,
633 .src_mask_names = (char const*[]){"src_wind_mask1", "src_wind_mask2", "src_wind_mask3"},
634 .tgt_mask_name = NULL,
635 .yaxt_exchanger_name = NULL,
636 .collection_selection = NULL,
637 .use_raw_exchange = 0},
638 {.ref_src_field_data_idx = 4,
639 .ref_tgt_field_data_idx = 5,
640 .interp_stack_config = NULL,
641 .mapping_on_source = 0,
642 .src_lag = 2,
643 .tgt_lag = 2,
644 .src_timestep = "3",
645 .tgt_timestep = "30",
646 .coupling_period = "30",
647 .coupling_period_operation = TIME_AVERAGE,
648 .enforce_write_weight_file = 1,
649 .weight_file_name = "weights3.nc",
650 .weight_file_on_existing = YAC_WEIGHT_FILE_KEEP,
651 .scale_factor = 1.0,
652 .scale_summand = -1.0,
653 .num_src_mask_names = 0,
654 .src_mask_names = NULL,
655 .tgt_mask_name = NULL,
656 .yaxt_exchanger_name = NULL,
657 .collection_selection = yac_collection_selection_new(2,(size_t[]){1,3}),
658 .use_raw_exchange = 0},
659 {.ref_src_field_data_idx = 7,
660 .ref_tgt_field_data_idx = 6,
661 .interp_stack_config = NULL,
662 .mapping_on_source = 0,
663 .src_lag = 3,
664 .tgt_lag = 1,
665 .src_timestep = "4",
666 .tgt_timestep = "40",
667 .coupling_period = "40",
668 .coupling_period_operation = TIME_MINIMUM,
669 .enforce_write_weight_file = 0,
670 .weight_file_name = "\0",
671 .weight_file_on_existing = YAC_WEIGHT_FILE_ON_EXISTING_DEFAULT_VALUE,
672 .scale_factor = 0.5,
673 .scale_summand = -0.5,
674 .num_src_mask_names = 0,
675 .src_mask_names = NULL,
676 .tgt_mask_name = NULL,
677 .yaxt_exchanger_name = NULL,
678 .collection_selection = NULL,
679 .use_raw_exchange = 0},
680 {.ref_src_field_data_idx = 8,
681 .ref_tgt_field_data_idx = 9,
682 .interp_stack_config = NULL,
683 .mapping_on_source = 1,
684 .src_lag = 4,
685 .tgt_lag = 0,
686 .src_timestep = "5",
687 .tgt_timestep = "50",
688 .coupling_period = "50",
689 .coupling_period_operation = TIME_MAXIMUM,
690 .enforce_write_weight_file = 1,
691 .weight_file_name = "weights5.nc",
692 .weight_file_on_existing = YAC_WEIGHT_FILE_ON_EXISTING_DEFAULT_VALUE,
693 .scale_factor = 1.0,
694 .scale_summand = 0.0,
695 .num_src_mask_names = 0,
696 .src_mask_names = NULL,
697 .tgt_mask_name = NULL,
698 .yaxt_exchanger_name = NULL,
699 .collection_selection = NULL,
700 .use_raw_exchange = 0},
701 {.ref_src_field_data_idx = 8,
702 .ref_tgt_field_data_idx = 10,
703 .interp_stack_config = NULL,
704 .mapping_on_source = 1,
705 .src_lag = 4,
706 .tgt_lag = 0,
707 .src_timestep = "5",
708 .tgt_timestep = "50",
709 .coupling_period = "50",
710 .coupling_period_operation = TIME_MAXIMUM,
711 .enforce_write_weight_file = 1,
712 .weight_file_name = "weights6.nc",
713 .weight_file_on_existing = YAC_WEIGHT_FILE_ERROR,
714 .scale_factor = 1.0,
715 .scale_summand = 0.0,
716 .num_src_mask_names = 0,
717 .src_mask_names = NULL,
718 .tgt_mask_name = NULL,
719 .yaxt_exchanger_name = NULL,
720 .collection_selection = NULL,
721 .use_raw_exchange = 0},
722 {.ref_src_field_data_idx = 12,
723 .ref_tgt_field_data_idx = 11,
724 .interp_stack_config = NULL,
725 .mapping_on_source = 0,
726 .src_lag = 0,
727 .tgt_lag = 0,
728 .src_timestep = "6",
729 .tgt_timestep = "60",
730 .coupling_period = "60",
731 .coupling_period_operation = TIME_NONE,
732 .enforce_write_weight_file = 0,
733 .weight_file_name = "\0",
734 .weight_file_on_existing = YAC_WEIGHT_FILE_ON_EXISTING_DEFAULT_VALUE,
735 .scale_factor = 9.0/5.0,
736 .scale_summand = 32.0,
737 .num_src_mask_names = 2,
738 .src_mask_names = (char const*[]){"src_mask1", "src_mask2"},
739 .tgt_mask_name = "tgt_mask",
740 .yaxt_exchanger_name = "irecv_isend",
741 .collection_selection = NULL,
742 .use_raw_exchange = 1},
743 {.ref_src_field_data_idx = 16,
744 .ref_tgt_field_data_idx = 18,
745 .interp_stack_config = NULL,
746 .mapping_on_source = 1,
747 .src_lag = 0,
748 .tgt_lag = 0,
749 .src_timestep = "1",
750 .tgt_timestep = "1",
751 .coupling_period = "1",
752 .coupling_period_operation = TIME_NONE,
753 .enforce_write_weight_file = 0,
754 .weight_file_name = "\0",
755 .weight_file_on_existing = YAC_WEIGHT_FILE_ON_EXISTING_DEFAULT_VALUE,
756 .scale_factor = 1.0,
757 .scale_summand = 0.0,
758 .num_src_mask_names = 0,
759 .src_mask_names = NULL,
760 .tgt_mask_name = NULL,
761 .yaxt_exchanger_name = NULL,
762 .collection_selection = NULL,
763 .use_raw_exchange = 0},
764 {.ref_src_field_data_idx = 16,
765 .ref_tgt_field_data_idx = 19,
766 .interp_stack_config = NULL,
767 .mapping_on_source = 1,
768 .src_lag = 0,
769 .tgt_lag = 0,
770 .src_timestep = "1",
771 .tgt_timestep = "1",
772 .coupling_period = "1",
773 .coupling_period_operation = TIME_NONE,
774 .enforce_write_weight_file = 0,
775 .weight_file_name = "\0",
776 .weight_file_on_existing = YAC_WEIGHT_FILE_ON_EXISTING_DEFAULT_VALUE,
777 .scale_factor = 1.0,
778 .scale_summand = 0.0,
779 .num_src_mask_names = 0,
780 .src_mask_names = NULL,
781 .tgt_mask_name = NULL,
782 .yaxt_exchanger_name = NULL,
783 .collection_selection = NULL,
784 .use_raw_exchange = 0},
785 {.ref_src_field_data_idx = 17,
786 .ref_tgt_field_data_idx = 18,
787 .interp_stack_config = NULL,
788 .mapping_on_source = 1,
789 .src_lag = 0,
790 .tgt_lag = 0,
791 .src_timestep = "1",
792 .tgt_timestep = "1",
793 .coupling_period = "1",
794 .coupling_period_operation = TIME_NONE,
795 .enforce_write_weight_file = 0,
796 .weight_file_name = "\0",
797 .weight_file_on_existing = YAC_WEIGHT_FILE_ON_EXISTING_DEFAULT_VALUE,
798 .scale_factor = 1.0,
799 .scale_summand = 0.0,
800 .num_src_mask_names = 0,
801 .src_mask_names = NULL,
802 .tgt_mask_name = NULL,
803 .yaxt_exchanger_name = NULL,
804 .collection_selection = NULL,
805 .use_raw_exchange = 0},
806 {.ref_src_field_data_idx = 17,
807 .ref_tgt_field_data_idx = 19,
808 .interp_stack_config = NULL,
809 .mapping_on_source = 1,
810 .src_lag = 0,
811 .tgt_lag = 0,
812 .src_timestep = "1",
813 .tgt_timestep = "1",
814 .coupling_period = "1",
815 .coupling_period_operation = TIME_NONE,
816 .enforce_write_weight_file = 0,
817 .weight_file_name = "\0",
818 .weight_file_on_existing = YAC_WEIGHT_FILE_ON_EXISTING_DEFAULT_VALUE,
819 .scale_factor = 1.0,
820 .scale_summand = 0.0,
821 .num_src_mask_names = 0,
822 .src_mask_names = NULL,
823 .tgt_mask_name = NULL,
824 .yaxt_exchanger_name = NULL,
825 .collection_selection = NULL,
826 .use_raw_exchange = 0},
827 {.ref_src_field_data_idx = 21,
828 .ref_tgt_field_data_idx = 20,
829 .interp_stack_config = NULL,
830 .mapping_on_source = 0,
831 .src_lag = 0,
832 .tgt_lag = 0,
833 .src_timestep = "6",
834 .tgt_timestep = "60",
835 .coupling_period = "60",
836 .coupling_period_operation = TIME_NONE,
837 .enforce_write_weight_file = 0,
838 .weight_file_name = "\0",
839 .weight_file_on_existing = YAC_WEIGHT_FILE_ON_EXISTING_DEFAULT_VALUE,
840 .scale_factor = 1.0,
841 .scale_summand = 0.0,
842 .num_src_mask_names = 0,
843 .src_mask_names = NULL,
844 .tgt_mask_name = NULL,
845 .yaxt_exchanger_name = NULL,
846 .collection_selection = yac_collection_selection_new(3, (size_t[]){0,2,4}),
847 .use_raw_exchange = 1}};
848 enum {
849 REF_NUM_FIELD_COUPLES =
850 sizeof(ref_field_couple_data) / sizeof(ref_field_couple_data[0])};
851
852 {
853 struct yac_interp_spmap_config * spmap_default_config =
855 0.1 * YAC_RAD, 0.2 * YAC_RAD, YAC_INTERP_SPMAP_DIST, NULL);
856 struct {
857 struct yac_point_selection * src_point_selection;
858 struct yac_interp_spmap_config * spmap_config;
859 } spmap_overwrite_config_data[] = {
860 {.src_point_selection = // amazon_delta
862 -50.0 * YAC_RAD, 0.0 * YAC_RAD, 4.0 * YAC_RAD),
863 .spmap_config =
865 0.3 * YAC_RAD,
869 {.src_point_selection = // north_pole
871 0.0 * YAC_RAD, 90.0 * YAC_RAD, 2.0 * YAC_RAD),
872 .spmap_config =
875 0.4 * YAC_RAD,
878 {.src_point_selection = // south_pole
880 180.0 * YAC_RAD, -90.0 * YAC_RAD, 2.0 * YAC_RAD),
881 .spmap_config =
883 0.5 * YAC_RAD,
884 0.6 * YAC_RAD,
887 enum {
888 NUM_SPMAP_OVERWRITE_CONFIGS =
889 sizeof(spmap_overwrite_config_data)/
890 sizeof(spmap_overwrite_config_data[0])};
891 struct yac_spmap_overwrite_config ** spmap_overwrite_configs =
892 xmalloc(
893 (NUM_SPMAP_OVERWRITE_CONFIGS + 1) * sizeof(*spmap_overwrite_configs));
894 for (size_t i = 0; i < NUM_SPMAP_OVERWRITE_CONFIGS; ++i)
895 spmap_overwrite_configs[i] =
897 spmap_overwrite_config_data[i].src_point_selection,
898 spmap_overwrite_config_data[i].spmap_config);
899 spmap_overwrite_configs[NUM_SPMAP_OVERWRITE_CONFIGS] = NULL;
901 ADD_INTERP(nnn,
906 ADD_INTERP(conservative, 1, 0, 0, YAC_INTERP_CONSERV_DESTAREA)
909 user_file, "weights.nc", YAC_INTERP_FILE_ON_MISSING_FILE_DEFAULT,
911 ADD_INTERP(spmap_ext,
912 spmap_default_config, spmap_overwrite_configs)
913 ADD_INTERP(fixed, -1.0))
914 for (size_t i = 0; i < NUM_SPMAP_OVERWRITE_CONFIGS; ++i) {
916 spmap_overwrite_config_data[i].src_point_selection);
918 spmap_overwrite_config_data[i].spmap_config);
919 }
920 yac_spmap_overwrite_configs_delete(spmap_overwrite_configs);
921 yac_interp_spmap_config_delete(spmap_default_config);
922 }
923
926 ADD_INTERP(nnn,
929 ADD_INTERP(conservative, 2, 1, 1, YAC_INTERP_CONSERV_FRACAREA))
930
932 ADD_INTERP(check, "", "")
933 ADD_INTERP(check, "check_constructor", "")
934 ADD_INTERP(check, "", "check_do_search")
935 ADD_INTERP(check, "check_constructor", "check_do_search")
936 ADD_INTERP(nnn,
939
941 ADD_INTERP(nnn, YAC_INTERP_NNN_GAUSS, 8, M_PI_2, 0.2)
942 ADD_INTERP(spmap,
945 0.0, "area.nc", "cell_area", 1,
949 ADD_INTERP(nnn,
951
953 ADD_INTERP(creep, 5)
954 ADD_INTERP(user_callback, "compute_weights")
955 ADD_INTERP(fixed, -2.0))
956
958 ADD_INTERP(creep, -1)
959 ADD_INTERP(user_callback, "compute_weights")
961 user_file, "weights.nc", YAC_INTERP_FILE_MISSING_CONT,
963 ADD_INTERP(fixed, -1.0))
964
967 ADD_INTERP(fixed, -1.0))
968
970 ADD_INTERP(fixed, NAN))
972 ADD_INTERP(fixed, NAN))
974 ADD_INTERP(fixed, NAN))
976 ADD_INTERP(fixed, NAN))
977
980 ADD_INTERP(fixed, -1.0))
981
982 int ref_missing_definition_is_fatal = 1;
983
984 //---------------------------------------------------------------------------
985 // testing date stuff
986 //---------------------------------------------------------------------------
987
988 char * start_datetime =
990 if (utest_compare_string(start_datetime, ref_start_datetime))
992 free(start_datetime);
993
994 char * end_datetime =
996 if (utest_compare_string(end_datetime, ref_end_datetime))
998 free(end_datetime);
999
1000 if (yac_couple_config_get_num_components(couple_config) != REF_NUM_COMPS)
1002
1003 //---------------------------------------------------------------------------
1004 // testing component stuff
1005 //---------------------------------------------------------------------------
1006
1007 for (size_t i = 0; i < REF_NUM_COMPS; ++i) {
1008
1010 couple_config, ref_comp_data[i].name))
1011 PUT_ERR("ERROR in yac_couple_config_component_name_is_valid");
1012
1013 if (utest_compare_string(
1015 couple_config, ref_comp_data[i].name),
1016 ref_comp_data[i].metadata))
1017 PUT_ERR("ERROR in yac_couple_config_component_get_metadata");
1018
1019 size_t comp_idx =
1021 couple_config, ref_comp_data[i].name);
1022 if (utest_compare_string(
1023 yac_couple_config_get_component_name(couple_config, comp_idx),
1024 ref_comp_data[i].name))
1025 PUT_ERR("ERROR in yac_couple_config_get_component_name");
1026
1027 // count number of associated fields
1028 size_t ref_num_comp_fields = 0;
1029 for (size_t j = 0; j < REF_NUM_FIELDS; ++j)
1030 if (ref_field_data[j].ref_comp_data_idx == i)
1031 ++ref_num_comp_fields;
1032
1033 if (yac_couple_config_get_num_fields(couple_config, comp_idx) !=
1034 ref_num_comp_fields)
1035 PUT_ERR("ERROR in yac_couple_config_get_num_fields");
1036 }
1037
1038 if (yac_couple_config_component_name_is_valid(couple_config, "INVALID"))
1039 PUT_ERR("ERROR in yac_couple_config_component_name_is_valid");
1040
1041 //---------------------------------------------------------------------------
1042 // testing grid stuff
1043 //---------------------------------------------------------------------------
1044
1045 if (yac_couple_config_get_num_grids(couple_config) != REF_NUM_GRIDS)
1046 PUT_ERR("ERROR in yac_couple_config_get_num_grids");
1047
1048 for (size_t i = 0; i < REF_NUM_GRIDS; ++i) {
1049
1051 couple_config, ref_grid_data[i].name))
1052 PUT_ERR("ERROR in yac_couple_config_contains_grid_name\n");
1053
1054 if (utest_compare_string(
1056 couple_config, ref_grid_data[i].name),
1057 ref_grid_data[i].output_filename))
1058 PUT_ERR("ERROR in yac_couple_config_grid_get_output_filename");
1059
1060 if (utest_compare_string(
1062 couple_config, ref_grid_data[i].name), ref_grid_data[i].metadata))
1063 PUT_ERR("ERROR in yac_couple_config_grid_get_metadata");
1064
1065 size_t grid_idx =
1067 couple_config, ref_grid_data[i].name);
1068 if (utest_compare_string(
1070 ref_grid_data[i].name))
1071 PUT_ERR("ERROR in yac_couple_config_get_grid_name");
1072 }
1073
1074 if (yac_couple_config_contains_grid_name(couple_config, "grid5"))
1075 PUT_ERR("ERROR in yac_couple_config_contains_grid_name\n");
1076
1077 //---------------------------------------------------------------------------
1078 // testing field stuff
1079 //---------------------------------------------------------------------------
1080
1081 for (size_t i = 0; i < REF_NUM_FIELDS; ++i) {
1082
1083 char const * field_comp_name =
1084 ref_comp_data[ref_field_data[i].ref_comp_data_idx].name;
1085 char const * field_grid_name =
1086 ref_grid_data[ref_field_data[i].ref_grid_data_idx].name;
1087 char const * field_name = ref_field_data[i].name;
1088
1089 if (utest_compare_string(
1091 couple_config, field_comp_name, field_grid_name, field_name),
1092 ref_field_data[i].metadata))
1093 PUT_ERR("ERROR in yac_couple_config_field_get_metadata");
1094
1095 // use memcmp to compare the values because they can be nan
1096 double frac_mask_fallback_value =
1098 couple_config, field_comp_name, field_grid_name, field_name);
1099 if (memcmp(
1100 &frac_mask_fallback_value, &ref_field_data[i].frac_mask_value,
1101 sizeof(frac_mask_fallback_value)))
1102 PUT_ERR("ERROR in yac_couple_config_get_frac_mask_fallback_value");
1103
1104 size_t comp_idx =
1106 couple_config, ref_comp_data[ref_field_data[i].ref_comp_data_idx].name);
1107 size_t grid_idx =
1109 couple_config, ref_grid_data[ref_field_data[i].ref_grid_data_idx].name);
1110 size_t field_idx =
1112 couple_config, comp_idx, grid_idx, ref_field_data[i].name);
1113
1114 if (utest_compare_string(
1116 couple_config, comp_idx, field_idx), field_grid_name))
1117 PUT_ERR("ERROR in yac_couple_config_get_field_grid_name");
1118
1119 if (utest_compare_string(
1121 couple_config, comp_idx, field_idx), field_name))
1122 PUT_ERR("ERROR in yac_couple_config_get_field_name");
1123
1124 // timestep can only be queried if it is valid
1125 if (ref_field_data[i].timestep != NULL)
1126 if (utest_compare_string(
1128 couple_config, field_comp_name, field_grid_name, field_name),
1129 yac_time_to_ISO(ref_field_data[i].timestep, C_SECOND)))
1130 PUT_ERR("ERROR in yac_couple_config_get_field_timestep");
1131
1132 // collection size can only be queried if it is valid
1133 if (ref_field_data[i].collection_size != SIZE_MAX)
1135 couple_config, field_comp_name, field_grid_name, field_name) !=
1136 ref_field_data[i].collection_size)
1137 PUT_ERR("ERROR in yac_couple_config_get_field_collection_size");
1138
1140 couple_config, field_comp_name, field_grid_name, field_name) !=
1141 ref_field_data[i].role)
1142 PUT_ERR("ERROR in yac_couple_config_get_field_role");
1143
1144 if (yac_couple_config_field_is_valid(couple_config, comp_idx, field_idx) !=
1145 ((ref_field_data[i].timestep != NULL) &&
1146 (ref_field_data[i].collection_size != SIZE_MAX)))
1147 PUT_ERR("ERROR in yac_couple_config_field_is_valid");
1148 }
1149
1150 //---------------------------------------------------------------------------
1151 // testing couple stuff
1152 //---------------------------------------------------------------------------
1153
1154 if (yac_couple_config_get_num_couples(couple_config) != REF_NUM_COUPLES)
1155 PUT_ERR("ERROR in yac_couple_config_get_num_couples\n");
1156
1157 for (size_t i = 0; i < REF_NUM_COUPLES; ++i) {
1158
1159 char const * ref_comp_names[2];
1160 ref_comp_names[0] = ref_comp_data[ref_couple_data[i].ref_comp_data_idxs[0]].name;
1161 ref_comp_names[1] = ref_comp_data[ref_couple_data[i].ref_comp_data_idxs[1]].name;
1162
1163 // find matching couple
1164 size_t couple_idx = SIZE_MAX;
1165 for (size_t j = 0; (j < REF_NUM_COUPLES) && (couple_idx == SIZE_MAX); ++j) {
1166
1167 char const * couple_comp_names[2];
1169 couple_config, j, couple_comp_names);
1170 if ((!utest_compare_string(couple_comp_names[0], ref_comp_names[0]) &&
1171 !utest_compare_string(couple_comp_names[1], ref_comp_names[1])) ||
1172 (!utest_compare_string(couple_comp_names[0], ref_comp_names[1]) &&
1173 !utest_compare_string(couple_comp_names[1], ref_comp_names[0])))
1174 couple_idx = j;
1175 }
1176
1177 if (couple_idx == SIZE_MAX) {
1178 PUT_ERR("ERROR: no matching couple found\n");
1179 continue;
1180 }
1181
1182 size_t num_couple_fields = 0;
1183 for (size_t j = 0; j < REF_NUM_FIELD_COUPLES; ++j)
1184 if (((ref_field_data[ref_field_couple_data[j].ref_src_field_data_idx].ref_comp_data_idx ==
1185 ref_couple_data[i].ref_comp_data_idxs[0]) &&
1186 (ref_field_data[ref_field_couple_data[j].ref_tgt_field_data_idx].ref_comp_data_idx ==
1187 ref_couple_data[i].ref_comp_data_idxs[1])) ||
1188 ((ref_field_data[ref_field_couple_data[j].ref_src_field_data_idx].ref_comp_data_idx ==
1189 ref_couple_data[i].ref_comp_data_idxs[1]) &&
1190 (ref_field_data[ref_field_couple_data[j].ref_tgt_field_data_idx].ref_comp_data_idx ==
1191 ref_couple_data[i].ref_comp_data_idxs[0])))
1192 ++num_couple_fields;
1193
1194 if (yac_couple_config_get_num_couple_fields(couple_config, couple_idx) !=
1195 num_couple_fields)
1196 PUT_ERR("ERROR in yac_couple_config_get_num_couple_fields");
1197 }
1198
1199 //-------------------------------------------------------------------------
1200 // testing field couple stuff
1201 //-------------------------------------------------------------------------
1202
1203 for (size_t i = 0; i < REF_NUM_FIELD_COUPLES; ++i) {
1204
1205 // find reference couple data
1206 size_t ref_couple_data_idx;
1207 for (ref_couple_data_idx = 0; ref_couple_data_idx < REF_NUM_COUPLES; ++ref_couple_data_idx)
1208 if (((ref_field_data[ref_field_couple_data[i].ref_src_field_data_idx].ref_comp_data_idx ==
1209 ref_couple_data[ref_couple_data_idx].ref_comp_data_idxs[0]) &&
1210 (ref_field_data[ref_field_couple_data[i].ref_tgt_field_data_idx].ref_comp_data_idx ==
1211 ref_couple_data[ref_couple_data_idx].ref_comp_data_idxs[1])) ||
1212 ((ref_field_data[ref_field_couple_data[i].ref_src_field_data_idx].ref_comp_data_idx ==
1213 ref_couple_data[ref_couple_data_idx].ref_comp_data_idxs[1]) &&
1214 (ref_field_data[ref_field_couple_data[i].ref_tgt_field_data_idx].ref_comp_data_idx ==
1215 ref_couple_data[ref_couple_data_idx].ref_comp_data_idxs[0]))) break;
1216
1217 char const * ref_comp_names[2];
1218 ref_comp_names[0] =
1219 ref_comp_data[ref_couple_data[ref_couple_data_idx].ref_comp_data_idxs[0]].name;
1220 ref_comp_names[1] =
1221 ref_comp_data[ref_couple_data[ref_couple_data_idx].ref_comp_data_idxs[1]].name;
1222
1223 // find matching couple
1224 size_t couple_idx = SIZE_MAX;
1225 for (size_t j = 0; (j < REF_NUM_COUPLES) && (couple_idx == SIZE_MAX); ++j) {
1226
1227 char const * couple_comp_names[2];
1229 couple_config, j, couple_comp_names);
1230 if ((!utest_compare_string(couple_comp_names[0], ref_comp_names[0]) &&
1231 !utest_compare_string(couple_comp_names[1], ref_comp_names[1])) ||
1232 (!utest_compare_string(couple_comp_names[0], ref_comp_names[1]) &&
1233 !utest_compare_string(couple_comp_names[1], ref_comp_names[0])))
1234 couple_idx = j;
1235 }
1236
1237 if (couple_idx == SIZE_MAX) {
1238 PUT_ERR("ERROR: no matching couple found\n");
1239 continue;
1240 }
1241
1242 size_t num_couples =
1243 yac_couple_config_get_num_couple_fields(couple_config, couple_idx);
1244
1245 char const * src_comp_name, * tgt_comp_name;
1246 char const * src_grid_name, * tgt_grid_name;
1247 char const * src_field_name, * tgt_field_name;
1248
1249 // find matching field couple index
1250 size_t field_couple_idx = SIZE_MAX;
1251 for (size_t j = 0; (j < num_couples) && (field_couple_idx == SIZE_MAX); ++j) {
1252
1254 couple_config, couple_idx, j, &src_comp_name, &tgt_comp_name);
1256 couple_config, couple_idx, j, &src_grid_name, &tgt_grid_name);
1258 couple_config, couple_idx, j, &src_field_name, &tgt_field_name);
1259
1260 if (!utest_compare_string(
1261 src_comp_name,
1262 ref_comp_data[
1263 ref_field_data[
1264 ref_field_couple_data[i].
1265 ref_src_field_data_idx].ref_comp_data_idx].name) &&
1266 !utest_compare_string(
1267 tgt_comp_name,
1268 ref_comp_data[
1269 ref_field_data[
1270 ref_field_couple_data[i].
1271 ref_tgt_field_data_idx].ref_comp_data_idx].name) &&
1272 !utest_compare_string(
1274 ref_grid_data[
1275 ref_field_data[
1276 ref_field_couple_data[i].
1277 ref_src_field_data_idx].ref_grid_data_idx].name) &&
1278 !utest_compare_string(
1280 ref_grid_data[
1281 ref_field_data[
1282 ref_field_couple_data[i].
1283 ref_tgt_field_data_idx].ref_grid_data_idx].name) &&
1284 !utest_compare_string(
1285 src_field_name,
1286 ref_field_data[
1287 ref_field_couple_data[i].ref_src_field_data_idx].name) &&
1288 !utest_compare_string(
1289 tgt_field_name,
1290 ref_field_data[
1291 ref_field_couple_data[i].ref_tgt_field_data_idx].name))
1292 field_couple_idx = j;
1293 }
1294
1295 if (field_couple_idx == SIZE_MAX) {
1296 PUT_ERR("ERROR: no matching field couple found\n");
1297 continue;
1298 }
1299
1301 ref_field_couple_data[i].interp_stack_config,
1303 couple_config, couple_idx, field_couple_idx)))
1304 PUT_ERR("ERROR in yac_interp_stack_config");
1305
1307 ref_field_couple_data[i].interp_stack_config);
1308
1310 couple_config, couple_idx, field_couple_idx) !=
1311 ref_field_couple_data[i].mapping_on_source)
1312 PUT_ERR("ERROR in yac_couple_config_mapping_on_source");
1313
1315 couple_config, couple_idx, field_couple_idx) !=
1316 ref_field_couple_data[i].src_lag)
1317 PUT_ERR("ERROR in yac_couple_config_get_source_lag");
1318
1320 couple_config, couple_idx, field_couple_idx) !=
1321 ref_field_couple_data[i].tgt_lag)
1322 PUT_ERR("ERROR in yac_couple_config_get_target_lag");
1323
1324 if (utest_compare_string(
1326 couple_config, couple_idx, field_couple_idx),
1327 yac_time_to_ISO(ref_field_couple_data[i].src_timestep, C_SECOND)))
1328 PUT_ERR("ERROR in yac_couple_config_get_source_timestep");
1329
1330 if (utest_compare_string(
1332 couple_config, couple_idx, field_couple_idx),
1333 yac_time_to_ISO(ref_field_couple_data[i].tgt_timestep, C_SECOND)))
1334 PUT_ERR("ERROR in yac_couple_config_get_target_timestep");
1335
1336 if (utest_compare_string(
1338 couple_config, couple_idx, field_couple_idx),
1339 yac_time_to_ISO(ref_field_couple_data[i].coupling_period, C_SECOND)))
1340 PUT_ERR("ERROR in yac_couple_config_get_coupling_period");
1341
1343 couple_config, couple_idx, field_couple_idx) !=
1344 ref_field_couple_data[i].coupling_period_operation)
1345 PUT_ERR("ERROR in yac_couple_config_get_coupling_period_operation");
1346
1348 couple_config, couple_idx, field_couple_idx) !=
1349 ref_field_couple_data[i].enforce_write_weight_file)
1350 PUT_ERR("ERROR in yac_couple_config_enforce_write_weight_file");
1351
1352 if (utest_compare_string(
1354 couple_config, couple_idx, field_couple_idx),
1355 ref_field_couple_data[i].weight_file_name))
1356 PUT_ERR("ERROR in yac_couple_config_get_weight_file_name");
1357
1359 couple_config, couple_idx, field_couple_idx) !=
1360 ref_field_couple_data[i].weight_file_on_existing)
1361 PUT_ERR("ERROR in yac_couple_config_get_weight_file_on_existing");
1362
1364 couple_config, couple_idx, field_couple_idx) !=
1365 ref_field_couple_data[i].scale_factor)
1366 PUT_ERR("ERROR in yac_couple_config_get_scale_factor");
1367
1369 couple_config, couple_idx, field_couple_idx) !=
1370 ref_field_couple_data[i].scale_summand)
1371 PUT_ERR("ERROR in yac_couple_config_get_scale_summand");
1372
1373 char const * const * src_mask_names;
1374 size_t num_src_mask_names;
1376 couple_config, couple_idx, field_couple_idx,
1377 &src_mask_names, &num_src_mask_names);
1378 if (ref_field_couple_data[i].num_src_mask_names != num_src_mask_names)
1379 PUT_ERR("ERROR in yac_couple_config_get_src_mask_names");
1380 if (ref_field_couple_data[i].num_src_mask_names == num_src_mask_names)
1381 for (size_t j = 0; j < num_src_mask_names; ++j)
1382 if (utest_compare_string(
1383 ref_field_couple_data[i].src_mask_names[j], src_mask_names[j]))
1384 PUT_ERR("ERROR in yac_couple_config_get_src_mask_names");
1385
1386 char const * tgt_mask_name =
1388 couple_config, couple_idx, field_couple_idx);
1389 if (utest_compare_string(
1390 ref_field_couple_data[i].tgt_mask_name, tgt_mask_name))
1391 PUT_ERR("ERROR in yac_couple_config_get_tgt_mask_name");
1392
1393 char const * yaxt_exchanger_name =
1395 couple_config, couple_idx, field_couple_idx);
1396 if (utest_compare_string(
1397 ref_field_couple_data[i].yaxt_exchanger_name, yaxt_exchanger_name))
1398 PUT_ERR("ERROR in yac_couple_config_get_yaxt_exchanger_name");
1399
1402 couple_config, couple_idx, field_couple_idx);
1404 ref_field_couple_data[i].collection_selection, collection_selection))
1405 PUT_ERR("ERROR in yac_couple_config_get_collection_selection");
1406
1408 couple_config, couple_idx, field_couple_idx) !=
1409 ref_field_couple_data[i].use_raw_exchange)
1410 PUT_ERR("ERROR in yac_couple_config_get_use_raw_exchange");
1411
1412 if (utest_compare_string("multi_grid_field", tgt_field_name)) {
1413 char const * src_comp_name_, * src_grid_name_, * src_field_name_;
1414
1416 couple_config, tgt_comp_name, tgt_grid_name, tgt_field_name,
1417 &src_comp_name_, &src_grid_name_, &src_field_name_);
1418
1419 if (utest_compare_string(src_comp_name, src_comp_name_) ||
1420 utest_compare_string(src_grid_name, src_grid_name_) ||
1421 utest_compare_string(src_field_name, src_field_name_))
1422 PUT_ERR("ERROR in yac_couple_config_get_field_source");
1423 }
1424
1425 { // testing yac_couple_config_get_interpolation_gen_config
1426 struct yac_interpolation_gen_config * ref_interp_gen_config =
1428
1429 if (!ref_field_couple_data[i].mapping_on_source)
1431 ref_interp_gen_config, YAC_MAPPING_ON_TGT);
1432 if (ref_field_couple_data[i].collection_selection == NULL) {
1434 ref_interp_gen_config,
1435 ref_field_data[
1436 ref_field_couple_data[i].ref_src_field_data_idx].collection_size);
1437 } else {
1439 ref_interp_gen_config, ref_field_couple_data[i].collection_selection);
1440 }
1442 ref_field_data[
1443 ref_field_couple_data[i].ref_src_field_data_idx].frac_mask_value))
1445 ref_interp_gen_config,
1446 ref_field_data[
1447 ref_field_couple_data[i].ref_src_field_data_idx].frac_mask_value);
1449 ref_interp_gen_config, ref_field_couple_data[i].scale_factor);
1451 ref_interp_gen_config, ref_field_couple_data[i].scale_summand);
1453 ref_interp_gen_config, ref_field_couple_data[i].yaxt_exchanger_name);
1454
1455 struct yac_interpolation_gen_config * interp_gen_config =
1457 couple_config, couple_idx, field_couple_idx);
1458
1460 ref_interp_gen_config, interp_gen_config))
1461 PUT_ERR("ERROR in yac_couple_config_get_interpolation_gen_config");
1462
1463 yac_interpolation_gen_config_delete(interp_gen_config);
1464 yac_interpolation_gen_config_delete(ref_interp_gen_config);
1465 }
1466 }
1467
1468 //-------------------------------------------------------------------------
1469 // cleanup
1470 //-------------------------------------------------------------------------
1471
1472 for (size_t i = 0; i < REF_NUM_FIELD_COUPLES; ++i) {
1474 ref_field_couple_data[i].collection_selection);
1475 }
1476
1477 //-------------------------------------------------------------------------
1478 // testing missing_definition_is_fatal-flag
1479 //-------------------------------------------------------------------------
1480
1482 ref_missing_definition_is_fatal)
1483 PUT_ERR("ERROR in yac_couple_config_get_missing_definition_is_fatal");
1484}
1485
1486static void utest_check_couple_config(
1487 struct yac_couple_config * couple_config) {
1488
1489 utest_check_couple_config_no_delete(couple_config);
1490
1492 couple_config, "2008-03-09T16:05:07", "2008-03-10T16:05:07");
1493
1494 char * start_datetime =
1496 if (utest_compare_string(start_datetime, ref_start_datetime))
1497 PUT_ERR("ERROR in yac_couple_config_get_start_datetime\n");
1498 free(start_datetime);
1499
1500 char * end_datetime =
1502 if (utest_compare_string(end_datetime, ref_end_datetime))
1503 PUT_ERR("ERROR in yac_couple_config_get_end_datetime\n");
1504 free(end_datetime);
1505
1506 yac_couple_config_delete(couple_config);
1507}
1508
1509static struct yac_couple_config *
1510 utest_generate_couple_config_from_YAML_parallel(
1511 char const * config_filename, int parse_flags) {
1512
1513 int size, rank;
1514 MPI_Comm_rank ( MPI_COMM_WORLD, &rank );
1515 MPI_Comm_size ( MPI_COMM_WORLD, &size );
1516
1517 struct yac_couple_config * couple_config = yac_couple_config_new();
1518
1519 // same datetime but with additional ".000" at the end
1520 if (rank == 0)
1522 couple_config, "2008-03-09T16:05:07.000", "2008-03-10T16:05:07.000");
1523 if (rank == 1)
1525 couple_config, "2008-03-09T16:05:07", "2008-03-10T16:05:07");
1526
1527 yac_couple_config_add_grid(couple_config, "grid1");
1528 yac_couple_config_add_grid(couple_config, "grid2");
1529 yac_couple_config_add_grid(couple_config, "grid3");
1530 yac_couple_config_add_grid(couple_config, "grid4");
1531 yac_couple_config_add_grid(couple_config, "src_grid_1");
1532 yac_couple_config_add_grid(couple_config, "src_grid_2");
1533 yac_couple_config_add_grid(couple_config, "tgt_grid_1");
1534 yac_couple_config_add_grid(couple_config, "tgt_grid_2");
1535
1536 if (rank == 0)
1538 couple_config, "grid1", "grid1_meta");
1539 if (rank == 1)
1541 couple_config, "grid2", "grid2_meta");
1542 if (rank == 0)
1544 couple_config, "grid4", "debug_grid.nc");
1545
1546 yac_couple_config_add_component(couple_config, "ICON-O");
1547 yac_couple_config_add_component(couple_config, "ICON-A");
1548 yac_couple_config_add_component(couple_config, "DUMMY");
1549 yac_couple_config_add_component(couple_config, "DUMMY_2");
1550 yac_couple_config_add_component(couple_config, "src_comp");
1551 yac_couple_config_add_component(couple_config, "tgt_comp");
1552
1553 // add metadata to some components
1554 if (rank == 0)
1556 couple_config, "ICON-O", "a lot of water");
1557 if (rank == 1)
1559 couple_config, "ICON-A", "a lot of hot air");
1560
1561 // only rank 0 provides a valid collection size and metadata
1563 couple_config, "ICON-O", "grid1", "sea_surface_temperature",
1564 yac_time_to_ISO("1", C_SECOND), (rank == 0)?3:SIZE_MAX);
1566 couple_config, "ICON-A", "grid3", "sea_surface_temperature",
1567 yac_time_to_ISO("10", C_SECOND), (rank == 0)?1:SIZE_MAX);
1568 if (rank == 0) {
1570 couple_config, "ICON-O", "grid1", "sea_surface_temperature", "T in C");
1572 couple_config, "ICON-A", "grid3", "sea_surface_temperature", "T in K");
1573 }
1574
1575 // only rank 1 provides a valid collection size,
1576 // fractional mask fallback value, and metadata
1578 couple_config, "ICON-A", "grid3", "wind_speed",
1579 yac_time_to_ISO("2", C_SECOND), (rank == 1)?3:SIZE_MAX);
1581 couple_config, "ICON-O", "grid1", "wind_speed",
1582 yac_time_to_ISO("20", C_SECOND), (rank == 1)?3:SIZE_MAX);
1583 if (rank == 1) {
1585 couple_config, "ICON-A", "grid3", "wind_speed", NAN);
1587 couple_config, "ICON-A", "grid3", "wind_speed", NAN);
1589 couple_config, "ICON-O", "grid1", "wind_speed", 1.0);
1591 couple_config, "ICON-A", "grid3", "wind_speed", "v in m/s");
1593 couple_config, "ICON-O", "grid1", "wind_speed", "v in km/h");
1594 }
1595
1596 // only rank 0 provides a valid timestep
1598 couple_config, "ICON-O", "grid1", "water_flux_into_sea_water",
1599 (rank == 0)?yac_time_to_ISO("3", C_SECOND):NULL, 4);
1601 couple_config, "ICON-A", "grid3", "water_flux_into_sea_water",
1602 (rank == 0)?yac_time_to_ISO("30", C_SECOND):NULL, 2);
1604 couple_config, "ICON-O", "grid1", "water_flux_into_sea_water", 0.0);
1606 couple_config, "ICON-A", "grid3", "water_flux_into_sea_water", 0.0);
1607
1608 // only rank 1 provides a valid timestep
1610 couple_config, "ICON-A", "grid3", "grid_eastward_wind",
1611 (rank == 1)?yac_time_to_ISO("4", C_SECOND):NULL, 4);
1613 couple_config, "ICON-O", "grid2", "grid_eastward_wind",
1614 (rank == 1)?yac_time_to_ISO("40", C_SECOND):NULL, 4);
1616 couple_config, "ICON-A", "grid3", "grid_eastward_wind", 0.0);
1617
1619 couple_config, "ICON-O", "grid2", "grid_northward_wind",
1620 yac_time_to_ISO("5", C_SECOND), 5);
1622 couple_config, "ICON-A", "grid3", "grid_northward_wind",
1623 yac_time_to_ISO("50", C_SECOND), 5);
1624
1626 couple_config, "ICON-O", "grid2", "grid_northward_wind",
1627 yac_time_to_ISO("5", C_SECOND), 5);
1629 couple_config, "DUMMY", "grid4", "grid_northward_wind",
1630 yac_time_to_ISO("50", C_SECOND), 5);
1631
1633 couple_config, "src_comp", "src_grid_1", "multi_grid_field",
1634 yac_time_to_ISO("1", C_SECOND), 1);
1636 couple_config, "src_comp", "src_grid_2", "multi_grid_field",
1637 yac_time_to_ISO("1", C_SECOND), 1);
1639 couple_config, "tgt_comp", "tgt_grid_1", "multi_grid_field",
1640 yac_time_to_ISO("1", C_SECOND), 1);
1642 couple_config, "tgt_comp", "tgt_grid_2", "multi_grid_field",
1643 yac_time_to_ISO("1", C_SECOND), 1);
1644
1645 // add couple by hand
1646 if (rank == 0) {
1650 yac_interp_stack_config_add_fixed(interp_stack, -1.0);
1651 {
1653 couple_config, "ICON-O", "grid2", "manual_field",
1654 yac_time_to_ISO("60", C_SECOND), 2);
1657 couple_config, "DUMMY", "grid4", "manual_field",
1658 "ICON-O", "grid2", "manual_field",
1660 interp_stack, 0, 0, NULL, YAC_WEIGHT_FILE_ON_EXISTING_DEFAULT_VALUE,
1661 0, 9.0/5.0, 32.0, 2, (char const *[]){"src_mask1", "src_mask2"},
1662 "tgt_mask", "irecv_isend", collection_selection, 1);
1663 }
1664 {
1666 couple_config, "ICON-O", "grid2", "manual_field_coll_sel",
1667 yac_time_to_ISO("60", C_SECOND), 3);
1669 yac_collection_selection_new(3,(size_t[]){0,2,4});
1671 couple_config, "DUMMY", "grid4", "manual_field_coll_sel",
1672 "ICON-O", "grid2", "manual_field_coll_sel",
1674 interp_stack, 0, 0, NULL, YAC_WEIGHT_FILE_ON_EXISTING_DEFAULT_VALUE,
1675 0, 1.0, 0.0, 0, NULL, NULL, NULL, collection_selection, 1);
1676 yac_collection_selection_delete(collection_selection);
1677 }
1678 yac_interp_stack_config_delete(interp_stack);
1679 } else if (rank == 1) {
1681 couple_config, "DUMMY", "grid4", "manual_field",
1682 yac_time_to_ISO("6", C_SECOND), 2);
1684 couple_config, "DUMMY", "grid4", "manual_field_coll_sel",
1685 yac_time_to_ISO("6", C_SECOND), 5);
1686 }
1687
1688 // rank 1 adds some uncoupled fields to component DUMMY
1689 if (rank == 1) {
1691 couple_config, "DUMMY", "grid4", "manual_field_uncoupled_a",
1692 yac_time_to_ISO("6", C_SECOND), 2);
1694 couple_config, "DUMMY", "grid4", "manual_field_uncoupled_b",
1695 yac_time_to_ISO("6", C_SECOND), SIZE_MAX);
1697 couple_config, "DUMMY", "grid4", "manual_field_uncoupled_c",
1698 NULL, 2);
1699 }
1700
1701 // rank zero reads in couplings from YAML configuration file
1702 if (rank == 0) {
1703 // reading the file twice should not cause any issues
1705 couple_config, config_filename, parse_flags);
1707 couple_config, config_filename, parse_flags);
1708 }
1709
1710 if (rank == 1)
1712
1713 // synchronise coupling configuration across all processes
1714 yac_couple_config_sync(couple_config, MPI_COMM_WORLD, NULL);
1715
1716 return couple_config;
1717}
1718
1719static void utest_write_couple_config_to_YAML(
1720 struct yac_couple_config * couple_config, char const * config_filename,
1721 int emit_flags) {
1722
1723 FILE * yaml_file = fopen(config_filename, "w");
1724
1725 int include_definitions = 0;
1726 char * str_couple_config =
1727 yac_yaml_emit_coupling(couple_config, emit_flags, include_definitions);
1728
1729 fputs(str_couple_config, yaml_file);
1730 free(str_couple_config);
1731 fclose(yaml_file);
1732}
1733
1734static struct yac_couple_config * utest_generate_couple_config_from_YAML(
1735 char const * config_filename, int parse_flags) {
1736
1737 struct yac_couple_config * couple_config = yac_couple_config_new();
1739 couple_config, config_filename, parse_flags);
1740
1741 // add stuff not included in the configuration file
1742 yac_couple_config_add_component(couple_config, "DUMMY_2");
1744 couple_config, "ICON-O", "a lot of water");
1746 couple_config, "ICON-A", "a lot of hot air");
1748 couple_config, "grid1", "grid1_meta");
1750 couple_config, "grid2", "grid2_meta");
1752 couple_config, "grid4", "debug_grid.nc");
1754 couple_config, "ICON-O", "grid1", "sea_surface_temperature",
1755 yac_time_to_ISO("1", C_SECOND), 3);
1757 couple_config, "ICON-A", "grid3", "sea_surface_temperature",
1758 yac_time_to_ISO("10", C_SECOND), 1);
1760 couple_config, "ICON-O", "grid1", "sea_surface_temperature", "T in C");
1762 couple_config, "ICON-A", "grid3", "sea_surface_temperature", "T in K");
1764 couple_config, "ICON-A", "grid3", "wind_speed",
1765 yac_time_to_ISO("2", C_SECOND), 3);
1767 couple_config, "ICON-A", "grid3", "wind_speed", NAN);
1769 couple_config, "ICON-O", "grid1", "wind_speed",
1770 yac_time_to_ISO("20", C_SECOND), 3);
1772 couple_config, "ICON-O", "grid1", "wind_speed", 1.0);
1774 couple_config, "ICON-A", "grid3", "wind_speed", "v in m/s");
1776 couple_config, "ICON-O", "grid1", "wind_speed", "v in km/h");
1778 couple_config, "ICON-O", "grid1", "water_flux_into_sea_water",
1779 yac_time_to_ISO("3", C_SECOND), 4);
1781 couple_config, "ICON-O", "grid1", "water_flux_into_sea_water", 0.0);
1783 couple_config, "ICON-A", "grid3", "water_flux_into_sea_water",
1784 yac_time_to_ISO("30", C_SECOND), 2);
1786 couple_config, "ICON-A", "grid3", "water_flux_into_sea_water", 0.0);
1788 couple_config, "ICON-A", "grid3", "grid_eastward_wind",
1789 yac_time_to_ISO("4", C_SECOND), 4);
1791 couple_config, "ICON-A", "grid3", "grid_eastward_wind", 0.0);
1793 couple_config, "ICON-O", "grid2", "grid_eastward_wind",
1794 yac_time_to_ISO("40", C_SECOND), 4);
1796 couple_config, "ICON-O", "grid2", "grid_northward_wind",
1797 yac_time_to_ISO("5", C_SECOND), 5);
1799 couple_config, "ICON-A", "grid3", "grid_northward_wind",
1800 yac_time_to_ISO("50", C_SECOND), 5);
1802 couple_config, "DUMMY", "grid4", "grid_northward_wind",
1803 yac_time_to_ISO("50", C_SECOND), 5);
1805 couple_config, "ICON-O", "grid2", "manual_field",
1806 yac_time_to_ISO("60", C_SECOND), 2);
1808 couple_config, "DUMMY", "grid4", "manual_field",
1809 yac_time_to_ISO("6", C_SECOND), 2);
1811 couple_config, "DUMMY", "grid4", "manual_field_uncoupled_a",
1812 yac_time_to_ISO("6", C_SECOND), 2);
1814 couple_config, "DUMMY", "grid4", "manual_field_uncoupled_b",
1815 yac_time_to_ISO("6", C_SECOND), SIZE_MAX);
1817 couple_config, "DUMMY", "grid4", "manual_field_uncoupled_c",
1818 NULL, 2);
1820 couple_config, "src_comp", "src_grid_1", "multi_grid_field",
1821 yac_time_to_ISO("1", C_SECOND), 1);
1823 couple_config, "src_comp", "src_grid_2", "multi_grid_field",
1824 yac_time_to_ISO("1", C_SECOND), 1);
1826 couple_config, "tgt_comp", "tgt_grid_1", "multi_grid_field",
1827 yac_time_to_ISO("1", C_SECOND), 1);
1829 couple_config, "tgt_comp", "tgt_grid_2", "multi_grid_field",
1830 yac_time_to_ISO("1", C_SECOND), 1);
1832 couple_config, "ICON-O", "grid2", "manual_field_coll_sel",
1833 yac_time_to_ISO("60", C_SECOND), 3);
1835 couple_config, "DUMMY", "grid4", "manual_field_coll_sel",
1836 yac_time_to_ISO("6", C_SECOND), 5);
1837
1838 return couple_config;
1839}
1840
1841static int utest_compare_string(char const * a, char const * b) {
1842
1843 int ret = (a == NULL) - (b == NULL);
1844 if (ret || (a == NULL)) return ret;
1845 return strcmp((void*)a,(void*)b);
1846}
unsigned grid_idx[3]
struct yac_interp_stack_config * yac_yaml_parse_interp_stack_config_string(char const *str_interp_stack_config, int parse_flags)
int const YAC_YAML_PARSER_JSON_AUTO
Definition config_yaml.c:69
char * yac_yaml_emit_coupling(struct yac_couple_config *couple_config, int emit_flags, int include_definitions)
int const YAC_YAML_EMITTER_DEFAULT
emit to YAML format
Definition config_yaml.c:66
void yac_yaml_read_coupling(struct yac_couple_config *couple_config, const char *yaml_filename, int parse_flags)
int const YAC_YAML_EMITTER_JSON
emit to JSON format
Definition config_yaml.c:67
int const YAC_YAML_PARSER_DEFAULT
default parse flags (YAML format)
Definition config_yaml.c:68
char const * yac_time_to_ISO(char const *time, enum yac_time_unit_type time_unit)
Definition event.c:329
int const YAC_YAML_PARSER_JSON_FORCE
assume JSON format
Definition config_yaml.c:70
void yac_couple_config_grid_set_metadata(struct yac_couple_config *couple_config, char const *grid_name, const char *metadata)
int yac_couple_config_field_is_valid(struct yac_couple_config *couple_config, size_t component_idx, size_t field_idx)
void yac_couple_config_get_field_source(struct yac_couple_config *couple_config, char const *tgt_component_name, char const *tgt_grid_name, char const *tgt_field_name, char const **src_component_name, char const **src_grid_name, char const **src_field_name)
char const * yac_couple_config_get_yaxt_exchanger_name(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
void yac_couple_config_sync(struct yac_couple_config *couple_config, MPI_Comm comm, char const *output_ref)
void yac_couple_config_field_enable_frac_mask(struct yac_couple_config *couple_config, char const *comp_name, char const *grid_name, char const *field_name, double frac_mask_fallback_value)
size_t yac_couple_config_get_num_fields(struct yac_couple_config *couple_config, size_t component_idx)
void yac_couple_config_get_field_grid_names(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx, char const **src_grid_name, char const **tgt_grid_name)
int yac_couple_config_contains_grid_name(struct yac_couple_config *couple_config, char const *grid_name)
const char * yac_couple_config_grid_get_output_filename(struct yac_couple_config *couple_config, const char *grid_name)
char * yac_couple_config_get_start_datetime(struct yac_couple_config *couple_config)
void yac_couple_config_set_datetime(struct yac_couple_config *couple_config, char const *start, char const *end)
void yac_couple_config_component_add_field(struct yac_couple_config *couple_config, const char *component_name, const char *grid_name, const char *name, char const *timestep, size_t collection_size)
char const * yac_couple_config_get_field_timestep(struct yac_couple_config *couple_config, char const *component_name, char const *grid_name, char const *field_name)
int yac_couple_config_mapping_on_source(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
int yac_couple_config_get_field_role(struct yac_couple_config *couple_config, char const *component_name, char const *grid_name, char const *field_name)
int yac_couple_config_component_name_is_valid(struct yac_couple_config *couple_config, char const *component_name)
struct yac_interpolation_gen_config * yac_couple_config_get_interpolation_gen_config(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
char const * yac_couple_config_get_coupling_period(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
void yac_couple_config_field_set_metadata(struct yac_couple_config *couple_config, const char *comp_name, const char *grid_name, const char *field_name, const char *metadata)
struct yac_interp_stack_config * yac_couple_config_get_interp_stack(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
enum yac_weight_file_on_existing yac_couple_config_get_weight_file_on_existing(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
char const * yac_couple_config_get_field_name(struct yac_couple_config *couple_config, size_t component_idx, size_t field_idx)
size_t yac_couple_config_get_field_idx(struct yac_couple_config *couple_config, size_t component_idx, size_t grid_idx, char const *field_name)
void yac_couple_config_component_set_metadata(struct yac_couple_config *couple_config, char const *comp_name, const char *metadata)
size_t yac_couple_config_get_field_collection_size(struct yac_couple_config *couple_config, char const *component_name, char const *grid_name, char const *field_name)
size_t yac_couple_config_get_num_couple_fields(struct yac_couple_config *couple_config, size_t couple_idx)
void yac_couple_config_get_src_mask_names(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx, char const *const **mask_names, size_t *num_mask_names)
int yac_couple_config_get_use_raw_exchange(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
size_t yac_couple_config_get_num_couples(struct yac_couple_config *couple_config)
int yac_couple_config_get_target_lag(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
double yac_couple_config_get_frac_mask_fallback_value(struct yac_couple_config *couple_config, char const *component_name, char const *grid_name, char const *field_name)
int yac_couple_config_get_source_lag(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
const char * yac_couple_config_field_get_metadata(struct yac_couple_config *couple_config, const char *comp_name, const char *grid_name, const char *field_name)
void yac_couple_config_get_couple_component_names(struct yac_couple_config *couple_config, size_t couple_idx, char const *couple_component_names[2])
const char * yac_couple_config_grid_get_metadata(struct yac_couple_config *couple_config, const char *grid_name)
const char * yac_couple_config_component_get_metadata(struct yac_couple_config *couple_config, const char *comp_name)
double yac_couple_config_get_scale_factor(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
size_t yac_couple_config_get_grid_idx(struct yac_couple_config *couple_config, char const *grid_name)
size_t yac_couple_config_get_component_idx(struct yac_couple_config *couple_config, char const *component_name)
char const * yac_couple_config_get_tgt_mask_name(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
void yac_couple_config_add_grid(struct yac_couple_config *couple_config, char const *name)
char const * yac_couple_config_get_grid_name(struct yac_couple_config *couple_config, size_t grid_idx)
double yac_couple_config_get_scale_summand(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
enum yac_reduction_type yac_couple_config_get_coupling_period_operation(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
struct yac_collection_selection const * yac_couple_config_get_collection_selection(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
int yac_couple_config_enforce_write_weight_file(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
void yac_couple_config_grid_set_output_filename(struct yac_couple_config *couple_config, char const *grid_name, const char *output_filename)
void yac_couple_config_get_field_names(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx, char const **src_field_name, const char **tgt_field_name)
struct yac_couple_config * yac_couple_config_new()
char const * yac_couple_config_get_weight_file_name(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
int yac_couple_config_get_missing_definition_is_fatal(struct yac_couple_config *couple_config)
void yac_couple_config_get_field_couple_component_names(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx, char const **src_component_name, char const **tgt_component_name)
char const * yac_couple_config_get_component_name(struct yac_couple_config *couple_config, size_t component_idx)
void yac_couple_config_set_missing_definition_is_fatal(struct yac_couple_config *couple_config, int missing_definition_is_fatal)
char const * yac_couple_config_get_source_timestep(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
void yac_couple_config_add_component(struct yac_couple_config *couple_config, char const *name)
size_t yac_couple_config_get_num_grids(struct yac_couple_config *couple_config)
char const * yac_couple_config_get_field_grid_name(struct yac_couple_config *couple_config, size_t component_idx, size_t field_idx)
void yac_couple_config_set_config_output_filename(struct yac_couple_config *couple_config, char const *filename, enum yac_text_filetype filetype, char const *ref, int include_definitions)
void yac_couple_config_def_couple(struct yac_couple_config *couple_config, 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_period, int time_reduction, struct yac_interp_stack_config *interp_stack, int src_lag, int tgt_lag, const char *weight_file_name, int weight_file_on_existing, int mapping_on_source, double scale_factor, double scale_summand, size_t num_src_mask_names, char const *const *src_mask_names, char const *tgt_mask_name, char const *yaxt_exchanger_name, struct yac_collection_selection const *collection_selection, int use_raw_exchange)
char * yac_couple_config_get_end_datetime(struct yac_couple_config *couple_config)
char const * yac_couple_config_get_target_timestep(struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
void yac_couple_config_delete(struct yac_couple_config *couple_config)
size_t yac_couple_config_get_num_components(struct yac_couple_config *couple_config)
yac_text_filetype
@ YAC_TEXT_FILETYPE_YAML
YAML format.
@ YAC_TEXT_FILETYPE_JSON
JSON format.
yac_reduction_type
@ TIME_NONE
@ TIME_ACCUMULATE
@ TIME_MAXIMUM
@ TIME_MINIMUM
@ TIME_AVERAGE
@ C_SECOND
#define YAC_RAD
void yac_collection_selection_delete(struct yac_collection_selection *collection_selection)
Delete a collection selection object.
int yac_collection_selection_compare(struct yac_collection_selection const *a, struct yac_collection_selection const *b)
Compare two collection selections.
struct yac_collection_selection * yac_collection_selection_new(size_t collection_size, size_t const *selection_indices)
Create a new collection selection.
#define YAC_INSTANCE_CONFIG_OUTPUT_REF_ENDDEF
Definition instance.h:15
#define YAC_INSTANCE_CONFIG_OUTPUT_REF_COMP
Definition instance.h:13
#define YAC_INSTANCE_CONFIG_OUTPUT_REF_SYNC
Definition instance.h:14
@ YAC_INTERP_AVG_DIST
@ YAC_INTERP_AVG_ARITHMETIC
@ YAC_INTERP_CONSERV_DESTAREA
@ YAC_INTERP_CONSERV_FRACAREA
#define YAC_INTERP_FILE_ON_SUCCESS_DEFAULT
@ YAC_INTERP_FILE_MISSING_CONT
continue on missing file
@ YAC_INTERP_FILE_SUCCESS_STOP
#define YAC_INTERP_FILE_ON_MISSING_FILE_DEFAULT
@ YAC_INTERP_NCC_DIST
distance weighted average of n source points
@ YAC_INTERP_NNN_GAUSS
distance with Gauss weights of n source points
@ YAC_INTERP_NNN_RBF
radial basis functions
@ YAC_INTERP_NNN_AVG
average of n source points
@ YAC_INTERP_NNN_DIST
distance weighted average of n source points
#define YAC_INTERP_RBF_MAX_SEARCH_DISTANCE_DEFAULT
#define YAC_INTERP_NNN_MAX_SEARCH_DISTANCE_DEFAULT
#define YAC_INTERP_NNN_GAUSS_SCALE_DEFAULT
#define YAC_INTERP_RBF_SCALE_DEFAULT
struct yac_spmap_overwrite_config * yac_spmap_overwrite_config_new(struct yac_point_selection const *src_point_selection, struct yac_interp_spmap_config const *config)
void yac_spmap_overwrite_configs_delete(struct yac_spmap_overwrite_config **overwrite_configs)
struct yac_interp_spmap_config * yac_interp_spmap_config_new(double spread_distance, double max_search_distance, enum yac_interp_spmap_weight_type weight_type, struct yac_spmap_scale_config const *scale_config)
void yac_interp_spmap_config_delete(struct yac_interp_spmap_config *config)
#define YAC_INTERP_SPMAP_MAX_SEARCH_DISTANCE_DEFAULT
@ YAC_INTERP_SPMAP_NONE
weights are not scaled
#define YAC_INTERP_SPMAP_SCALE_CONFIG_DEFAULT
#define YAC_INTERP_SPMAP_VARNAME_DEFAULT
#define YAC_INTERP_SPMAP_FILENAME_DEFAULT
#define YAC_INTERP_SPMAP_WEIGHTED_DEFAULT
#define YAC_INTERP_SPMAP_SPREAD_DISTANCE_DEFAULT
@ YAC_INTERP_SPMAP_DIST
#define YAC_INTERP_SPMAP_MIN_GLOBAL_ID_DEFAULT
int yac_interp_stack_config_compare(void const *a_, void const *b_)
void yac_interp_stack_config_add_fixed(struct yac_interp_stack_config *interp_stack_config, double value)
void yac_interp_stack_config_add_average(struct yac_interp_stack_config *interp_stack_config, enum yac_interp_avg_weight_type reduction_type, int partial_coverage)
void yac_interp_stack_config_delete(struct yac_interp_stack_config *interp_stack_config)
void yac_interp_stack_config_add_conservative(struct yac_interp_stack_config *interp_stack_config, int order, int enforced_conserv, int partial_coverage, enum yac_interp_method_conserv_normalisation normalisation)
struct yac_interp_stack_config * yac_interp_stack_config_new()
#define YAC_WEIGHT_FILE_ON_EXISTING_DEFAULT_VALUE
@ YAC_MAPPING_ON_TGT
weights will be applied at target processes
yac_weight_file_on_existing
@ YAC_WEIGHT_FILE_KEEP
keep existing weight file
@ YAC_WEIGHT_FILE_ERROR
error when weight file existis already
double const YAC_FRAC_MASK_NO_VALUE
void yac_interpolation_gen_config_set_reorder(struct yac_interpolation_gen_config *config, enum yac_interp_weights_reorder_type reorder)
Set the reordering strategy for interpolation weights.
void yac_interpolation_gen_config_set_collection_size(struct yac_interpolation_gen_config *config, size_t collection_size)
Set the number of contiguous fields (starting at "0") in the field collection.
int yac_interpolation_gen_config_compare(struct yac_interpolation_gen_config const *a, struct yac_interpolation_gen_config const *b)
Compare two interpolation configuration structures.
void yac_interpolation_gen_config_set_collection_selection(struct yac_interpolation_gen_config *config, struct yac_collection_selection const *collection_selection)
Set the collection selection of source field in the source field collection.
void yac_interpolation_gen_config_set_scaling_factor(struct yac_interpolation_gen_config *config, double scaling_factor)
Set the multiplicative scaling factor.
void yac_interpolation_gen_config_set_yaxt_exchanger_name(struct yac_interpolation_gen_config *config, char const *name)
Set the name of the Yaxt exchanger.
void yac_interpolation_gen_config_delete(struct yac_interpolation_gen_config *config)
Release a interpolation generation configuration structure allocated by yac_interpolation_gen_config_...
void yac_interpolation_gen_config_set_frac_mask_fallback_value(struct yac_interpolation_gen_config *config, double frac_mask_fallback_value)
Set the fractional mask fallback value.
struct yac_interpolation_gen_config * yac_interpolation_gen_config_new(void)
Allocate and initialise an interpolation generation configuration structure.
void yac_interpolation_gen_config_set_scaling_summand(struct yac_interpolation_gen_config *config, double scaling_summand)
Set the additive scaling summand.
Defines internal basic interpolation definitions.
#define YAC_FRAC_MASK_VALUE_IS_VALID(value)
Test whether a fractional mask value is valid.
int yac_file_exists(const char *filename)
Definition utils_core.c:12
struct yac_point_selection * yac_point_selection_bnd_circle_new(double center_lon, double center_lat, double inc_angle)
void yac_point_selection_delete(struct yac_point_selection *point_select)
#define xmalloc(size)
Definition ppm_xfuncs.h:66
Configuration structure for interpolation generation.
struct yac_collection_selection * collection_selection
struct yac_point_selection * src_point_selection
#define ADD_INTERP(NAME,...)
char const * ref_end_datetime
char const * ref_start_datetime
#define ADD_INTERP_NO_PARAM(NAME)
#define DEF_INTERP_STACK(IDX,...)
int collection_size
char const * weight_file_name
char const src_grid_name[]
char const tgt_grid_name[]
char const * config_filename
#define TEST_EXIT_CODE
Definition tests.h:14
#define PUT_ERR(string)
Definition tests.h:10
char const * name
Definition toy_scrip.c:114
int const YAC_EXCHANGE_TYPE_SOURCE
Definition yac.c:36
int const YAC_EXCHANGE_TYPE_NONE
Definition yac.c:35
int const YAC_EXCHANGE_TYPE_TARGET
Definition yac.c:37
void yac_cdef_calendar(int calendar)
Definition yac.c:746
int const YAC_PROLEPTIC_GREGORIAN
Definition yac.c:65
int const YAC_REDUCTION_TIME_NONE
Definition yac.c:49