YetAnotherCoupler 3.2.0_a
Loading...
Searching...
No Matches
yac.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#ifdef HAVE_CONFIG_H
6#include "config.h"
7#endif
8
9#include <stdlib.h>
10#include <stdio.h>
11#include <string.h>
12#include "yac_mpi_common.h"
13#include "ensure_array_size.h"
14#include "event.h"
15#include "yac.h"
16#include "mpi_handshake.h"
17#include "utils_mci.h"
18#include "version.h"
19#include "instance.h"
20#include "fields.h"
21#include "couple_config.h"
22#include "config_yaml.h"
23#include "geometry.h"
24#include "yac_mpi.h"
25#include "utils_common.h"
26
30
34
44
50
59
60int const YAC_CALENDAR_NOT_SET = CALENDAR_NOT_SET;
61int const YAC_PROLEPTIC_GREGORIAN = PROLEPTIC_GREGORIAN;
62int const YAC_YEAR_OF_365_DAYS = YEAR_OF_365_DAYS;
63int const YAC_YEAR_OF_360_DAYS = YEAR_OF_360_DAYS;
64
68
71
77
80
83
88
93
100
106
107static int default_instance_id = INT_MAX;
108
109static int yac_instance_count = 0;
110
111void ** pointer_lookup_table = NULL;
113
114struct yac_basic_grid ** grids = NULL;
115size_t num_grids = 0;
116
117static struct user_input_data_component ** components = NULL;
118static size_t num_components = 0;
119
121static size_t num_points = 0;
122
123static struct user_input_data_masks ** masks = NULL;
124static size_t num_masks = 0;
125
127static size_t num_interp_stack_configs = 0;
128
138
157
164static void * yac_unique_id_to_pointer(int id, char const * id_name) {
165
168 id >= 0,
169 "ERROR(yac_unique_id_to_pointer): invalid %s", id_name)
170 return pointer_lookup_table[id];
171}
172
181static int yac_lookup_pointer(void const * pointer) {
182
183 int ret = INT_MAX;
184 for (int i = 0; (ret == INT_MAX) && (i < pointer_lookup_table_size); ++i)
185 if (pointer_lookup_table[i] == pointer) ret = i;
186 return ret;
187}
188
202
203/* ---------------------------------------------------------------------- */
204
205static int yac_add_grid(
206 const char * grid_name, struct yac_basic_grid_data grid_data) {
207
208 for (size_t i = 0; i < num_grids; ++i)
210 strcmp(yac_basic_grid_get_name(grids[i]), grid_name),
211 "ERROR(yac_add_grid): multiple definitions of grid with identical name")
212
214 strlen(grid_name) <= YAC_MAX_CHARLEN,
215 "ERROR(yac_add_grid): grid name is too long (maximum is YAC_MAX_CHARLEN)")
216
217 struct yac_basic_grid * grid = yac_basic_grid_new(grid_name, grid_data);
218
219 grids = xrealloc(grids, (num_grids + 1) * sizeof(*grids));
220 grids[num_grids] = grid;
221 num_grids++;
222 return yac_pointer_to_unique_id(grid);
223}
224
225static void yac_free_grids() {
226
227 for (size_t i = 0; i < num_grids; ++i)
229 free(grids);
230 grids = NULL;
231 num_grids = 0;
232}
233
234/* ---------------------------------------------------------------------- */
235
236static void yac_free_points() {
237
238 for (size_t i = 0; i < num_points; ++i) free(points[i]);
239 free(points);
240 points = NULL;
241 num_points = 0;
242}
243
244/* ---------------------------------------------------------------------- */
245
246static void yac_free_masks() {
247
248 for (size_t i = 0; i < num_masks; ++i) free(masks[i]);
249 free(masks);
250 masks = NULL;
251 num_masks = 0;
252}
253
254/* ---------------------------------------------------------------------- */
255
256static void yac_free_components() {
257
258 for (size_t i = 0; i < num_components; ++i){
259 free(components[i]->name);
260 free(components[i]);
261 }
262 free(components);
263 components = NULL;
264 num_components = 0;
265}
266
267/* ---------------------------------------------------------------------- */
268
278
279/* ---------------------------------------------------------------------- */
280
281static void check_default_instance_id(char const * routine_name) {
282
284 default_instance_id != INT_MAX,
285 "ERROR(%s): no default yac instance is defined yet", routine_name)
286}
287
288/* ---------------------------------------------------------------------- */
289
290static void yac_check_version(MPI_Comm comm) {
291
292 int comm_rank;
293 yac_mpi_call(MPI_Comm_rank(comm, &comm_rank), comm);
294
295 char recv_version[64];
296
297 size_t yac_version_len = strlen(yac_version) + 1;
298
300 yac_version_len <= sizeof(recv_version),
301 "ERROR(yac_check_version): "
302 "version string \"%s\" is too long (has to be shorter than %zu)",
303 yac_version, sizeof(recv_version))
304
305 if (comm_rank == 0) strcpy(recv_version, yac_version);
306
308 MPI_Bcast(recv_version, (int)yac_version_len, MPI_CHAR, 0, comm), comm);
309
311 !strcmp(recv_version, yac_version),
312 "ERROR(yac_check_version): inconsistent yac versions between processes "
313 "(on local process \"%s\"; on root \"%s\")", yac_version, recv_version)
314}
315
316void check_mpi_initialised(char const * routine_name) {
317
320 "ERROR(%s): "
321 "MPI has not yet been initialised, but this call got a "
322 "communicator which is not allowed by the MPI standard "
323 "(MPI_COMM_WORLD is not to be used before the call to "
324 "MPI_Init or MPI_Init_thread)", routine_name);
325}
326
327void yac_cmpi_handshake(MPI_Comm comm, size_t n, char const** group_names,
328 MPI_Comm * group_comms) {
329 check_mpi_initialised("yac_cmpi_handshake");
330 yac_mpi_handshake(comm, n, group_names, group_comms);
331}
332
333void yac_cmpi_handshake_f2c(MPI_Fint comm, int n, char const** group_names,
334 MPI_Fint * group_comms) {
335 MPI_Comm comm_c = MPI_Comm_f2c(comm);
336 MPI_Comm * group_comms_c = xmalloc(n*sizeof(*group_comms_c));
337 yac_mpi_handshake(comm_c, n, group_names, group_comms_c);
338 for(int i = 0; i<n; ++i)
339 group_comms[i] = MPI_Comm_c2f(group_comms_c[i]);
340 free(group_comms_c);
341}
342
343static int yac_init(MPI_Comm comm) {
344
345 check_mpi_initialised("yac_init");
346 yac_yaxt_init(comm);
347 yac_check_version(comm);
348
349 int comm_rank, comm_size;
350 yac_mpi_call(MPI_Comm_rank(comm, &comm_rank), comm);
351 yac_mpi_call(MPI_Comm_size(comm, &comm_size), comm);
352
354 return
356 yac_instance_new(comm));
357}
358
360 check_default_instance_id("yac_cget_default_instance_id");
361 return default_instance_id;
362}
363
365 MPI_Comm comm, int * yac_instance_id) {
366
367 *yac_instance_id = yac_init(comm);
368}
369
371 MPI_Fint comm, int * yac_instance_id) {
372
373 yac_cinit_comm_instance(MPI_Comm_f2c(comm), yac_instance_id);
374}
375
376void yac_cinit_comm ( MPI_Comm comm ) {
377
379 default_instance_id == INT_MAX,
380 "ERROR(yac_cinit_comm): default yac instance already defined")
381
383}
384
385void yac_cinit_comm_f2c ( MPI_Fint comm_f ) {
386
387 yac_cinit_comm(MPI_Comm_f2c(comm_f));
388}
389
391 int * yac_instance_id) {
392
393 // we have to initalise MPI here in order to be able to use MPI_COMM_WORLD
394 yac_mpi_init();
395 MPI_Comm yac_comm;
396 const char* group_name = "yac";
397 yac_cmpi_handshake(MPI_COMM_WORLD, 1, &group_name, &yac_comm);
398 yac_cinit_comm_instance(yac_comm, yac_instance_id);
399 yac_mpi_call(MPI_Comm_free(&yac_comm), MPI_COMM_WORLD);
400}
401
402void yac_cinit ( void ) {
404 default_instance_id == INT_MAX,
405 "ERROR(yac_cinit_comm): default yac instance already defined")
406
408}
409
410/* ---------------------------------------------------------------------- */
411
412void yac_cinit_comm_dummy ( MPI_Comm comm ) {
413
414 check_mpi_initialised("yac_cinit_comm_dummy");
415
416 yac_yaxt_init(comm);
417 yac_check_version(comm);
418
420}
421
422void yac_cinit_comm_dummy_f2c ( MPI_Fint comm_f ) {
423
424 check_mpi_initialised("yac_cinit_comm_dummy_f2c");
425 yac_cinit_comm_dummy(MPI_Comm_f2c(comm_f));
426}
427
428void yac_cinit_dummy( void ) {
429
430 // we have to initalise MPI here in order to be able to use MPI_COMM_WORLD
431 yac_mpi_init();
432 yac_cmpi_handshake(MPI_COMM_WORLD, 0, NULL, NULL);
433}
434
435/* ---------------------------------------------------------------------- */
436
440
444
445/* ---------------------------------------------------------------------- */
446
447
448void yac_cread_config_yaml_instance( int yac_instance_id,
449 const char * yaml_filename){
450 struct yac_instance * instance
451 = yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
453 yac_instance_get_couple_config(instance), yaml_filename,
455}
456
457void yac_cread_config_yaml( const char * yaml_filename){
458 check_default_instance_id("read_config_yaml");
460}
461
462void yac_cread_config_json_instance( int yac_instance_id,
463 const char * yaml_filename){
464 struct yac_instance * instance
465 = yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
467 yac_instance_get_couple_config(instance), yaml_filename,
469}
470
471void yac_cread_config_json( const char * yaml_filename){
472 check_default_instance_id("read_config_yaml");
474}
475
476/* ---------------------------------------------------------------------- */
477
478static void yac_ccleanup_instance_(int yac_instance_id) {
479
480 struct yac_instance * instance
481 = yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
482
483 /* free memory */
484 yac_instance_delete(instance);
486 if(yac_instance_id == default_instance_id)
487 default_instance_id = INT_MAX;
488
489 // remove dangeling pointers from components
490 for(int i = 0; i<num_components;++i){
491 if(components[i]->instance == instance){
492 components[i]->instance = NULL;
493 }
494 }
495}
496
497void yac_ccleanup_instance (int yac_instance_id) {
498
499 yac_ccleanup_instance_(yac_instance_id);
500
501 /* cleanup mpi */
503}
504
506
507 check_default_instance_id("yac_ccleanup");
508
510}
511
512/* ---------------------------------------------------------------------- */
513
523
524void yac_cfinalize_instance(int yac_instance_id) {
525
526 yac_ccleanup_instance_(yac_instance_id);
527
528 /* cleanup close MPI */
529
530 if (yac_instance_count == 0) cleanup();
531}
532
534
535 if (default_instance_id != INT_MAX)
537
538 /* cleanup close MPI */
539
540 if (yac_instance_count == 0) cleanup();
541}
542
543/* ---------------------------------------------------------------------- */
544
546 int yac_instance_id, const char * start_datetime,
547 const char * end_datetime) {
548
550 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id"),
551 start_datetime, end_datetime);
552}
553
554void yac_cdef_datetime ( const char * start_datetime,
555 const char * end_datetime ) {
556
557 check_default_instance_id("yac_cdef_datetime");
559 default_instance_id, start_datetime, end_datetime);
560}
561
562void yac_cdef_calendar ( int calendar ) {
563
565 (calendar == YAC_PROLEPTIC_GREGORIAN) ||
566 (calendar == YAC_YEAR_OF_360_DAYS) ||
567 (calendar == YAC_YEAR_OF_365_DAYS),
568 "ERROR(yac_cdef_calendar): invalid calendar type")
569
570 calendarType curr_calendar = getCalendarType();
572 (curr_calendar == CALENDAR_NOT_SET) ||
573 (curr_calendar == (calendarType)calendar),
574 "ERROR(yac_cdef_calendar): inconsistent calendar definition")
575
576 initCalendar((calendarType)calendar);
577}
578
579/* ---------------------------------------------------------------------- */
580
581char * yac_cget_start_datetime_instance(int yac_instance_id) {
582
583 return
585 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id"));
586}
587
588char * yac_cget_start_datetime ( void ) {
589
590 check_default_instance_id("yac_cget_start_datetime");
592}
593
594/* ---------------------------------------------------------------------- */
595
596char * yac_cget_end_datetime_instance(int yac_instance_id) {
597
598 return
600 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id"));
601}
602
603char * yac_cget_end_datetime ( void ) {
604
605 check_default_instance_id("yac_cget_end_datetime");
607}
608
609/* ---------------------------------------------------------------------- */
610
611/* The YAC version number is provided in version.h
612 */
613
614char * yac_cget_version ( void ) {
615 return yac_version;
616}
617
618/* ---------------------------------------------------------------------- */
619
621 int comp_id, char const * routine) {
622
623 struct user_input_data_component * comp_info =
624 yac_unique_id_to_pointer(comp_id, "comp_id");
625
627 comp_info->instance != NULL,
628 "ERROR(%s): instance of component \"%s\" is already finalized",
629 routine, comp_info->name);
630
631 return comp_info;
632}
633
634/* ---------------------------------------------------------------------- */
635
636/* c interface routine */
637
638void yac_cget_comp_comm ( int comp_id, MPI_Comm *comp_comm ) {
639
640 struct user_input_data_component * comp_info =
641 get_user_input_data_component(comp_id, "yac_cget_comp_comm");
642
643 *comp_comm =
645 comp_info->instance, (char const **)&(comp_info->name), 1);
646}
647
648/* internal routine to serve the Fortran interface */
649
650void yac_get_comp_comm_f2c ( int comp_id, MPI_Fint *comp_comm_f ) {
651
652 MPI_Comm comp_comm;
653 yac_cget_comp_comm(comp_id, &comp_comm);
654
655 *comp_comm_f = MPI_Comm_c2f(comp_comm);
656}
657
658/* internal routine to serve the Python interface */
659
660void yac_cget_comp_size_c2py(int comp_id, int* size){
661 struct user_input_data_component * comp_info =
662 get_user_input_data_component(comp_id, "yac_cget_comp_comm");
663
664 *size = yac_instance_get_comp_size(comp_info->instance, comp_info->name);
665}
666
667void yac_cget_comp_rank_c2py(int comp_id, int* rank){
668 struct user_input_data_component * comp_info =
669 get_user_input_data_component(comp_id, "yac_cget_comp_comm");
670
671 *rank = yac_instance_get_comp_rank(comp_info->instance, comp_info->name);
672}
673
674/* ---------------------------------------------------------------------- */
675
676/* c interface routine */
677
679 int yac_instance_id,
680 char const ** comp_names, int num_comps, MPI_Comm * comps_comm) {
681
682 *comps_comm =
684 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id"),
685 comp_names, (size_t)num_comps);
686}
687
689 const char ** comp_names, int num_comps, MPI_Comm * comps_comm) {
690
691 check_default_instance_id("yac_cget_comps_comm");
693 default_instance_id, comp_names, num_comps, comps_comm);
694}
695
696/* internal routine to serve the Fortran interface */
697
699 int yac_instance_id,
700 char const ** comp_names, int num_comps, MPI_Fint * comps_comm_f) {
701
702 MPI_Comm comps_comm;
704 yac_instance_id, comp_names, num_comps, &comps_comm);
705 *comps_comm_f = MPI_Comm_c2f(comps_comm);
706}
707
709 char const ** comp_names, int num_comps, MPI_Fint *comps_comm_f) {
710
711 MPI_Comm comps_comm;
712 yac_cget_comps_comm(comp_names, num_comps, &comps_comm);
713 *comps_comm_f = MPI_Comm_c2f(comps_comm);
714}
715
716/* ---------------------------------------------------------------------- */
717
719 int yac_instance_id, char const * name, int * comp_id){
720
721 struct yac_instance * instance =
722 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
723
726 "ERROR(yac_cpredef_comp_instance): components have already been defined");
727
729 (name != NULL) && (*name != '\0'),
730 "ERROR(yac_cpredef_comp_instance): missing component name");
731
732 for (size_t i = 0; i < num_components; ++i) {
734 (components[i]->instance != instance) ||
735 strcmp(components[i]->name, name),
736 "ERROR(yac_cpredef_comp_instance): "
737 "component \"%s\" is already defined", name);
738 }
739
740 components =
741 xrealloc(
742 components, (num_components + 1) * sizeof(*components));
743
746 components[num_components]->name = strdup(name);
749}
750
751void yac_cpredef_comp(char const * name, int * comp_id){
752 check_default_instance_id("yac_cpredef_comp");
754}
755
757 int yac_instance_id, char const ** comp_names, int num_comps,
758 int * comp_ids) {
759
760 struct yac_instance * instance =
761 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
762
763 for(int i = 0; i<num_comps; ++i)
764 yac_cpredef_comp_instance(yac_instance_id, comp_names[i], comp_ids + i);
765
766 // count predefined components and set their index
767 size_t comp_counter = 0;
768 char const ** all_comp_names = xmalloc(num_components * sizeof(*all_comp_names));
769 for(int i = 0; i<num_components; ++i){
770 if(components[i]->instance == instance){
771 all_comp_names[comp_counter] = components[i]->name;
772 comp_counter++;
773 }
774 }
775
776 yac_instance_def_components(instance, all_comp_names, comp_counter);
777
778 free(all_comp_names);
779}
780
782 char const ** comp_names, int num_comps, int * comp_ids ) {
783
784 check_default_instance_id("yac_cdef_comps");
786 default_instance_id, comp_names, num_comps, comp_ids);
787}
788
790 int yac_instance_id, char const * comp_name, int * comp_id ) {
791
792 yac_cdef_comps_instance(yac_instance_id, &comp_name, 1, comp_id);
793}
794
795void yac_cdef_comp ( char const * comp_name, int * comp_id ) {
796
797 yac_cdef_comps(&comp_name, 1, comp_id);
798}
799
800/* ---------------------------------------------------------------------- */
801
803 struct yac_basic_grid * grid, enum yac_location location,
804 yac_coordinate_pointer coordinates) {
805
806 struct user_input_data_points * curr_points = xmalloc(1 * sizeof(*curr_points));
807 curr_points->default_mask_id = INT_MAX;
808 curr_points->grid = grid;
809 curr_points->location = location;
810 curr_points->coordinates_idx =
812
813 points = xrealloc(points, (num_points + 1) * sizeof(*points));
815 num_points++;
816
818}
819
820/* ---------------------------------------------------------------------- */
821
823 double const * x_vertices, size_t count, char const * routine_name) {
824
825 for (size_t i = 0; i < count; ++i)
827 (x_vertices[i] >= -720.0) && (x_vertices[i] <= 720.0),
828 "ERROR(%s): x_vertices[%zu] = %lf outside of valid range [-720;720]",
829 routine_name, i, x_vertices[i]);
830}
831
833 double const * y_vertices, size_t count, char const * routine_name) {
834
835 for (size_t i = 0; i < count; ++i)
837 (y_vertices[i] >= -90.00001) && (y_vertices[i] <= 90.00001),
838 "ERROR(%s): y_vertices[%zu] = %lf "
839 "outside of valid range [90.00001;90.00001]",
840 routine_name, i, y_vertices[i]);
841}
842
843/* ---------------------------------------------------------------------- */
844
845void yac_cdef_points_reg2d ( int const grid_id,
846 int const *nbr_points,
847 int const located,
848 double const *x_points,
849 double const *y_points,
850 int *point_id ) {
851
853 struct yac_basic_grid * grid = yac_unique_id_to_pointer(grid_id, "grid_id");
854
856 location != YAC_LOC_EDGE,
857 "ERROR(yac_cdef_points_reg2d): "
858 "edge-location is not supported, use yac_cdef_points_unstruct instead.");
859
860 size_t num_points = yac_basic_grid_get_data_size(grid, location);
862 ((size_t)nbr_points[0] * (size_t)nbr_points[1]) == num_points,
863 "ERROR(yac_cdef_points_reg2d): nbr_points does not match with grid")
864
866 x_points, (size_t)(nbr_points[0]), "yac_cdef_points_reg2d");
868 y_points, (size_t)(nbr_points[1]), "yac_cdef_points_reg2d");
869
870 yac_coordinate_pointer coordinates =
871 xmalloc(num_points * sizeof(*coordinates));
872 for (int i = 0, k = 0; i < nbr_points[1]; ++i)
873 for (int j = 0; j < nbr_points[0]; ++j, ++k)
874 LLtoXYZ(x_points[j], y_points[i], coordinates[k]);
875
876 *point_id = user_input_data_add_points(grid, location, coordinates);
877}
878
879/* ---------------------------------------------------------------------- */
880
881void yac_cdef_points_curve2d ( int const grid_id,
882 int const *nbr_points,
883 int const located,
884 double const *x_points,
885 double const *y_points,
886 int *point_id ) {
887
888 enum yac_location location = yac_get_location(located);
889 struct yac_basic_grid * grid = yac_unique_id_to_pointer(grid_id, "grid_id");
890
892 location != YAC_LOC_EDGE,
893 "ERROR(yac_cdef_points_curve2d): "
894 "edge-location is not supported, use yac_cdef_points_unstruct instead.");
895
896 size_t num_points = yac_basic_grid_get_data_size(grid, location);
898 ((size_t)nbr_points[0] * (size_t)nbr_points[1]) == num_points,
899 "ERROR(yac_cdef_points_curve2d): nbr_points does not match with grid"
900 " (%zu*%zu != %zu)",
901 (size_t)nbr_points[0], (size_t)nbr_points[1], num_points)
902
904 x_points, (size_t)(nbr_points[0]), "yac_cdef_points_curve2d");
906 y_points, (size_t)(nbr_points[1]), "yac_cdef_points_curve2d");
907
908 yac_coordinate_pointer coordinates =
909 xmalloc(num_points * sizeof(*coordinates));
910 for (int i = 0, k = 0; i < nbr_points[1]; ++i)
911 for (int j = 0; j < nbr_points[0]; ++j, ++k)
912 LLtoXYZ(x_points[k], y_points[k], coordinates[k]);
913
914 *point_id = user_input_data_add_points(grid, location, coordinates);
915}
916
917/* ---------------------------------------------------------------------- */
918
919void yac_cdef_points_unstruct ( int const grid_id,
920 int const nbr_points,
921 int const located,
922 double const *x_points,
923 double const *y_points,
924 int *point_id ) {
925
926 enum yac_location location = yac_get_location(located);
927 struct yac_basic_grid * grid = yac_unique_id_to_pointer(grid_id, "grid_id");
928
930 (size_t)nbr_points == yac_basic_grid_get_data_size(grid, location),
931 "ERROR(yac_cdef_points_unstruct): nbr_points does not match with grid")
932
933 check_x_vertices(x_points, (size_t)nbr_points, "yac_cdef_points_unstruct");
934 check_y_vertices(y_points, (size_t)nbr_points, "yac_cdef_points_unstruct");
935
936 yac_coordinate_pointer coordinates =
937 xmalloc((size_t)nbr_points * sizeof(*coordinates));
938 for (int i = 0; i < nbr_points; ++i)
939 LLtoXYZ(x_points[i], y_points[i], coordinates[i]);
940
941 *point_id = user_input_data_add_points(grid, location, coordinates);
942}
943
944/* ---------------------------------------------------------------------- */
945
947 struct yac_basic_grid * grid, enum yac_location location,
948 int const * is_valid, size_t nbr_points, char const * name) {
949
950 struct user_input_data_masks * curr_mask = xmalloc(1 * sizeof(*curr_mask));
951 curr_mask->grid = grid;
952 curr_mask->location = location;
953 curr_mask->masks_idx =
954 yac_basic_grid_add_mask(grid, location, is_valid, nbr_points, name);
955
956 masks = xrealloc(masks, (num_masks + 1) * sizeof(*masks));
957 masks[num_masks] = curr_mask;
958 num_masks++;
959
960 return yac_pointer_to_unique_id(curr_mask);
961}
962
963/* ---------------------------------------------------------------------- */
964
965void yac_cdef_mask_named ( int const grid_id,
966 int const nbr_points,
967 int const located,
968 int const * is_valid,
969 char const * name,
970 int *mask_id ) {
971
972 enum yac_location location = yac_get_location(located);
973 struct yac_basic_grid * grid = yac_unique_id_to_pointer(grid_id, "grid_id");
974
976 (size_t)nbr_points == yac_basic_grid_get_data_size(grid, location),
977 "ERROR(yac_cdef_mask_named): nbr_points does not match with grid")
978
979 *mask_id =
981 grid, location, is_valid, (size_t)nbr_points, name);
982}
983
984void yac_cdef_mask ( int const grid_id,
985 int const nbr_points,
986 int const located,
987 int const * is_valid,
988 int *mask_id ) {
989
990 yac_cdef_mask_named(grid_id, nbr_points, located, is_valid, NULL, mask_id);
991}
992
993void yac_cset_mask ( int const * is_valid, int points_id ) {
994
996 yac_unique_id_to_pointer(points_id, "points_id");
997
1000 "ERROR(yac_cset_mask): default mask has already been set before")
1001
1002 struct yac_basic_grid * grid = points->grid;
1003 enum yac_location location = points->location;
1004 size_t nbr_points = yac_basic_grid_get_data_size(grid, location);
1005
1007 user_input_data_add_mask(grid, location, is_valid, nbr_points, NULL);
1008}
1009
1010/* ---------------------------------------------------------------------- */
1011
1012void yac_cdef_field_mask ( char const * name,
1013 int const comp_id,
1014 int const * point_ids,
1015 int const * mask_ids,
1016 int const num_pointsets,
1017 int collection_size,
1018 const char* timestep,
1019 int time_unit,
1020 int * field_id ) {
1021
1022 YAC_ASSERT(
1023 num_pointsets >= 1,
1024 "ERROR(yac_cdef_field_mask): invalid number of pointsets")
1025
1026 YAC_ASSERT(
1027 point_ids != NULL,"ERROR(yac_cdef_field_mask): no point_ids provided")
1028
1029 struct yac_basic_grid * grid =
1030 ((struct user_input_data_points *)
1031 yac_unique_id_to_pointer(point_ids[0], "point_ids[0]"))->grid;
1032
1034 struct yac_interp_field * interp_fields =
1035 (num_pointsets == 1)?
1037 xmalloc((size_t)num_pointsets * sizeof(*interp_fields));
1038
1039 for (int i = 0; i < num_pointsets; ++i) {
1040
1042 yac_unique_id_to_pointer(point_ids[i], "point_ids[i]");
1043
1044 YAC_ASSERT(
1045 grid == points->grid,
1046 "ERROR(yac_cdef_field_mask): grid of point_ids do not match")
1047
1048 size_t masks_idx;
1049 if (mask_ids[i] != INT_MAX) {
1050
1051 struct user_input_data_masks * mask =
1052 yac_unique_id_to_pointer(mask_ids[i], "mask_ids[i]");
1053
1054 YAC_ASSERT(
1055 mask->grid == points->grid,
1056 "ERROR(yac_cdef_field_mask): "
1057 "grids of mask and points do not match")
1058 YAC_ASSERT(
1059 mask->location == points->location,
1060 "ERROR(yac_cdef_field_mask): "
1061 "location of mask and points do not match")
1062 masks_idx = mask->masks_idx;
1063 } else {
1064 masks_idx = SIZE_MAX;
1065 }
1066
1067 interp_fields[i].location = points->location;
1068 interp_fields[i].coordinates_idx = points->coordinates_idx;
1069 interp_fields[i].masks_idx = masks_idx;
1070 }
1071
1072 struct user_input_data_component * comp_info =
1073 get_user_input_data_component(comp_id, "yac_cdef_field_mask");
1074
1075 *field_id =
1078 comp_info->instance, name, comp_info->name,
1079 grid, interp_fields, num_pointsets, collection_size,
1080 yac_time_to_ISO(timestep, (enum yac_time_unit_type)time_unit)));
1081
1082 if (num_pointsets > 1) free(interp_fields);
1083}
1084
1085void yac_cdef_field ( char const * name,
1086 int const comp_id,
1087 int const * point_ids,
1088 int const num_pointsets,
1089 int collection_size,
1090 const char* timestep,
1091 int time_unit,
1092 int * field_id ) {
1093
1094 YAC_ASSERT(
1095 num_pointsets >= 1,
1096 "ERROR(yac_cdef_field): invalid number of pointsets")
1097
1098 YAC_ASSERT(
1099 point_ids != NULL, "ERROR(yac_cdef_field): no point_ids provided")
1100
1101 int * mask_ids = xmalloc((size_t)num_pointsets * sizeof(*mask_ids));
1102
1103 for (int i = 0; i < num_pointsets; ++i)
1104 mask_ids[i] =
1105 ((struct user_input_data_points *)
1106 yac_unique_id_to_pointer(point_ids[i], "point_ids[i]"))->
1107 default_mask_id;
1108
1110 name, comp_id, point_ids, mask_ids, num_pointsets,
1111 collection_size, timestep, time_unit, field_id);
1112
1113 free(mask_ids);
1114}
1115
1117 int yac_instance_id, const char* comp_name, const char* grid_name,
1118 const char* field_name, double frac_mask_fallback_value) {
1119 struct yac_instance * instance =
1120 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
1121 struct yac_couple_config * couple_config =
1124 couple_config, comp_name, grid_name, field_name,
1125 frac_mask_fallback_value);
1126}
1127
1129 const char* comp_name, const char* grid_name, const char* field_name,
1130 double frac_mask_fallback_value) {
1131 check_default_instance_id("yac_cenable_field_frac_mask");
1133 default_instance_id, comp_name, grid_name, field_name,
1134 frac_mask_fallback_value);
1135}
1136
1138 const char* comp_name, const char* metadata) {
1139 struct yac_instance * instance =
1140 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
1141 struct yac_couple_config * couple_config = yac_instance_get_couple_config(instance);
1142 yac_couple_config_component_set_metadata(couple_config, comp_name, metadata);
1143}
1144
1145void yac_cdef_component_metadata(const char* comp_name, const char* metadata) {
1146 check_default_instance_id("yac_cdef_component_metadata");
1148}
1149
1150void yac_cdef_grid_metadata_instance(int yac_instance_id, const char* grid_name,
1151 const char* metadata) {
1152 struct yac_instance * instance =
1153 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
1154 struct yac_couple_config * couple_config
1156 yac_couple_config_grid_set_metadata(couple_config, grid_name, metadata);
1157}
1158
1159void yac_cdef_grid_metadata(const char* grid_name, const char* metadata) {
1160 check_default_instance_id("yac_cdef_grid_metadata");
1162}
1163
1164void yac_cdef_field_metadata_instance(int yac_instance_id, const char* comp_name,
1165 const char* grid_name, const char* field_name, const char* metadata) {
1166 struct yac_instance * instance =
1167 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
1168 struct yac_couple_config * couple_config
1170 yac_couple_config_field_set_metadata(couple_config, comp_name, grid_name, field_name, metadata);
1171}
1172
1173void yac_cdef_field_metadata(const char* comp_name, const char* grid_name,
1174 const char* field_name, const char* metadata) {
1175 check_default_instance_id("yac_cdef_field_metadata");
1177 field_name, metadata);
1178}
1179
1180const char* yac_cget_component_metadata_instance(int yac_instance_id,
1181 const char* comp_name) {
1182 struct yac_instance * instance =
1183 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
1184 struct yac_couple_config * couple_config = yac_instance_get_couple_config(instance);
1185 return yac_couple_config_component_get_metadata(couple_config, comp_name);
1186}
1187
1188const char* yac_cget_component_metadata(const char* comp_name) {
1189 check_default_instance_id("yac_cget_component_metadata");
1191}
1192
1193const char* yac_cget_grid_metadata_instance(int yac_instance_id,
1194 const char* grid_name) {
1195 struct yac_instance * instance =
1196 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
1197 struct yac_couple_config * couple_config = yac_instance_get_couple_config(instance);
1198 return yac_couple_config_grid_get_metadata(couple_config, grid_name);
1199}
1200
1201const char* yac_cget_grid_metadata(const char* grid_name) {
1202 check_default_instance_id("yac_cget_grid_metadata");
1204}
1205
1206const char* yac_cget_field_metadata_instance(int yac_instance_id,
1207 const char* comp_name, const char* grid_name, const char* field_name) {
1208 struct yac_instance * instance =
1209 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
1210 struct yac_couple_config * couple_config = yac_instance_get_couple_config(instance);
1211 return yac_couple_config_field_get_metadata(couple_config, comp_name, grid_name,
1212 field_name);
1213}
1214
1215const char* yac_cget_field_metadata(const char* comp_name, const char* grid_name,
1216 const char* field_name) {
1217 check_default_instance_id("yac_cget_field_metadata");
1219 grid_name, field_name);
1220}
1221
1223 struct yac_ext_couple_config * ext_couple_config) {
1224 ext_couple_config->weight_file = NULL;
1225 ext_couple_config->mapping_side = 1;
1226 ext_couple_config->scale_factor = 1.0;
1227 ext_couple_config->scale_summand = 0.0;
1228 ext_couple_config->num_src_mask_names = 0;
1229 ext_couple_config->src_mask_names = NULL;
1230 ext_couple_config->tgt_mask_name = NULL;
1231}
1232
1233void yac_cget_ext_couple_config(int * ext_couple_config_id) {
1234
1235 struct yac_ext_couple_config * ext_couple_config =
1236 xmalloc(1 * sizeof(*ext_couple_config));
1237 init_ext_couple_config(ext_couple_config);
1238 *ext_couple_config_id = yac_pointer_to_unique_id(ext_couple_config);
1239}
1240
1241void yac_cfree_ext_couple_config(int ext_couple_config_id) {
1242 struct yac_ext_couple_config * ext_couple_config =
1243 yac_unique_id_to_pointer(ext_couple_config_id, "ext_couple_config_id");
1244 free(ext_couple_config->weight_file);
1245 for (size_t i = 0; i < ext_couple_config->num_src_mask_names; ++i)
1246 free(ext_couple_config->src_mask_names[i]);
1247 free(ext_couple_config->src_mask_names);
1248 free(ext_couple_config->tgt_mask_name);
1249 free(ext_couple_config);
1250}
1251
1253 struct yac_ext_couple_config * ext_couple_config,
1254 char const * weight_file) {
1255 free(ext_couple_config->weight_file);
1256 ext_couple_config->weight_file =
1257 (weight_file != NULL)?strdup(weight_file):NULL;
1258}
1259
1260void yac_cset_ext_couple_config_weight_file(int ext_couple_config_id,
1261 char const * weight_file) {
1263 yac_unique_id_to_pointer(ext_couple_config_id, "ext_couple_config_id"),
1264 weight_file);
1265}
1266
1267void yac_cget_ext_couple_config_weight_file(int ext_couple_config_id,
1268 char const ** weight_file) {
1269 struct yac_ext_couple_config * ext_couple_config =
1270 yac_unique_id_to_pointer(ext_couple_config_id, "ext_couple_config_id");
1271 *weight_file = ext_couple_config->weight_file;
1272}
1273
1275 struct yac_ext_couple_config * ext_couple_config,
1276 int mapping_side) {
1278 (mapping_side == 0) ||
1279 (mapping_side == 1),
1280 "ERROR(yac_cset_ext_couple_config_mapping_side_): "
1281 "\"%d\" is not a valid mapping side (has to be 0 or 1)",
1282 mapping_side);
1283 ext_couple_config->mapping_side = mapping_side;
1284}
1285
1286void yac_cset_ext_couple_config_mapping_side(int ext_couple_config_id,
1287 int mapping_side) {
1289 yac_unique_id_to_pointer(ext_couple_config_id, "ext_couple_config_id"),
1290 mapping_side);
1291}
1292
1293void yac_cget_ext_couple_config_mapping_side(int ext_couple_config_id,
1294 int * mapping_side) {
1295 struct yac_ext_couple_config * ext_couple_config =
1296 yac_unique_id_to_pointer(ext_couple_config_id, "ext_couple_config_id");
1297 *mapping_side = ext_couple_config->mapping_side;
1298}
1299
1301 struct yac_ext_couple_config * ext_couple_config,
1302 double scale_factor) {
1303 YAC_ASSERT_F(isnormal(scale_factor),
1304 "ERROR(yac_cset_ext_couple_config_scale_factor_): "
1305 "\"%lf\" is not a valid scale factor", scale_factor);
1306 ext_couple_config->scale_factor = scale_factor;
1307}
1308
1309void yac_cset_ext_couple_config_scale_factor(int ext_couple_config_id,
1310 double scale_factor) {
1312 yac_unique_id_to_pointer(ext_couple_config_id, "ext_couple_config_id"),
1313 scale_factor);
1314}
1315
1316void yac_cget_ext_couple_config_scale_factor(int ext_couple_config_id,
1317 double * scale_factor) {
1318 struct yac_ext_couple_config * ext_couple_config =
1319 yac_unique_id_to_pointer(ext_couple_config_id, "ext_couple_config_id");
1320 *scale_factor = ext_couple_config->scale_factor;
1321}
1322
1324 struct yac_ext_couple_config * ext_couple_config,
1325 double scale_summand) {
1326 YAC_ASSERT_F((scale_summand == 0.0) || isnormal(scale_summand),
1327 "ERROR(yac_cset_ext_couple_config_scale_summand_): "
1328 "\"%lf\" is not a valid scale summand", scale_summand);
1329 ext_couple_config->scale_summand = scale_summand;
1330}
1331
1332void yac_cset_ext_couple_config_scale_summand(int ext_couple_config_id,
1333 double scale_summand) {
1335 yac_unique_id_to_pointer(ext_couple_config_id, "ext_couple_config_id"),
1337}
1338
1339void yac_cget_ext_couple_config_scale_summand(int ext_couple_config_id,
1340 double * scale_summand) {
1341 struct yac_ext_couple_config * ext_couple_config =
1342 yac_unique_id_to_pointer(ext_couple_config_id, "ext_couple_config_id");
1343 *scale_summand = ext_couple_config->scale_summand;
1344}
1345
1347 struct yac_ext_couple_config * ext_couple_config,
1348 size_t num_src_mask_names, char const * const * src_mask_names) {
1349 if (ext_couple_config->num_src_mask_names > 0)
1350 for (size_t i = 0; i < ext_couple_config->num_src_mask_names; ++i)
1351 free(ext_couple_config->src_mask_names[i]);
1352 free(ext_couple_config->src_mask_names);
1353 ext_couple_config->num_src_mask_names = num_src_mask_names;
1354 if (num_src_mask_names > 0) {
1355 ext_couple_config->src_mask_names =
1357 for (size_t i = 0; i < num_src_mask_names; ++i)
1358 ext_couple_config->src_mask_names[i] = strdup(src_mask_names[i]);
1359 } else ext_couple_config->src_mask_names = NULL;
1360}
1361
1363 int ext_couple_config_id, size_t num_src_mask_names,
1364 char const * const * src_mask_names) {
1366 yac_unique_id_to_pointer(ext_couple_config_id, "ext_couple_config_id"),
1368}
1369
1371 int ext_couple_config_id, size_t * num_src_mask_names,
1372 char const * const ** src_mask_names) {
1373 struct yac_ext_couple_config * ext_couple_config =
1374 yac_unique_id_to_pointer(ext_couple_config_id, "ext_couple_config_id");
1375 *num_src_mask_names = ext_couple_config->num_src_mask_names;
1376 *src_mask_names = (char const * const *)ext_couple_config->src_mask_names;
1377}
1378
1380 struct yac_ext_couple_config * ext_couple_config,
1381 char const * tgt_mask_name) {
1382 free(ext_couple_config->tgt_mask_name);
1383 ext_couple_config->tgt_mask_name =
1384 (tgt_mask_name != NULL)?strdup(tgt_mask_name):NULL;
1385}
1386
1388 int ext_couple_config_id, char const * tgt_mask_name) {
1390 yac_unique_id_to_pointer(ext_couple_config_id, "ext_couple_config_id"),
1392}
1393
1395 int ext_couple_config_id, char const ** tgt_mask_name) {
1396 struct yac_ext_couple_config * ext_couple_config =
1397 yac_unique_id_to_pointer(ext_couple_config_id, "ext_couple_config_id");
1398 *tgt_mask_name = ext_couple_config->tgt_mask_name;
1399}
1400
1402 int yac_instance_id,
1403 char const * src_comp_name, char const * src_grid_name, char const * src_field_name,
1404 char const * tgt_comp_name, char const * tgt_grid_name, char const * tgt_field_name,
1405 char const * coupling_timestep, int time_unit, int time_reduction,
1406 int interp_stack_config_id, int src_lag, int tgt_lag,
1407 struct yac_ext_couple_config * ext_couple_config) {
1408 struct yac_instance * instance =
1409 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
1410 struct yac_interp_stack_config * interp_stack_config =
1412 interp_stack_config_id, "interp_stack_config_id");
1413 char const * coupling_timestep_iso8601 =
1414 yac_time_to_ISO(coupling_timestep, (enum yac_time_unit_type)time_unit);
1415 yac_instance_def_couple(instance,
1416 src_comp_name, src_grid_name, src_field_name,
1417 tgt_comp_name, tgt_grid_name, tgt_field_name,
1418 coupling_timestep_iso8601, time_reduction,
1419 interp_stack_config, src_lag, tgt_lag,
1420 ext_couple_config->weight_file,
1421 ext_couple_config->mapping_side,
1422 ext_couple_config->scale_factor,
1423 ext_couple_config->scale_summand,
1424 ext_couple_config->num_src_mask_names,
1425 (char const * const *)ext_couple_config->src_mask_names,
1426 ext_couple_config->tgt_mask_name);
1427}
1428
1430 int yac_instance_id,
1431 char const * src_comp_name, char const * src_grid_name, char const * src_field_name,
1432 char const * tgt_comp_name, char const * tgt_grid_name, char const * tgt_field_name,
1433 char const * coupling_timestep, int time_unit, int time_reduction,
1434 int interp_stack_config_id, int src_lag, int tgt_lag,
1435 int ext_couple_config_id) {
1436
1438 yac_instance_id, src_comp_name, src_grid_name, src_field_name,
1439 tgt_comp_name, tgt_grid_name, tgt_field_name, coupling_timestep,
1440 time_unit, time_reduction, interp_stack_config_id, src_lag, tgt_lag,
1441 yac_unique_id_to_pointer(ext_couple_config_id, "ext_couple_config_id"));
1442}
1443
1445 char const * src_comp_name, char const * src_grid_name, char const * src_field_name,
1446 char const * tgt_comp_name, char const * tgt_grid_name, char const * tgt_field_name,
1447 char const * coupling_timestep, int time_unit, int time_reduction,
1448 int interp_stack_config_id, int src_lag, int tgt_lag,
1449 int ext_couple_config_id) {
1450
1451 check_default_instance_id("yac_cdef_couple_custom");
1453 src_comp_name, src_grid_name, src_field_name,
1454 tgt_comp_name, tgt_grid_name, tgt_field_name, coupling_timestep,
1455 time_unit, time_reduction, interp_stack_config_id, src_lag, tgt_lag,
1456 yac_unique_id_to_pointer(ext_couple_config_id, "ext_couple_config_id"));
1457}
1458
1460 int yac_instance_id,
1461 char const * src_comp_name, char const * src_grid_name, char const * src_field_name,
1462 char const * tgt_comp_name, char const * tgt_grid_name, char const * tgt_field_name,
1463 char const * coupling_timestep, int time_unit, int time_reduction,
1464 int interp_stack_config_id, int src_lag, int tgt_lag) {
1465
1466 struct yac_ext_couple_config ext_couple_config;
1467 init_ext_couple_config(&ext_couple_config);
1468
1470 yac_instance_id, src_comp_name, src_grid_name, src_field_name,
1471 tgt_comp_name, tgt_grid_name, tgt_field_name, coupling_timestep,
1472 time_unit, time_reduction, interp_stack_config_id, src_lag, tgt_lag,
1473 &ext_couple_config);
1474}
1475
1477 char const * src_comp_name, char const * src_grid_name, char const * src_field_name,
1478 char const * tgt_comp_name, char const * tgt_grid_name, char const * tgt_field_name,
1479 char const * coupling_timestep, int time_unit, int time_reduction,
1480 int interp_stack_config_id, int src_lag, int tgt_lag){
1481
1482 check_default_instance_id("yac_cdef_couple");
1484 src_comp_name, src_grid_name, src_field_name,
1485 tgt_comp_name, tgt_grid_name, tgt_field_name,
1486 coupling_timestep, time_unit, time_reduction, interp_stack_config_id,
1487 src_lag, tgt_lag);
1488}
1489
1491 int yac_instance_id,
1492 char const * src_comp_name, char const * src_grid_name, char const * src_field_name,
1493 char const * tgt_comp_name, char const * tgt_grid_name, char const * tgt_field_name,
1494 char const * coupling_timestep, int time_unit, int time_reduction,
1495 int interp_stack_config_id, int src_lag, int tgt_lag,
1496 char const * weight_file, int mapping_side,
1497 double scale_factor, double scale_summand,
1498 int num_src_mask_names, char const * const * src_mask_names,
1499 char const * tgt_mask_name) {
1500
1502 num_src_mask_names >= 0,
1503 "ERROR(yac_cdef_couple_instance_): "
1504 "\"%d\" is not a valid number of source mask names", num_src_mask_names)
1505
1506 struct yac_ext_couple_config ext_couple_config;
1507 init_ext_couple_config(&ext_couple_config);
1509 &ext_couple_config, weight_file);
1511 &ext_couple_config, mapping_side);
1513 &ext_couple_config, scale_factor);
1515 &ext_couple_config, scale_summand);
1517 &ext_couple_config, (size_t)num_src_mask_names, src_mask_names);
1519 &ext_couple_config, tgt_mask_name);
1520
1522 yac_instance_id, src_comp_name, src_grid_name, src_field_name,
1523 tgt_comp_name, tgt_grid_name, tgt_field_name, coupling_timestep,
1524 time_unit, time_reduction, interp_stack_config_id, src_lag, tgt_lag,
1525 &ext_couple_config);
1526}
1527
1529 char const * src_comp_name, char const * src_grid_name, char const * src_field_name,
1530 char const * tgt_comp_name, char const * tgt_grid_name, char const * tgt_field_name,
1531 char const * coupling_timestep, int time_unit, int time_reduction,
1532 int interp_stack_config_id, int src_lag, int tgt_lag,
1533 char const * weight_file, int mapping_side,
1534 double scale_factor, double scale_summand,
1535 int num_src_mask_names, char const * const * src_mask_names,
1536 char const * tgt_mask_name) {
1537
1538 check_default_instance_id("yac_cdef_couple_");
1540 src_comp_name, src_grid_name, src_field_name,
1541 tgt_comp_name, tgt_grid_name, tgt_field_name,
1542 coupling_timestep, time_unit, time_reduction, interp_stack_config_id,
1543 src_lag, tgt_lag, weight_file, mapping_side,
1546}
1547
1548/* ---------------------------------------------------------------------- */
1549
1551 int collection_size,
1552 int num_interp_fields,
1553 int const * interp_field_sizes ) {
1554
1555 struct coupling_field * cpl_field =
1556 yac_unique_id_to_pointer(field_id, "field_id");
1557
1561 "ERROR(yac_ccheck_field_dimensions): mismatching collection sizes "
1562 "for component %s grid %s field %s (%d != %d)",
1566 yac_get_coupling_field_name(cpl_field),
1568
1569 if (num_interp_fields != -1) {
1570
1572 (size_t)num_interp_fields ==
1574 "ERROR(yac_ccheck_field_dimensions): mismatching number of interp fields "
1575 "for component %s grid %s field %s (%d != %zu)",
1579 yac_get_coupling_field_name(cpl_field),
1581
1582 if (interp_field_sizes) {
1583 for (int interp_field_idx = 0; interp_field_idx < num_interp_fields;
1584 ++interp_field_idx) {
1585
1587 (size_t)interp_field_sizes[interp_field_idx] ==
1589 cpl_field,
1591 cpl_field, (size_t)interp_field_idx)),
1592 "ERROR(yac_ccheck_field_dimensions): mismatching interp field size "
1593 "for component %s grid %s field %s interp_field_idx %d (%d != %zu)",
1597 yac_get_coupling_field_name(cpl_field),
1598 interp_field_idx,
1599 interp_field_sizes[interp_field_idx],
1601 cpl_field,
1603 cpl_field, (size_t)interp_field_idx)));
1604 }
1605 }
1606 }
1607}
1608
1609/* ---------------------------------------------------------------------- */
1610
1611void yac_cget_action(int field_id, int * action) {
1612
1613 struct coupling_field * cpl_field =
1614 yac_unique_id_to_pointer(field_id, "field_id");
1617
1618 YAC_ASSERT(
1619 (exchange_type == NOTHING) ||
1620 (exchange_type == SOURCE) ||
1621 (exchange_type == TARGET),
1622 "ERROR(yac_cget_action): invalid field exchange type")
1623
1624 switch(exchange_type) {
1625 default:
1626 case(NOTHING): {
1627
1628 *action = YAC_ACTION_NONE;
1629 break;
1630 }
1631 case(TARGET): {
1632
1633 enum yac_action_type event_action =
1635 *action = (int)((event_action == RESTART)?GET_FOR_RESTART:event_action);
1636 break;
1637 }
1638 case(SOURCE): {
1639
1640 enum yac_action_type event_action = NONE;
1641 unsigned num_puts = yac_get_coupling_field_num_puts(cpl_field);
1642 for (unsigned put_idx = 0; put_idx < num_puts; ++put_idx)
1643 event_action =
1644 MAX(
1645 event_action,
1647 yac_get_coupling_field_put_op_event(cpl_field, put_idx)));
1648 *action = (int)((event_action == RESTART)?PUT_FOR_RESTART:event_action);
1649 break;
1650 }
1651 }
1652}
1653
1654const char* yac_cget_field_datetime(int field_id){
1655 struct coupling_field * cpl_field =
1656 yac_unique_id_to_pointer(field_id, "field_id");
1657 return yac_coupling_field_get_datetime(cpl_field);
1658}
1659
1660/* ---------------------------------------------------------------------- */
1661
1662static void inline yac_cupdate_(
1663 struct coupling_field * cpl_field, struct event * event, int is_source) {
1664
1667 "ERROR(yac_cupdate): current action of %s field \"%s\" of "
1668 "componente \"%s\" is not YAC_ACTION_NONE",
1669 ((is_source)?"source":"target"), yac_get_coupling_field_name(cpl_field),
1672}
1673
1674void yac_cupdate(int field_id) {
1675
1676 struct coupling_field * cpl_field =
1677 yac_unique_id_to_pointer(field_id, "field_id");
1680
1681 YAC_ASSERT(
1682 (exchange_type == NOTHING) ||
1683 (exchange_type == SOURCE) ||
1684 (exchange_type == TARGET),
1685 "ERROR(yac_cupdate): invalid field exchange type")
1686
1687 switch(exchange_type) {
1688 default:
1689 case(NOTHING): {
1690 break;
1691 }
1692 case(TARGET): {
1693
1695 cpl_field, yac_get_coupling_field_get_op_event(cpl_field), 0);
1696 break;
1697 }
1698 case(SOURCE): {
1699
1700 unsigned num_puts = yac_get_coupling_field_num_puts(cpl_field);
1701 for (unsigned put_idx = 0; put_idx < num_puts; ++put_idx)
1703 cpl_field,
1704 yac_get_coupling_field_put_op_event(cpl_field, put_idx), 1);
1705 break;
1706 }
1707 }
1708}
1709
1710/* ---------------------------------------------------------------------- */
1711
1713 int const field_id,
1714 int const collection_size,
1715 double *recv_field) { // recv_field[collection_size][Points]
1716
1717 struct coupling_field * cpl_field =
1718 yac_unique_id_to_pointer(field_id, "field_id");
1719
1720 YAC_ASSERT(
1722 "ERROR(get_recv_field_pointers): invalid number of interpolation fields "
1723 "(should be one)")
1724
1725 enum yac_location location =
1727 size_t num_points =
1728 yac_coupling_field_get_data_size(cpl_field, location);
1729
1730 double ** recv_field_ = xmalloc(collection_size * sizeof(*recv_field_));
1731
1732 for (int i = 0; i < collection_size; ++i) {
1733 recv_field_[i] = recv_field;
1734 recv_field += num_points;
1735 }
1736
1737 return recv_field_;
1738}
1739
1741 int const field_id, int collection_size, int *info, int *ierr) {
1742
1743 *info = (int)NONE;
1744 *ierr = 0;
1745
1746 struct coupling_field * cpl_field =
1747 yac_unique_id_to_pointer(field_id, "field_id");
1748
1750 return NULL;
1751
1752 /* --------------------------------------------------------------------
1753 Check for restart and coupling events
1754 -------------------------------------------------------------------- */
1755
1756 struct event * event = yac_get_coupling_field_get_op_event(cpl_field);
1758 *info = (int)((action == RESTART)?GET_FOR_RESTART:action);
1759
1760 /* --------------------------------------------------------------------
1761 add one model time step (as provided in coupling configuration) to
1762 the current event date
1763 -------------------------------------------------------------------- */
1764
1766
1767 /* ------------------------------------------------------------------
1768 return in case we are already beyond the end of the run
1769 ------------------------------------------------------------------ */
1770
1771 if ( action == OUT_OF_BOUND ) {
1772
1773 fputs("WARNING: yac get action is beyond end of run date!\n", stderr);
1774 fputs("WARNING: yac get action is beyond end of run date!\n", stdout);
1775
1776 return NULL;
1777 }
1778
1779 /* --------------------------------------------------------------------
1780 start actions
1781 -------------------------------------------------------------------- */
1782
1783 if ( action == NONE ) return NULL;
1784
1785 YAC_ASSERT(
1786 collection_size == yac_get_coupling_field_collection_size(cpl_field),
1787 "ERROR: collection size does not match with coupling configuration.")
1788
1790}
1791
1792static void yac_get ( int const field_id,
1793 int collection_size,
1794 double ** recv_field,
1795 int is_async,
1796 int *info,
1797 int *ierr ) {
1798
1799 yac_ccheck_field_dimensions(field_id, collection_size, 1, NULL);
1800
1801 struct yac_interpolation * interpolation =
1802 yac_cget_pre_processing(field_id, collection_size, info, ierr);
1803
1804 if ((*ierr == 0) && (interpolation != NULL)) {
1805 if (is_async)
1806 yac_interpolation_execute_get_async(interpolation, recv_field);
1807 else
1808 yac_interpolation_execute_get(interpolation, recv_field);
1809 }
1810}
1811
1812/* ---------------------------------------------------------------------- */
1813
1814void yac_get_ ( int const field_id,
1815 int const collection_size,
1816 double *recv_field,
1817 int is_async,
1818 int *info,
1819 int *ierr ) {
1820
1821 yac_ccheck_field_dimensions(field_id, collection_size, 1, NULL);
1822
1823 /* Needed to transfer from Fortran data structure to C */
1824 double ** recv_field_ =
1825 get_recv_field_pointers(field_id, collection_size, recv_field);
1826
1827 yac_get(field_id, collection_size, recv_field_, is_async, info, ierr);
1828
1829 free(recv_field_);
1830}
1831
1832void yac_cget_ ( int const field_id,
1833 int const collection_size,
1834 double *recv_field, // recv_field[collection_size][Points]
1835 int *info,
1836 int *ierr ) {
1837
1838 yac_get_(field_id, collection_size, recv_field, 0, info, ierr);
1839}
1840
1841void yac_cget_async_ ( int const field_id,
1842 int const collection_size,
1843 double *recv_field, // recv_field[collection_size][Points]
1844 int *info,
1845 int *ierr ) {
1846
1847 yac_get_(field_id, collection_size, recv_field, 1, info, ierr);
1848}
1849
1850void yac_cget ( int const field_id,
1851 int collection_size,
1852 double ** recv_field, // recv_field[collection_size][Points]
1853 int *info,
1854 int *ierr ) {
1855
1856 yac_get(field_id, collection_size, recv_field, 0, info, ierr);
1857}
1858
1859void yac_cget_async ( int const field_id,
1860 int collection_size,
1861 double ** recv_field, // recv_field[collection_size][Points]
1862 int *info,
1863 int *ierr ) {
1864
1865
1866 yac_get(field_id, collection_size, recv_field, 1, info, ierr);
1867}
1868
1869/* ---------------------------------------------------------------------- */
1870
1872 int const field_id,
1873 int const collection_size,
1874 double * send_field, // send_field[collection_size][nPointSets][Points]
1875 double * send_frac_mask,
1876 double **** send_field_,
1877 double **** send_frac_mask_) {
1878
1879 struct coupling_field * cpl_field =
1880 yac_unique_id_to_pointer(field_id, "field_id");
1881
1882 size_t num_interp_fields =
1884
1885 size_t * num_points = xmalloc(num_interp_fields * sizeof(*num_points));
1886
1887 for (size_t i = 0; i < num_interp_fields; i++) {
1888
1889 enum yac_location location =
1891 num_points[i] = yac_coupling_field_get_data_size(cpl_field, location);
1892 }
1893
1894 *send_field_ = xmalloc(collection_size * sizeof(**send_field_));
1895 for (int i = 0; i < collection_size; ++i) {
1896 (*send_field_)[i] = xmalloc(num_interp_fields * sizeof(***send_field_));
1897 for (size_t j = 0; j < num_interp_fields; ++j) {
1898 (*send_field_)[i][j] = send_field;
1899 send_field += num_points[j];
1900 }
1901 }
1902 if (send_frac_mask != NULL) {
1903 *send_frac_mask_ =
1904 xmalloc(collection_size * sizeof(**send_frac_mask_));
1905 for (int i = 0; i < collection_size; ++i) {
1906 (*send_frac_mask_)[i] =
1907 xmalloc(num_interp_fields * sizeof(***send_frac_mask_));
1908 for (size_t j = 0; j < num_interp_fields; ++j) {
1909 (*send_frac_mask_)[i][j] = send_frac_mask;
1910 send_frac_mask += num_points[j];
1911 }
1912 }
1913 }
1914 free(num_points);
1915}
1916
1917void yac_cput_ ( int const field_id,
1918 int const collection_size,
1919 double *send_field, // send_field[collection_size]
1920 // [nPointSets]
1921 // [Points]
1922 int *info,
1923 int *ierr ) {
1924
1925 yac_ccheck_field_dimensions(field_id, collection_size, -1, NULL);
1926
1927 /* Needed to transfer from Fortran data structure to C */
1928 double *** send_field_;
1930 field_id, collection_size, send_field, NULL, &send_field_, NULL);
1931
1932 yac_cput ( field_id, collection_size, send_field_, info, ierr );
1933
1934 for (int i = 0; i < collection_size; ++i) free(send_field_[i]);
1935 free(send_field_);
1936}
1937
1938void yac_cput_frac_ ( int const field_id,
1939 int const collection_size,
1940 double *send_field, // send_field[collection_size]
1941 // [nPointSets]
1942 // [Points]
1943 double *send_frac_mask, // send_frac_mask[collection_size]
1944 // [nPointSets]
1945 // [Points]
1946 int *info,
1947 int *ierr ) {
1948
1949 yac_ccheck_field_dimensions(field_id, collection_size, -1, NULL);
1950
1951 /* Needed to transfer from Fortran data structure to C */
1952 double *** send_field_;
1953 double *** send_frac_mask_;
1955 field_id, collection_size, send_field, send_frac_mask,
1956 &send_field_, &send_frac_mask_);
1957
1959 field_id, collection_size, send_field_, send_frac_mask_, info, ierr);
1960
1961 for (int i = 0; i < collection_size; ++i) {
1962 free(send_field_[i]);
1963 free(send_frac_mask_[i]);
1964 }
1965 free(send_field_);
1966 free(send_frac_mask_);
1967}
1968
1969/* ---------------------------------------------------------------------- */
1970
1972 int const field_id,
1973 int const collection_size,
1974 double **send_field, // send_field[collection_size*nPointSets][Points]
1975 double **send_frac_mask,
1976 double ****send_field_,
1977 double ****send_frac_mask_) {
1978
1979 struct coupling_field * cpl_field =
1980 yac_unique_id_to_pointer(field_id, "field_id");
1981
1982 size_t num_interp_fields =
1984
1985 size_t * num_points = xmalloc(num_interp_fields * sizeof(*num_points));
1986
1987 for (size_t i = 0; i < num_interp_fields; i++) {
1988
1989 enum yac_location location =
1991 num_points[i] = yac_coupling_field_get_data_size(cpl_field, location);
1992 }
1993
1994 *send_field_ = xmalloc(collection_size * sizeof(**send_field_));
1995 for (int i = 0, k = 0; i < collection_size; ++i) {
1996
1997 (*send_field_)[i] = xmalloc(num_interp_fields * sizeof(***send_field_));
1998 for (size_t j = 0; j < num_interp_fields; ++j, ++k)
1999 (*send_field_)[i][j] = send_field[k];
2000 }
2001 if (send_frac_mask != NULL) {
2002 *send_frac_mask_ = xmalloc(collection_size * sizeof(**send_frac_mask_));
2003 for (int i = 0, k = 0; i < collection_size; ++i) {
2004
2005 (*send_frac_mask_)[i] =
2006 xmalloc(num_interp_fields * sizeof(***send_frac_mask_));
2007 for (size_t j = 0; j < num_interp_fields; ++j, ++k)
2008 (*send_frac_mask_)[i][j] = send_frac_mask[k];
2009 }
2010 }
2011
2012 free(num_points);
2013}
2014
2015void yac_cput_ptr_ ( int const field_id,
2016 int const collection_size,
2017 double ** send_field, // send_field[collection_size *
2018 // nPointSets][Points]
2019 int *info,
2020 int *ierr ) {
2021
2022 yac_ccheck_field_dimensions(field_id, collection_size, -1, NULL);
2023
2024 /* Needed to transfer from Fortran data structure to C */
2025 double *** send_field_;
2027 field_id, collection_size, send_field, NULL, &send_field_, NULL);
2028
2029 yac_cput ( field_id, collection_size, send_field_, info, ierr );
2030
2031 for (int i = 0; i < collection_size; ++i) free(send_field_[i]);
2032 free(send_field_);
2033}
2034
2035void yac_cput_frac_ptr_ ( int const field_id,
2036 int const collection_size,
2037 double ** send_field, // send_field[collection_size *
2038 // nPointSets][Points]
2039 double ** send_frac_mask, // send_frac_mask[collection_size *
2040 // nPointSets][Points]
2041 int *info,
2042 int *ierr ) {
2043
2044 yac_ccheck_field_dimensions(field_id, collection_size, -1, NULL);
2045
2046 /* Needed to transfer from Fortran data structure to C */
2047 double *** send_field_;
2048 double *** send_frac_mask_;
2050 field_id, collection_size, send_field, send_frac_mask,
2051 &send_field_, &send_frac_mask_);
2052
2054 field_id, collection_size, send_field_, send_frac_mask_, info, ierr);
2055
2056 for (int i = 0; i < collection_size; ++i) {
2057 free(send_field_[i]);
2058 free(send_frac_mask_[i]);
2059 }
2060 free(send_field_);
2061 free(send_frac_mask_);
2062}
2063
2064/* ---------------------------------------------------------------------- */
2065
2066void yac_ctest(int field_id, int * flag) {
2067
2068 struct coupling_field * cpl_field =
2069 yac_unique_id_to_pointer(field_id, "field_id");
2070
2071 *flag = 1;
2072 if (yac_get_coupling_field_exchange_type(cpl_field) == SOURCE) {
2073 for (
2074 unsigned put_idx = 0;
2075 (put_idx < yac_get_coupling_field_num_puts(cpl_field)) && *flag;
2076 ++put_idx)
2077 *flag &=
2080 }
2081
2082 if (*flag && yac_get_coupling_field_exchange_type(cpl_field) == TARGET)
2083 *flag =
2086}
2087
2088/* ---------------------------------------------------------------------- */
2089
2090void yac_cwait(int field_id) {
2091
2092 struct coupling_field * cpl_field =
2093 yac_unique_id_to_pointer(field_id, "field_id");
2094
2095 if (yac_get_coupling_field_exchange_type(cpl_field) == SOURCE) {
2096 for (
2097 unsigned put_idx = 0;
2098 (put_idx < yac_get_coupling_field_num_puts(cpl_field)); ++put_idx)
2101 }
2102
2106}
2107
2108/* ---------------------------------------------------------------------- */
2109
2110void * yac_get_field_put_mask_c2f(int field_id) {
2111
2112 struct coupling_field * cpl_field =
2113 yac_unique_id_to_pointer(field_id, "field_id");
2114
2115 return (void*)yac_get_coupling_field_put_mask(cpl_field);
2116}
2117
2118void * yac_get_field_get_mask_c2f(int field_id) {
2119
2120 struct coupling_field * cpl_field =
2121 yac_unique_id_to_pointer(field_id, "field_id");
2122
2123 return (void*)yac_get_coupling_field_get_mask(cpl_field);
2124}
2125
2126/* ---------------------------------------------------------------------- */
2127
2129 struct coupling_field * cpl_field, unsigned put_idx,
2130 int const collection_size, double *** send_field,
2131 double **** send_field_acc_, double *** send_frac_mask,
2132 double **** send_frac_mask_acc_, int *info, int *ierr) {
2133
2134 *ierr = 0;
2135
2136 int with_frac_mask = send_frac_mask != NULL;
2137
2138 /* ------------------------------------------------------------------
2139 Check for restart and coupling events
2140 ------------------------------------------------------------------ */
2141
2142 struct event * event = yac_get_coupling_field_put_op_event(cpl_field, put_idx);
2144 *info = (int)((action == RESTART)?PUT_FOR_RESTART:action);
2145
2146 /* ------------------------------------------------------------------
2147 add one model time step (as provided in coupling configuration) to
2148 the current event date
2149 ------------------------------------------------------------------ */
2150
2152
2153 /* ------------------------------------------------------------------
2154 return in case we are already beyond the end of the run
2155 ------------------------------------------------------------------ */
2156
2157 if (action == OUT_OF_BOUND) {
2158
2159 fputs("WARNING: yac put action is beyond end of run date!\n", stderr);
2160 fputs("WARNING: yac put action is beyond end of run date!\n", stdout);
2161
2162 *send_field_acc_ = NULL;
2163 *send_frac_mask_acc_ = NULL;
2164 return NULL;
2165 }
2166
2167 /* ------------------------------------------------------------------
2168 start actions
2169 ------------------------------------------------------------------ */
2170
2171 if ( action == NONE ) return NULL;
2172
2173 /* ------------------------------------------------------------------
2174 If it is time for restart, set appropriate flags and continue
2175 ------------------------------------------------------------------ */
2176
2177 /* ------------------------------------------------------------------
2178 First deal with instant sends
2179 ------------------------------------------------------------------ */
2180
2181 int ** put_mask = yac_get_coupling_field_put_mask(cpl_field);
2182 size_t num_interp_fields =
2184
2186 if ( time_operation == TIME_NONE ) {
2187
2188 *info = MAX((int)COUPLING, *info);
2189
2190 if (with_frac_mask) {
2191
2192 // apply fractional mask to send field
2193 double *** send_field_acc =
2195 *send_field_acc_ = send_field_acc;
2196 *send_frac_mask_acc_ = send_frac_mask;
2197
2198 for (int h = 0; h < collection_size; h++) {
2199 for (size_t i = 0; i < num_interp_fields; i++) {
2200 size_t num_points =
2202 cpl_field,
2203 yac_coupling_field_get_interp_fields(cpl_field)[i].location);
2204 if (put_mask) {
2205 for (size_t j = 0; j < num_points; ++j) {
2206 if (put_mask[i][j]) {
2207 double frac_mask = send_frac_mask[h][i][j];
2208 send_field_acc[h][i][j] =
2209 (frac_mask != 0.0)?(send_field[h][i][j] * frac_mask):0.0;
2210 }
2211 }
2212 } else {
2213 for (size_t j = 0; j < num_points; ++j) {
2214 double frac_mask = send_frac_mask[h][i][j];
2215 send_field_acc[h][i][j] =
2216 (frac_mask != 0.0)?(send_field[h][i][j] * frac_mask):0.0;
2217 }
2218 }
2219 }
2220 }
2221 } else {
2222 *send_field_acc_ = NULL;
2223 *send_frac_mask_acc_ = NULL;
2224 }
2225 return yac_get_coupling_field_put_op_interpolation(cpl_field, put_idx);
2226 }
2227
2228 /* ------------------------------------------------------------------
2229 Accumulation & Averaging
2230 ------------------------------------------------------------------ */
2231
2232 YAC_ASSERT(
2237 "ERROR(yac_cput_pre_processing): invalid time operation type")
2238
2239 int time_accumulation_count =
2241
2242 time_accumulation_count++;
2243
2244 // if this is the first accumulation step
2245 if (time_accumulation_count == 1) {
2246
2247 double send_field_acc_init_value;
2248 switch (time_operation) {
2249 default:
2250 case(TIME_ACCUMULATE):
2251 case(TIME_AVERAGE):
2252 send_field_acc_init_value = 0.0;
2253 break;
2254 case(TIME_MINIMUM):
2255 send_field_acc_init_value = DBL_MAX;
2256 break;
2257 case(TIME_MAXIMUM):
2258 send_field_acc_init_value = -DBL_MAX;
2259 break;
2260 }
2261
2262 /* initalise memory */
2263
2265 cpl_field, put_idx, send_field_acc_init_value);
2266 if (with_frac_mask)
2268 cpl_field, put_idx, 0.0);
2269 }
2270
2271 /* accumulate data */
2272
2273 double *** send_field_acc =
2275 *send_field_acc_ = send_field_acc;
2276 double *** send_frac_mask_acc;
2277 if (with_frac_mask) {
2278 send_frac_mask_acc =
2280 *send_frac_mask_acc_ = send_frac_mask_acc;
2281 } else {
2282 send_frac_mask_acc = NULL;
2283 *send_frac_mask_acc_ = NULL;
2284 }
2285
2286#define NO_CHECK (1)
2287#define PUT_CHECK (put_mask[i][j])
2288#define SUM +=
2289#define ASSIGN =
2290#define AGGREGATE_FRAC(CHECK, EXTRA_CHECK, ACCU_OP) \
2291 { \
2292 YAC_OMP_PARALLEL \
2293 { \
2294 YAC_OMP_FOR \
2295 for (size_t j = 0; j < num_points; ++j) { \
2296 double frac_mask = send_frac_mask[h][i][j]; \
2297 double send_field_value = send_field[h][i][j] * frac_mask; \
2298 if (CHECK && (EXTRA_CHECK)) { \
2299 if (frac_mask != 0.0) { \
2300 send_field_acc[h][i][j] ACCU_OP send_field_value; \
2301 send_frac_mask_acc[h][i][j] ACCU_OP frac_mask; \
2302 } \
2303 } \
2304 } \
2305 } \
2306 }
2307#define AGGREATE_NOFRAC(CHECK, EXTRA_CHECK, ACCU_OP) \
2308 { \
2309 YAC_OMP_PARALLEL \
2310 { \
2311 YAC_OMP_FOR \
2312 for (size_t j = 0; j < num_points; ++j) {\
2313 double send_field_value = send_field[h][i][j]; \
2314 if (CHECK && (EXTRA_CHECK)) \
2315 send_field_acc[h][i][j] ACCU_OP send_field_value; \
2316 } \
2317 } \
2318 }
2319#define AGGREGATE(EXTRA_CHECK, ACCU_OP) \
2320 { \
2321 for (int h = 0; h < collection_size; h++) { \
2322 for (size_t i = 0; i < num_interp_fields; i++) { \
2323 size_t num_points = \
2324 yac_coupling_field_get_data_size( \
2325 cpl_field, \
2326 yac_coupling_field_get_interp_fields(cpl_field)[i].location); \
2327 if (with_frac_mask) { \
2328 if (put_mask) AGGREGATE_FRAC(PUT_CHECK, EXTRA_CHECK, ACCU_OP) \
2329 else AGGREGATE_FRAC(NO_CHECK, EXTRA_CHECK, ACCU_OP) \
2330 } else { \
2331 if (put_mask) AGGREATE_NOFRAC(PUT_CHECK, EXTRA_CHECK, ACCU_OP) \
2332 else AGGREATE_NOFRAC(NO_CHECK, EXTRA_CHECK, ACCU_OP) \
2333 } \
2334 } \
2335 } \
2336 break; \
2337 }
2338
2339 switch (time_operation) {
2340 default:
2341 case(TIME_ACCUMULATE):
2342 case(TIME_AVERAGE):
2344 case(TIME_MINIMUM):
2345 AGGREGATE(send_field_acc[h][i][j] > send_field_value, ASSIGN)
2346 case(TIME_MAXIMUM):
2347 AGGREGATE(send_field_acc[h][i][j] < send_field_value, ASSIGN)
2348 }
2349
2350#undef AGGREGATE
2351#undef AGGREATE_NOFRAC
2352#undef AGGREGATE_FRAC
2353#undef ASSIGN
2354#undef SUM
2355#undef PUT_CHECK
2356#undef NO_CHECK
2357
2358/* --------------------------------------------------------------------
2359 Check whether we have to perform the coupling in this call
2360 -------------------------------------------------------------------- */
2361
2362 if (action == REDUCTION) {
2364 cpl_field, put_idx, time_accumulation_count);
2365 return NULL;
2366 }
2367
2368/* --------------------------------------------------------------------
2369 Average data if required
2370 -------------------------------------------------------------------- */
2371
2372 if (( time_operation == TIME_AVERAGE ) ||
2374
2375 double weight = 1.0 / (double)time_accumulation_count;
2376
2377#define NO_CHECK (1)
2378#define PUT_CHECK (put_mask[i][j])
2379#define WEIGHT_ACC_(ACC, CHECK, EXTRA_CHECK) \
2380 { \
2381 for (size_t j = 0; j < num_points; j++) \
2382 if (CHECK && (EXTRA_CHECK)) ACC[h][i][j] *= weight; \
2383 }
2384#define WEIGHT_ACC(ACC, EXTRA_CHECK) \
2385 { \
2386 if (put_mask) WEIGHT_ACC_(ACC, PUT_CHECK, EXTRA_CHECK) \
2387 else WEIGHT_ACC_(ACC, NO_CHECK, EXTRA_CHECK) \
2388 }
2389
2390 for (int h = 0; h < collection_size; ++h) {
2391 for (size_t i = 0; i < num_interp_fields; i++) {
2392 size_t num_points =
2394 cpl_field,
2395 yac_coupling_field_get_interp_fields(cpl_field)[i].location);
2396 if (with_frac_mask)
2397 WEIGHT_ACC(send_frac_mask_acc, NO_CHECK)
2399 if (with_frac_mask)
2400 WEIGHT_ACC(send_field_acc, send_frac_mask_acc[h][i][j] != 0.0)
2401 else
2402 WEIGHT_ACC(send_field_acc, NO_CHECK)
2403 }
2404 }
2405 }
2406 }
2407
2408#undef NO_CHECK
2409#undef PUT_CHECK
2410#undef WEIGHT_ACC_
2411#undef WEIGHT_ACC
2412
2413 // reset time_accumulation_count
2415 cpl_field, put_idx, 0);
2416
2417/* --------------------------------------------------------------------
2418 return interpolation
2419 -------------------------------------------------------------------- */
2420
2421 *info = MAX((int)COUPLING, *info);
2422 return yac_get_coupling_field_put_op_interpolation(cpl_field, put_idx);
2423}
2424
2425void yac_cput_frac ( int const field_id,
2426 int const collection_size,
2427 double *** const send_field, // send_field[collection_size]
2428 // [nPointSets][Points]
2429 double *** const send_frac_mask, // send_frac_mask[collection_size]
2430 // [nPointSets][Points]
2431 int *info,
2432 int *ierr ) {
2433
2434 yac_ccheck_field_dimensions(field_id, collection_size, -1, NULL);
2435
2436 *info = NONE;
2437 *ierr = 0;
2438
2439 struct coupling_field * cpl_field =
2440 yac_unique_id_to_pointer(field_id, "field_id");
2441
2443 return;
2444
2445 YAC_ASSERT(
2447 "ERROR: collection size does not match with coupling configuration.")
2448
2449 for (unsigned put_idx = 0;
2450 put_idx < yac_get_coupling_field_num_puts(cpl_field); ++put_idx) {
2451
2452 int curr_action;
2453 int curr_ierr;
2454 double *** send_field_acc;
2455 double *** send_frac_mask_acc;
2456 struct yac_interpolation * interpolation =
2458 cpl_field, put_idx, collection_size,
2459 send_field, &send_field_acc,
2460 send_frac_mask, &send_frac_mask_acc,
2461 &curr_action, &curr_ierr);
2462
2463 *info = MAX(*info, curr_action);
2464 *ierr = MAX(*ierr, curr_ierr);
2465
2466 /* ------------------------------------------------------------------
2467 return in case we are already beyond the end of the run
2468 ------------------------------------------------------------------ */
2469 if (curr_action == OUT_OF_BOUND) {
2470 *info = OUT_OF_BOUND;
2471 return;
2472 }
2473
2474 /* ------------------------------------------------------------------
2475 in case there is nothing to be done for the current put
2476 ------------------------------------------------------------------ */
2477 if ((curr_action == NONE) || (curr_action == REDUCTION)) continue;
2478
2479 /* ------------------------------------------------------------------
2480 in case we are supposed to couple
2481 ------------------------------------------------------------------ */
2482 if ((*ierr == 0) && (interpolation != NULL)) {
2483
2484 int with_frac_mask =
2485 yac_interpolation_with_frac_mask(interpolation);
2486
2488 (with_frac_mask && (send_frac_mask != NULL)) ||
2489 !with_frac_mask,
2490 "ERROR: interpolation for field \"%s\" was built for dynamic "
2491 "fractional masking, but no mask was provided",
2492 yac_get_coupling_field_name(cpl_field));
2494 (!with_frac_mask && (send_frac_mask == NULL)) ||
2495 with_frac_mask,
2496 "ERROR: interpolation for field \"%s\" was not built for dynamic "
2497 "fractional masking, but a mask was provided",
2498 yac_get_coupling_field_name(cpl_field));
2499
2500 double *** send_field_ptr =
2501 (send_field_acc == NULL)?send_field:send_field_acc;
2502 double *** send_frac_mask_ptr =
2503 (send_frac_mask_acc == NULL)?send_frac_mask:send_frac_mask_acc;
2504
2505 if (with_frac_mask)
2507 interpolation, send_field_ptr, send_frac_mask_ptr);
2508 else
2509 yac_interpolation_execute_put(interpolation, send_field_ptr);
2510 }
2511 }
2512}
2513
2514void yac_cput ( int const field_id,
2515 int const collection_size,
2516 double *** const send_field, // send_field[collection_size]
2517 // [nPointSets][Points]
2518 int *info,
2519 int *ierr ) {
2520
2522 field_id, collection_size, send_field, NULL, info, ierr);
2523}
2524
2525/* ---------------------------------------------------------------------- */
2526
2527
2528void yac_cexchange_ ( int const send_field_id,
2529 int const recv_field_id,
2530 int const collection_size,
2531 double *send_field, // send_field[collection_size]
2532 // [nPointSets]
2533 // [Points]
2534 double *recv_field, // recv_field[collection_size][Points]
2535 int *send_info,
2536 int *recv_info,
2537 int *ierr ) {
2538
2539 yac_ccheck_field_dimensions(send_field_id, collection_size, 1, NULL);
2540 yac_ccheck_field_dimensions(recv_field_id, collection_size, -1, NULL);
2541
2542 /* Needed to transfer from Fortran data structure to C */
2543 double *** send_field_;
2545 send_field_id, collection_size, send_field, NULL, &send_field_, NULL);
2546 double ** recv_field_ =
2547 get_recv_field_pointers(recv_field_id, collection_size, recv_field);
2548
2550 send_field_id, recv_field_id, collection_size, send_field_, recv_field_,
2551 send_info, recv_info, ierr);
2552
2553 free(recv_field_);
2554 for (int i = 0; i < collection_size; ++i) free(send_field_[i]);
2555 free(send_field_);
2556}
2557
2558/* ---------------------------------------------------------------------- */
2559
2560
2561void yac_cexchange_frac_ ( int const send_field_id,
2562 int const recv_field_id,
2563 int const collection_size,
2564 double *send_field, // send_field[collection_size]
2565 // [nPointSets]
2566 // [Points]
2567 double *send_frac_mask, // send_frac_mask[collection_size]
2568 // [nPointSets]
2569 // [Points]
2570 double *recv_field, // recv_field[collection_size][Points]
2571 int *send_info,
2572 int *recv_info,
2573 int *ierr ) {
2574
2575 yac_ccheck_field_dimensions(send_field_id, collection_size, 1, NULL);
2576 yac_ccheck_field_dimensions(recv_field_id, collection_size, -1, NULL);
2577
2578 /* Needed to transfer from Fortran data structure to C */
2579 double *** send_field_;
2580 double *** send_frac_mask_;
2582 send_field_id, collection_size, send_field, send_frac_mask,
2583 &send_field_, &send_frac_mask_);
2584 double ** recv_field_ =
2585 get_recv_field_pointers(recv_field_id, collection_size, recv_field);
2586
2588 send_field_id, recv_field_id, collection_size, send_field_, send_frac_mask_,
2589 recv_field_, send_info, recv_info, ierr);
2590
2591 free(recv_field_);
2592 for (int i = 0; i < collection_size; ++i) {
2593 free(send_field_[i]);
2594 free(send_frac_mask_[i]);
2595 }
2596 free(send_field_);
2597 free(send_frac_mask_);
2598}
2599
2600/* ---------------------------------------------------------------------- */
2601
2602
2603void yac_cexchange_ptr_ ( int const send_field_id,
2604 int const recv_field_id,
2605 int const collection_size,
2606 double ** send_field, // send_field[collection_size *
2607 // nPointSets][Points]
2608 double ** recv_field, // recv_field[collection_size][Points]
2609 int *send_info,
2610 int *recv_info,
2611 int *ierr ) {
2612
2613 yac_ccheck_field_dimensions(send_field_id, collection_size, 1, NULL);
2614 yac_ccheck_field_dimensions(recv_field_id, collection_size, -1, NULL);
2615
2616
2617 /* Needed to transfer from Fortran data structure to C */
2618 double *** send_field_;
2620 send_field_id, collection_size, send_field, NULL, &send_field_, NULL);
2621
2623 send_field_id, recv_field_id, collection_size, send_field_, recv_field,
2624 send_info, recv_info, ierr);
2625
2626 for (int i = 0; i < collection_size; ++i) free(send_field_[i]);
2627 free(send_field_);
2628}
2629
2630/* ---------------------------------------------------------------------- */
2631
2632
2633void yac_cexchange_frac_ptr_ ( int const send_field_id,
2634 int const recv_field_id,
2635 int const collection_size,
2636 double ** send_field, // send_field[collection_size *
2637 // nPointSets][Points]
2638 double ** send_frac_mask, // send_frac_mask[collection_size *
2639 // nPointSets][Points]
2640 double ** recv_field, // recv_field[collection_size][Points]
2641 int *send_info,
2642 int *recv_info,
2643 int *ierr ) {
2644
2645 yac_ccheck_field_dimensions(send_field_id, collection_size, 1, NULL);
2646 yac_ccheck_field_dimensions(recv_field_id, collection_size, -1, NULL);
2647
2648 /* Needed to transfer from Fortran data structure to C */
2649 double *** send_field_;
2650 double *** send_frac_mask_;
2652 send_field_id, collection_size, send_field, send_frac_mask,
2653 &send_field_, &send_frac_mask_);
2654
2656 send_field_id, recv_field_id, collection_size, send_field_, send_frac_mask_,
2657 recv_field, send_info, recv_info, ierr);
2658
2659 for (int i = 0; i < collection_size; ++i) {
2660 free(send_field_[i]);
2661 free(send_frac_mask_[i]);
2662 }
2663 free(send_field_);
2664 free(send_frac_mask_);
2665}
2666
2667/* ---------------------------------------------------------------------- */
2668
2669void yac_cexchange_frac ( int const send_field_id,
2670 int const recv_field_id,
2671 int const collection_size,
2672 double *** const send_field, // send_field[collection_size]
2673 // [nPointSets][Points]
2674 double *** const send_frac_mask, // send_frac_mask[collection_size]
2675 // [nPointSets][Points]
2676 double ** recv_field, // recv_field[collection_size][Points]
2677 int *send_info,
2678 int *recv_info,
2679 int *ierr ) {
2680
2681 yac_ccheck_field_dimensions(send_field_id, collection_size, 1, NULL);
2682 yac_ccheck_field_dimensions(recv_field_id, collection_size, -1, NULL);
2683
2684 *send_info = NONE;
2685 *ierr = -1;
2686
2687 struct coupling_field * send_cpl_field =
2688 yac_unique_id_to_pointer(send_field_id, "send_field_id");
2689
2690 if (yac_get_coupling_field_exchange_type(send_cpl_field) != SOURCE) {
2691 yac_cget(recv_field_id, collection_size, recv_field, recv_info, ierr);
2692 return;
2693 }
2694
2695 YAC_ASSERT(
2697 "ERROR(yac_cexchange_frac): "
2698 "collection size does not match with coupling configuration.")
2699
2700 YAC_ASSERT(
2701 yac_get_coupling_field_num_puts(send_cpl_field) == 1,
2702 "ERROR(yac_cexchange_frac): more than one put per field is not supported "
2703 "for yac_cexchange_frac.")
2704
2705 int send_action;
2706 int send_ierr;
2707 double *** send_field_acc;
2708 double *** send_frac_mask_acc;
2709 struct yac_interpolation * put_interpolation =
2711 send_cpl_field, 0, collection_size, send_field,
2712 &send_field_acc, send_frac_mask, &send_frac_mask_acc,
2713 &send_action, &send_ierr);
2714
2715 *send_info = MAX(*send_info, send_action);
2716 *ierr = MAX(*ierr, send_ierr);
2717
2718 /* ------------------------------------------------------------------
2719 return in case we are already beyond the end of the run for the puts
2720 or there is nothing to be done for the current put
2721 ------------------------------------------------------------------ */
2722 if ((send_action == OUT_OF_BOUND) ||
2723 (send_action == NONE) ||
2724 (send_action == REDUCTION)) {
2725 yac_cget(recv_field_id, collection_size, recv_field, recv_info, ierr);
2726 return;
2727 }
2728
2729 /* ------------------------------------------------------------------
2730 check the get
2731 ------------------------------------------------------------------ */
2732
2733 struct yac_interpolation * get_interpolation =
2734 yac_cget_pre_processing(recv_field_id, collection_size, recv_info, ierr);
2735
2736 /* ------------------------------------------------------------------
2737 do the required exchanges
2738 ------------------------------------------------------------------ */
2739
2740 if (*ierr == 0) {
2741
2742 double *** send_field_ptr =
2743 (send_field_acc == NULL)?send_field:send_field_acc;
2744 double *** send_frac_mask_ptr =
2745 (send_frac_mask_acc == NULL)?send_frac_mask:send_frac_mask_acc;
2746
2747 int with_frac_mask =
2748 yac_interpolation_with_frac_mask(put_interpolation);
2749
2750 // if the get is active
2751 if (get_interpolation != NULL) {
2752
2753 YAC_ASSERT(
2754 get_interpolation == put_interpolation,
2755 "ERROR(yac_cexchange): send_field_id and recv_field_id do not match")
2756
2758 (with_frac_mask && (send_frac_mask != NULL)) ||
2759 !with_frac_mask,
2760 "ERROR: interpolation for field \"%s\" was built for dynamic "
2761 "fractional masking, but no mask was provided",
2762 yac_get_coupling_field_name(send_cpl_field));
2764 (!with_frac_mask && (send_frac_mask == NULL)) ||
2765 with_frac_mask,
2766 "ERROR: interpolation for field \"%s\" was not built for dynamic "
2767 "fractional masking, but a mask was provided",
2768 yac_get_coupling_field_name(send_cpl_field));
2769
2770 if (with_frac_mask)
2772 put_interpolation, send_field_ptr, send_frac_mask_ptr, recv_field);
2773 else
2775 put_interpolation, send_field_ptr, recv_field);
2776
2777 } else {
2778
2780 (with_frac_mask && (send_frac_mask != NULL)) ||
2781 !with_frac_mask,
2782 "ERROR: interpolation for field \"%s\" was built for dynamic "
2783 "fractional masking, but no mask was provided",
2784 yac_get_coupling_field_name(send_cpl_field));
2786 (!with_frac_mask && (send_frac_mask == NULL)) ||
2787 with_frac_mask,
2788 "ERROR: interpolation for field \"%s\" was not built for dynamic "
2789 "fractional masking, but a mask was provided",
2790 yac_get_coupling_field_name(send_cpl_field));
2791
2792 // just execute the put
2793 if (with_frac_mask)
2795 put_interpolation, send_field_ptr, send_frac_mask_ptr);
2796 else
2797 yac_interpolation_execute_put(put_interpolation, send_field_ptr);
2798 }
2799 }
2800}
2801
2802
2803
2804void yac_cexchange ( int const send_field_id,
2805 int const recv_field_id,
2806 int const collection_size,
2807 double *** const send_field, // send_field[collection_size]
2808 // [nPointSets][Points]
2809 double ** recv_field, // recv_field[collection_size][Points]
2810 int *send_info,
2811 int *recv_info,
2812 int *ierr ) {
2813
2815 send_field_id, recv_field_id, collection_size,
2816 send_field, NULL, recv_field, send_info, recv_info, ierr);
2817}
2818
2819/* ---------------------------------------------------------------------- */
2820
2821void yac_csync_def_instance ( int yac_instance_id ){
2823 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id"));
2824}
2825
2830
2831
2832/* ---------------------------------------------------------------------- */
2833
2834void yac_cenddef_instance(int yac_instance_id) {
2835
2837 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id"));
2838}
2839
2840void yac_cenddef (void) {
2841
2842 check_default_instance_id("yac_cenddef");
2844}
2845
2847 int yac_instance_id, int emit_flags, char ** config) {
2848
2849 *config =
2851 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id"),
2852 emit_flags);
2853}
2854
2855void yac_cenddef_and_emit_config ( int emit_flags, char ** config ) {
2856
2857 check_default_instance_id("yac_cenddef");
2859 default_instance_id, emit_flags, config);
2860}
2861
2862/* ----------------------------------------------------------------------
2863 query functions
2864 ----------------------------------------------------------------------*/
2865
2866int yac_cget_field_id_instance(int yac_instance_id, const char* comp_name,
2867 const char* grid_name, const char* field_name){
2868 struct yac_instance * instance =
2869 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
2870 struct coupling_field* cpl_field =
2871 yac_instance_get_field(instance, comp_name, grid_name, field_name);
2872 YAC_ASSERT_F(cpl_field != NULL,
2873 "ERROR(yac_cget_field_id_instance): "
2874 "no field '%s' defined on the local process for "
2875 "component '%s' and grid '%s'", field_name, comp_name, grid_name);
2876 return yac_lookup_pointer(cpl_field);
2877}
2878
2879int yac_cget_field_id(const char* comp_name, const char* grid_name, const char* field_name){
2880 check_default_instance_id("yac_cget_field_id");
2882 grid_name, field_name);
2883}
2884
2885/* ---------------------------------------------------------------------- */
2886
2887int yac_cget_nbr_comps_instance ( int yac_instance_id ) {
2888 struct yac_instance * instance =
2889 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
2890 struct yac_couple_config * couple_config =
2892 return yac_couple_config_get_num_components(couple_config);
2893}
2894
2896 check_default_instance_id("yac_cget_nbr_comps");
2898}
2899
2900int yac_cget_nbr_grids_instance ( int yac_instance_id ) {
2901 struct yac_instance * instance =
2902 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
2903 struct yac_couple_config * couple_config =
2905 return yac_couple_config_get_num_grids(couple_config);
2906}
2907
2909 check_default_instance_id("yac_cget_nbr_grids");
2911}
2912
2913int yac_cget_comp_nbr_grids_instance ( int yac_instance_id,
2914 const char* comp_name ) {
2915 struct yac_instance * instance =
2916 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
2917 struct yac_couple_config * couple_config =
2919 YAC_ASSERT(comp_name != NULL,
2920 "ERROR(yac_cget_comp_grid_names_instance):"
2921 "Invalid comp_name. (NULL is not allowed)");
2922 int nbr_grids = 0;
2923 for(int i=0; i<yac_couple_config_get_num_grids(couple_config); ++i){
2924 const char* grid_name = yac_couple_config_get_grid_name(couple_config, i);
2925 if (yac_cget_nbr_fields_instance(yac_instance_id, comp_name, grid_name) > 0)
2926 nbr_grids++;
2927 }
2928 return nbr_grids;
2929}
2930
2931int yac_cget_comp_nbr_grids ( const char* comp_name ){
2932 check_default_instance_id("yac_cget_comp_nbr_grids");
2934}
2935
2936int yac_cget_nbr_fields_instance ( int yac_instance_id, const char* comp_name,
2937 const char* grid_name) {
2938 struct yac_instance * instance =
2939 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
2940 struct yac_couple_config * couple_config =
2942 size_t comp_idx = yac_couple_config_get_component_idx(couple_config, comp_name);
2943 int nbr_fields = 0;
2944 size_t nbr_comp_fields =
2945 yac_couple_config_get_num_fields(couple_config, comp_idx);
2946 for(size_t field_idx=0; field_idx<nbr_comp_fields; ++field_idx)
2947 if(yac_couple_config_field_is_valid(couple_config, comp_idx, field_idx) &&
2948 !strcmp(
2949 grid_name,
2951 couple_config, comp_idx, field_idx)))
2952 nbr_fields++;
2953 return nbr_fields;
2954}
2955
2956int yac_cget_nbr_fields ( const char* comp_name, const char* grid_name ) {
2957 check_default_instance_id("yac_cget_nbr_fields");
2958 return yac_cget_nbr_fields_instance(default_instance_id, comp_name, grid_name);
2959}
2960
2961void yac_cget_comp_names_instance ( int yac_instance_id, int nbr_comps,
2962 const char ** comp_names ) {
2963 struct yac_instance * instance =
2964 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
2965 struct yac_couple_config * couple_config =
2967 for(size_t i=0;i<nbr_comps;++i) {
2968 comp_names[i] = yac_couple_config_get_component_name(couple_config, i);
2969 }
2970}
2971
2972void yac_cget_comp_names ( int nbr_comps, const char ** comp_names ) {
2973 check_default_instance_id("yac_cget_comp_names");
2975 comp_names );
2976}
2977
2978void yac_cget_grid_names_instance ( int yac_instance_id,
2979 int nbr_grids, const char ** grid_names ) {
2980 struct yac_instance * instance =
2981 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
2982 struct yac_couple_config * couple_config =
2984 for(size_t i=0; i<nbr_grids; ++i){
2985 grid_names[i] = yac_couple_config_get_grid_name(couple_config, i);
2986 }
2987}
2988
2989void yac_cget_grid_names ( int nbr_grids, const char ** grid_names ) {
2990 check_default_instance_id("yac_cget_grid_names");
2991 yac_cget_grid_names_instance(default_instance_id, nbr_grids, grid_names);
2992}
2993
2994void yac_cget_comp_grid_names_instance ( int yac_instance_id, const char* comp_name,
2995 int nbr_grids, const char ** grid_names ) {
2996 struct yac_instance * instance =
2997 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
2998 struct yac_couple_config * couple_config =
3000 size_t idx = 0;
3001 YAC_ASSERT(comp_name != NULL,
3002 "ERROR(yac_cget_comp_grid_names_instance):"
3003 "Invalid comp_name. (NULL is not allowed)");
3004 for(size_t i=0; i<yac_couple_config_get_num_grids(couple_config); ++i){
3005 const char* grid_name = yac_couple_config_get_grid_name(couple_config, i);
3006 if (yac_cget_nbr_fields_instance(yac_instance_id, comp_name, grid_name) > 0){
3007 grid_names[idx] = grid_name;
3008 idx++;
3009 }
3010 }
3011}
3012
3013void yac_cget_comp_grid_names ( const char* comp_name, int nbr_grids,
3014 const char ** grid_names ) {
3015 check_default_instance_id("yac_cget_grid_names");
3016 yac_cget_comp_grid_names_instance(default_instance_id, comp_name, nbr_grids, grid_names);
3017}
3018
3019void yac_cget_field_names_instance ( int yac_instance_id,
3020 const char * comp_name, const char* grid_name,
3021 int nbr_fields, const char ** field_names ) {
3022 struct yac_instance * instance =
3023 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
3024 struct yac_couple_config * couple_config =
3026 size_t comp_idx = yac_couple_config_get_component_idx(couple_config, comp_name);
3027
3028 size_t nbr_comp_fields =
3029 yac_couple_config_get_num_fields(couple_config, comp_idx);
3030
3031 for(size_t field_idx=0; field_idx<nbr_comp_fields; ++field_idx) {
3032 if(yac_couple_config_field_is_valid(couple_config, comp_idx, field_idx) &&
3033 !strcmp(
3034 grid_name,
3036 couple_config, comp_idx, field_idx))) {
3037 *field_names =
3039 couple_config, comp_idx, field_idx);
3040 field_names++;
3041 }
3042 }
3043}
3044
3045void yac_cget_field_names ( const char* comp_name, const char* grid_name,
3046 int nbr_fields, const char ** field_names ) {
3047 check_default_instance_id("yac_cget_field_names");
3049 comp_name, grid_name, nbr_fields, field_names );
3050}
3051
3052const char* yac_cget_component_name_from_field_id ( int field_id ) {
3053 struct coupling_field * field =
3054 yac_unique_id_to_pointer(field_id, "field_id");
3055 YAC_ASSERT(field != NULL, "ERROR: field ID not defined!");
3057}
3058
3059const char* yac_cget_grid_name_from_field_id ( int field_id ) {
3060 struct coupling_field * field =
3061 yac_unique_id_to_pointer(field_id, "field_id");
3062 YAC_ASSERT(field != NULL, "ERROR: field ID not defined!");
3064 return yac_basic_grid_get_name(grid);
3065}
3066
3067const char* yac_cget_field_name_from_field_id ( int field_id ) {
3068 struct coupling_field * field =
3069 yac_unique_id_to_pointer(field_id, "field_id");
3070 YAC_ASSERT(field != NULL, "ERROR: field ID not defined!");
3071 return yac_get_coupling_field_name(field);
3072}
3073
3074const char* yac_cget_timestep_from_field_id ( int field_id ){
3075 struct coupling_field * field =
3076 yac_unique_id_to_pointer(field_id, "field_id");
3077 YAC_ASSERT(field != NULL, "ERROR: field ID not defined!");
3078 return yac_get_coupling_field_timestep(field);
3079}
3080
3082 struct coupling_field * field =
3083 yac_unique_id_to_pointer(field_id, "field_id");
3084 YAC_ASSERT(field != NULL, "ERROR: field ID not defined!");
3086}
3087
3088int yac_cget_role_from_field_id ( int field_id ){
3089 struct coupling_field * field =
3090 yac_unique_id_to_pointer(field_id, "field_id");
3091 YAC_ASSERT(field != NULL, "ERROR: field ID not defined!");
3093}
3094
3095/* ---------------------------------------------------------------------- */
3096
3098 int yac_instance_id, const char* comp_name, const char* grid_name,
3099 const char* field_name ) {
3100 struct yac_instance * instance =
3101 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
3102 struct yac_couple_config * couple_config =
3104 return
3106 couple_config, comp_name, grid_name, field_name);
3107}
3108
3109const char* yac_cget_field_timestep ( const char* comp_name, const char* grid_name,
3110 const char* field_name ) {
3111 check_default_instance_id("yac_cget_field_timestep");
3113 grid_name, field_name);
3114}
3115
3117 int yac_instance_id, const char* comp_name, const char* grid_name,
3118 const char* field_name) {
3119 struct yac_instance * instance =
3120 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
3121 return
3124 comp_name, grid_name, field_name);
3125}
3126
3128 const char* comp_name, const char* grid_name, const char* field_name ) {
3129 struct yac_instance * instance =
3130 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
3131 return
3134 comp_name, grid_name, field_name);
3135}
3136
3138 const char* comp_name, const char* grid_name, const char* field_name) {
3139 check_default_instance_id("yac_cget_field_frac_mask_fallback_value");
3140 return
3142 default_instance_id, comp_name, grid_name, field_name);
3143}
3144
3145int yac_cget_field_collection_size ( const char* comp_name,
3146 const char* grid_name, const char* field_name ) {
3147 check_default_instance_id("yac_cget_field_collection_size");
3149 grid_name, field_name);
3150}
3151
3152int yac_cget_field_role_instance ( int yac_instance_id, const char* comp_name,
3153 const char* grid_name, const char* field_name ) {
3154 struct yac_instance * instance =
3155 yac_unique_id_to_pointer(yac_instance_id, "yac_instance_id");
3156 struct yac_couple_config * couple_config =
3158 return
3160 couple_config, comp_name, grid_name, field_name);
3161}
3162
3163int yac_cget_field_role ( const char* comp_name, const char* grid_name,
3164 const char* field_name ) {
3165 check_default_instance_id("yac_cget_field_role");
3167 grid_name, field_name);
3168}
3169
3170/* ---------------------------------------------------------------------- */
3171
3173 const char * grid_name, int nbr_vertices[2], int cyclic[2],
3174 double *x_vertices, double *y_vertices, int *grid_id) {
3175
3176 size_t nbr_vertices_size_t[2] =
3177 {(size_t)nbr_vertices[0], (size_t)nbr_vertices[1]};
3178
3179 check_x_vertices(x_vertices, nbr_vertices[0], "yac_cdef_grid_reg2d");
3180 check_y_vertices(y_vertices, nbr_vertices[1], "yac_cdef_grid_reg2d");
3181
3182 *grid_id =
3185 nbr_vertices_size_t, cyclic, x_vertices, y_vertices));
3186}
3187
3188/* ---------------------------------------------------------------------- */
3189
3191 const char * grid_name, int nbr_vertices[2], int cyclic[2],
3192 double *x_vertices, double *y_vertices, int *grid_id) {
3193
3194 size_t nbr_vertices_size_t[2] =
3195 {(size_t)nbr_vertices[0], (size_t)nbr_vertices[1]};
3196
3197 check_x_vertices(x_vertices, nbr_vertices[0], "yac_cdef_grid_curve2d");
3198 check_y_vertices(y_vertices, nbr_vertices[1], "yac_cdef_grid_curve2d");
3199
3200 *grid_id =
3203 nbr_vertices_size_t, cyclic, x_vertices, y_vertices));
3204}
3205
3206/* ---------------------------------------------------------------------- */
3207
3209 const char * grid_name, int nbr_vertices,
3210 int nbr_cells, int *num_vertices_per_cell, double *x_vertices,
3211 double *y_vertices, int *cell_to_vertex, int *grid_id) {
3212
3213 check_x_vertices(x_vertices, nbr_vertices, "yac_cdef_grid_unstruct");
3214 check_y_vertices(y_vertices, nbr_vertices, "yac_cdef_grid_unstruct");
3215
3216 *grid_id =
3218 grid_name,
3220 (size_t)nbr_vertices, (size_t)nbr_cells, num_vertices_per_cell,
3221 x_vertices, y_vertices, cell_to_vertex));
3222}
3223
3224/* ---------------------------------------------------------------------- */
3225
3227 const char * grid_name, int nbr_vertices,
3228 int nbr_cells, int *num_vertices_per_cell, double *x_vertices,
3229 double *y_vertices, int *cell_to_vertex, int *grid_id) {
3230
3231 check_x_vertices(x_vertices, nbr_vertices, "yac_cdef_grid_unstruct_ll");
3232 check_y_vertices(y_vertices, nbr_vertices, "yac_cdef_grid_unstruct_ll");
3233
3234 *grid_id =
3236 grid_name,
3238 (size_t)nbr_vertices, (size_t)nbr_cells, num_vertices_per_cell,
3239 x_vertices, y_vertices, cell_to_vertex));
3240}
3241
3242/* ---------------------------------------------------------------------- */
3243
3245 int const * global_index, int location, int grid_id) {
3246
3247 struct yac_basic_grid_data * grid_data =
3249
3250 yac_int ** grid_global_ids;
3251 size_t count;
3252
3253 YAC_ASSERT(
3254 (location == YAC_LOC_CELL) ||
3255 (location == YAC_LOC_CORNER) ||
3256 (location == YAC_LOC_EDGE),
3257 "ERROR(yac_cset_global_index): invalid location")
3258 switch (location) {
3259 case (YAC_LOC_CELL): {
3260 grid_global_ids = &(grid_data->cell_ids);
3261 count = grid_data->num_cells;
3262 break;
3263 }
3264 case (YAC_LOC_CORNER): {
3265 grid_global_ids = &(grid_data->vertex_ids);
3266 count = grid_data->num_vertices;
3267 break;
3268 }
3269 default:
3270 case (YAC_LOC_EDGE): {
3271 grid_global_ids = &(grid_data->edge_ids);
3272 count = grid_data->num_edges;
3273 break;
3274 }
3275 }
3276
3277 size_t global_ids_size = count * sizeof(**grid_global_ids);
3278 if (*grid_global_ids == NULL) *grid_global_ids = xmalloc(global_ids_size);
3279 for (size_t i = 0; i < count; ++i)
3280 (*grid_global_ids)[i] = (yac_int)(global_index[i]);
3281}
3282
3283/* ---------------------------------------------------------------------- */
3284
3286 int const * is_core, int location, int grid_id) {
3287
3288 struct yac_basic_grid_data * grid_data =
3290
3291 int ** grid_core_mask;
3292 size_t count;
3293
3294 YAC_ASSERT(
3295 (location == YAC_LOC_CELL) ||
3296 (location == YAC_LOC_CORNER) ||
3297 (location == YAC_LOC_EDGE),
3298 "ERROR(yac_cset_core_mask): invalid location")
3299 switch (location) {
3300 case (YAC_LOC_CELL): {
3301 grid_core_mask = &(grid_data->core_cell_mask);
3302 count = grid_data->num_cells;
3303 break;
3304 }
3305 case (YAC_LOC_CORNER): {
3306 grid_core_mask = &(grid_data->core_vertex_mask);
3307 count = grid_data->num_vertices;
3308 break;
3309 }
3310 default:
3311 case (YAC_LOC_EDGE): {
3312 grid_core_mask = &(grid_data->core_edge_mask);
3313 count = grid_data->num_edges;
3314 break;
3315 }
3316 }
3317
3318 size_t core_mask_size = count * sizeof(**grid_core_mask);
3319 if (*grid_core_mask == NULL) *grid_core_mask = xmalloc(core_mask_size);
3320 memcpy(*grid_core_mask, is_core, core_mask_size);
3321}
3322
3323/* ---------------------------------------------------------------------- */
3324
3325size_t yac_cget_grid_size ( int located, int grid_id ) {
3326
3327 struct yac_basic_grid * grid =
3328 yac_unique_id_to_pointer(grid_id, "grid_id");
3329 enum yac_location location = yac_get_location(located);
3330
3331 return yac_basic_grid_get_data_size(grid, location);
3332}
3333
3334/* ---------------------------------------------------------------------- */
3335
3336size_t yac_cget_points_size ( int points_id ) {
3337
3339 yac_unique_id_to_pointer(points_id, "points_id");
3340 struct yac_basic_grid * grid = points->grid;
3341 enum yac_location location = points->location;
3342
3343 return yac_basic_grid_get_data_size(grid, location);
3344}
3345
3346/* ---------------------------------------------------------------------- */
3347
3361
3362void yac_cfree_interp_stack_config(int interp_stack_config_id) {
3363
3364 struct yac_interp_stack_config * interp_stack_config =
3366 interp_stack_config_id, "interp_stack_config_id");
3367 yac_interp_stack_config_delete(interp_stack_config);
3368
3369 int flag = 0;
3370 for (size_t i = 0; i < num_interp_stack_configs; ++i) {
3371 if (interp_stack_configs[i] == interp_stack_config)
3372 interp_stack_configs[i] = NULL;
3373 flag |= (interp_stack_configs[i] != NULL);
3374 }
3375 if (!flag) {
3377 interp_stack_configs = NULL;
3379 }
3380}
3381
3383 int interp_stack_config_id,
3384 int reduction_type, int partial_coverage) {
3385
3386 struct yac_interp_stack_config * interp_stack_config =
3388 interp_stack_config_id, "interp_stack_config_id");
3389
3390 YAC_ASSERT(
3391 (reduction_type == YAC_INTERP_AVG_ARITHMETIC) ||
3392 (reduction_type == YAC_INTERP_AVG_DIST) ||
3393 (reduction_type == YAC_INTERP_AVG_BARY),
3394 "ERROR(yac_add_interp_stack_config_average): invalid reduction type")
3395
3397 interp_stack_config, (enum yac_interp_avg_weight_type)reduction_type,
3398 partial_coverage);
3399}
3400
3402 int interp_stack_config_id,
3403 int weight_type, int partial_coverage) {
3404
3405 struct yac_interp_stack_config * interp_stack_config =
3407 interp_stack_config_id, "interp_stack_config_id");
3408
3409 YAC_ASSERT(
3410 (weight_type == YAC_INTERP_NCC_AVG) ||
3411 (weight_type == YAC_INTERP_NCC_DIST),
3412 "ERROR(yac_add_interp_stack_config_ncc): invalid reduction type")
3413
3415 interp_stack_config, (enum yac_interp_ncc_weight_type)weight_type,
3416 partial_coverage);
3417}
3418
3420 int interp_stack_config_id,
3421 int type, size_t n, double scale) {
3422
3423 struct yac_interp_stack_config * interp_stack_config =
3425 interp_stack_config_id, "interp_stack_config_id");
3426
3427 YAC_ASSERT(
3428 (type == YAC_INTERP_NNN_AVG) ||
3431 (type == YAC_INTERP_NNN_RBF) ||
3433 "ERROR(yac_add_interp_stack_config_nnn): invalid weightening type")
3434
3436 interp_stack_config, (enum yac_interp_nnn_weight_type)type, n, scale);
3437}
3438
3440 int interp_stack_config_id, int order, int enforced_conserv,
3441 int partial_coverage, int normalisation) {
3442
3443 struct yac_interp_stack_config * interp_stack_config =
3445 interp_stack_config_id, "interp_stack_config_id");
3446
3447 YAC_ASSERT(
3448 (normalisation == YAC_INTERP_CONSERV_DESTAREA) ||
3449 (normalisation == YAC_INTERP_CONSERV_FRACAREA),
3450 "ERROR(yac_add_interp_stack_config_conservative):"
3451 "invalid normalisation type")
3452
3454 interp_stack_config, order, enforced_conserv, partial_coverage,
3455 (enum yac_interp_method_conserv_normalisation)normalisation);
3456}
3457
3459 int interp_stack_config_id, double spread_distance,
3460 double max_search_distance, int weight_type, int scale_type,
3461 double src_sphere_radius, double tgt_sphere_radius) {
3462
3463 struct yac_interp_stack_config * interp_stack_config =
3465 interp_stack_config_id, "interp_stack_config_id");
3466
3467 YAC_ASSERT(
3468 (weight_type == YAC_INTERP_SPMAP_AVG) ||
3469 (weight_type == YAC_INTERP_SPMAP_DIST),
3470 "ERROR(yac_add_interp_stack_config_spmap):"
3471 "invalid weightening type")
3472
3473 YAC_ASSERT(
3474 (scale_type == YAC_INTERP_SPMAP_NONE) ||
3475 (scale_type == YAC_INTERP_SPMAP_SRCAREA) ||
3476 (scale_type == YAC_INTERP_SPMAP_INVTGTAREA) ||
3477 (scale_type == YAC_INTERP_SPMAP_FRACAREA),
3478 "ERROR(yac_add_interp_stack_config_spmap):"
3479 "invalid scaling type")
3480
3482 interp_stack_config, spread_distance, max_search_distance,
3483 (enum yac_interp_spmap_weight_type)weight_type,
3484 (enum yac_interp_spmap_scale_type)scale_type,
3485 src_sphere_radius, tgt_sphere_radius);
3486}
3487
3488void yac_cadd_interp_stack_config_hcsbb(int interp_stack_config_id) {
3489
3490 struct yac_interp_stack_config * interp_stack_config =
3492 interp_stack_config_id, "interp_stack_config_id");
3493
3494 yac_interp_stack_config_add_hcsbb(interp_stack_config);
3495}
3496
3498 int interp_stack_config_id, char const * filename, char const * src_grid_name,
3499 char const * tgt_grid_name) {
3500
3501 struct yac_interp_stack_config * interp_stack_config =
3503 interp_stack_config_id, "interp_stack_config_id");
3504
3506 interp_stack_config, filename, src_grid_name,
3507 tgt_grid_name);
3508}
3509
3511 int interp_stack_config_id, double value) {
3512
3513 struct yac_interp_stack_config * interp_stack_config =
3515 interp_stack_config_id, "interp_stack_config_id");
3516
3517 yac_interp_stack_config_add_fixed(interp_stack_config, value);
3518}
3519
3521 int interp_stack_config_id, char const * constructor_key,
3522 char const * do_search_key) {
3523
3524 struct yac_interp_stack_config * interp_stack_config =
3526 interp_stack_config_id, "interp_stack_config_id");
3527
3529 interp_stack_config, constructor_key, do_search_key);
3530}
3531
3533 int interp_stack_config_id, int creep_distance) {
3534
3535 struct yac_interp_stack_config * interp_stack_config =
3537 interp_stack_config_id, "interp_stack_config_id");
3538
3539 yac_interp_stack_config_add_creep(interp_stack_config, creep_distance);
3540}
3541
3543 int interp_stack_config_id, char const * func_compute_weights_key) {
3544
3545 struct yac_interp_stack_config * interp_stack_config =
3547 interp_stack_config_id, "interp_stack_config_id");
3548
3550 interp_stack_config, func_compute_weights_key);
3551}
3552
3553/* ---------------------------------------------------------------------- */
3554
3556 yac_func_compute_weights compute_weights_callback,
3557 void * user_data, char const * key) {
3558
3560 compute_weights_callback, user_data, key);
3561}
struct yac_basic_grid * yac_basic_grid_new(char const *name, struct yac_basic_grid_data grid_data)
Definition basic_grid.c:45
struct yac_basic_grid_data * yac_basic_grid_get_data(struct yac_basic_grid *grid)
Definition basic_grid.c:132
size_t yac_basic_grid_add_mask(struct yac_basic_grid *grid, enum yac_location location, int const *mask, size_t count, char const *mask_name)
Definition basic_grid.c:279
size_t yac_basic_grid_add_coordinates_nocpy(struct yac_basic_grid *grid, enum yac_location location, yac_coordinate_pointer coordinates)
Definition basic_grid.c:203
char const * yac_basic_grid_get_name(struct yac_basic_grid *grid)
Definition basic_grid.c:123
size_t yac_basic_grid_get_data_size(struct yac_basic_grid *grid, enum yac_location location)
Definition basic_grid.c:142
void yac_basic_grid_delete(struct yac_basic_grid *grid)
Definition basic_grid.c:65
struct yac_basic_grid_data yac_generate_basic_grid_data_reg_2d(size_t nbr_vertices[2], int cyclic[2], double *lon_vertices, double *lat_vertices)
Definition grid_reg2d.c:65
struct yac_basic_grid_data yac_generate_basic_grid_data_unstruct_ll(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_curve_2d(size_t nbr_vertices[2], int cyclic[2], double *lon_vertices, double *lat_vertices)
struct yac_basic_grid_data yac_generate_basic_grid_data_unstruct(size_t nbr_vertices, size_t nbr_cells, int *num_vertices_per_cell, double *x_vertices, double *y_vertices, int *cell_to_vertex)
int YAC_YAML_EMITTER_JSON
emit to JSON format
Definition config_yaml.c:47
void yac_yaml_read_coupling(struct yac_couple_config *couple_config, const char *yaml_filename, int parse_flags)
int YAC_YAML_PARSER_DEFAULT
default parse flags (YAML format)
Definition config_yaml.c:48
int YAC_YAML_PARSER_JSON_FORCE
assume JSON format
Definition config_yaml.c:50
int YAC_YAML_EMITTER_DEFAULT
emit to YAML format
Definition config_yaml.c:46
char const * yac_time_to_ISO(char const *time, enum yac_time_unit_type time_unit)
Definition event.c:329
@ COUPLING
Definition config_yaml.c:83
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_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)
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_get_field_role(struct yac_couple_config *couple_config, char const *component_name, char const *grid_name, char const *field_name)
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)
char const * yac_couple_config_get_field_name(struct yac_couple_config *couple_config, size_t component_idx, size_t field_idx)
void yac_couple_config_component_set_metadata(struct yac_couple_config *couple_config, char const *comp_name, const char *metadata)
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)
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)
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)
size_t yac_couple_config_get_component_idx(struct yac_couple_config *couple_config, char const *component_name)
char const * yac_couple_config_get_grid_name(struct yac_couple_config *couple_config, size_t grid_idx)
char const * yac_couple_config_get_component_name(struct yac_couple_config *couple_config, size_t component_idx)
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)
size_t yac_couple_config_get_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_components(struct yac_couple_config *couple_config)
@ TIME_NONE
@ TIME_ACCUMULATE
@ TIME_MAXIMUM
@ TIME_MINIMUM
@ TIME_AVERAGE
yac_time_unit_type
@ C_SECOND
@ C_HOUR
@ C_DAY
@ C_MILLISECOND
@ C_MINUTE
@ C_MONTH
@ C_ISO_FORMAT
@ C_YEAR
int yac_get_event_time_operation(struct event *event)
Definition event.c:284
enum yac_action_type yac_event_check(struct event *event)
Definition event.c:171
void yac_event_update(struct event *event)
Definition event.c:159
yac_action_type
Definition event.h:17
@ REDUCTION
Definition event.h:19
@ RESTART
Definition event.h:21
@ OUT_OF_BOUND
Definition event.h:26
@ GET_FOR_CHECKPOINT
Definition event.h:24
@ NONE
Definition event.h:18
@ PUT_FOR_RESTART
Definition event.h:23
@ GET_FOR_RESTART
Definition event.h:22
@ PUT_FOR_CHECKPOINT
Definition event.h:25
unsigned yac_get_coupling_field_collection_size(struct coupling_field *field)
Definition fields.c:86
const char * yac_get_coupling_field_timestep(struct coupling_field *field)
Definition fields.c:91
unsigned yac_get_coupling_field_num_puts(struct coupling_field *field)
Definition fields.c:438
char const * yac_get_coupling_field_comp_name(struct coupling_field *field)
Definition fields.c:119
int yac_get_coupling_field_put_op_time_accumulation_count(struct coupling_field *field, unsigned put_idx)
Definition fields.c:413
double *** yac_get_coupling_field_put_op_send_frac_mask_acc(struct coupling_field *field, unsigned put_idx)
Definition fields.c:209
struct yac_basic_grid * yac_coupling_field_get_basic_grid(struct coupling_field *field)
Definition fields.c:113
size_t yac_coupling_field_get_num_interp_fields(struct coupling_field *field)
Definition fields.c:96
struct yac_interpolation * yac_get_coupling_field_put_op_interpolation(struct coupling_field *field, unsigned put_idx)
Definition fields.c:401
enum yac_location yac_get_coupling_field_get_interp_field_location(struct coupling_field *field, size_t interp_field_idx)
Definition fields.c:102
struct event * yac_get_coupling_field_get_op_event(struct coupling_field *field)
Definition fields.c:446
size_t yac_coupling_field_get_data_size(struct coupling_field *field, enum yac_location location)
Definition fields.c:136
struct yac_interp_field const * yac_coupling_field_get_interp_fields(struct coupling_field *cpl_field)
Definition fields.c:509
int * yac_get_coupling_field_get_mask(struct coupling_field *field)
Definition fields.c:310
struct event * yac_get_coupling_field_put_op_event(struct coupling_field *field, unsigned put_idx)
Definition fields.c:389
char * yac_coupling_field_get_datetime(struct coupling_field *cpl_field)
Definition fields.c:515
void yac_init_coupling_field_put_op_send_field_acc(struct coupling_field *field, unsigned put_idx, double init_value)
Definition fields.c:347
struct yac_interpolation * yac_get_coupling_field_get_op_interpolation(struct coupling_field *field)
Definition fields.c:456
void yac_set_coupling_field_put_op_time_accumulation_count(struct coupling_field *field, unsigned put_idx, int count)
Definition fields.c:426
enum yac_field_exchange_type yac_get_coupling_field_exchange_type(struct coupling_field *field)
Definition fields.c:125
const char * yac_get_coupling_field_name(struct coupling_field *field)
Definition fields.c:108
int ** yac_get_coupling_field_put_mask(struct coupling_field *field)
Definition fields.c:265
void yac_init_coupling_field_put_op_send_frac_mask_acc(struct coupling_field *field, unsigned put_idx, double init_value)
Definition fields.c:368
double *** yac_get_coupling_field_put_op_send_field_acc(struct coupling_field *field, unsigned put_idx)
Definition fields.c:199
yac_field_exchange_type
Definition fields.h:12
@ SOURCE
Definition fields.h:14
@ TARGET
Definition fields.h:15
@ NOTHING
Definition fields.h:13
static void LLtoXYZ(double lon, double lat, double p_out[])
Definition geometry.h:287
void yac_instance_delete(struct yac_instance *instance)
Definition instance.c:1240
char * yac_instance_setup_and_emit_config(struct yac_instance *instance, int emit_flags)
Definition instance.c:1180
int yac_instance_get_comp_rank(struct yac_instance *instance, const char *comp_name)
Definition instance.c:1206
char * yac_instance_get_start_datetime(struct yac_instance *instance)
Definition instance.c:1280
char * yac_instance_get_end_datetime(struct yac_instance *instance)
Definition instance.c:1285
void yac_instance_def_datetime(struct yac_instance *instance, const char *start_datetime, const char *end_datetime)
Definition instance.c:1272
void yac_instance_sync_def(struct yac_instance *instance)
Definition instance.c:1149
struct yac_instance * yac_instance_new(MPI_Comm comm)
Definition instance.c:1215
int yac_instance_components_are_defined(struct yac_instance *instance)
Definition instance.c:1312
void yac_instance_setup(struct yac_instance *instance)
Definition instance.c:1157
struct coupling_field * yac_instance_add_field(struct yac_instance *instance, char const *field_name, char const *comp_name, struct yac_basic_grid *grid, struct yac_interp_field *interp_fields, size_t num_interp_fields, int collection_size, char const *timestep)
Definition instance.c:1317
void yac_instance_dummy_new(MPI_Comm comm)
Definition instance.c:1234
void yac_instance_def_components(struct yac_instance *instance, char const **comp_names, size_t num_comps)
Definition instance.c:1290
struct yac_couple_config * yac_instance_get_couple_config(struct yac_instance *instance)
Definition instance.c:1257
void yac_instance_def_couple(struct yac_instance *instance, 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_config, int src_lag, int tgt_lag, const char *weight_file_name, 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)
Definition instance.c:1376
int yac_instance_get_comp_size(struct yac_instance *instance, const char *comp_name)
Definition instance.c:1197
MPI_Comm yac_instance_get_comps_comm(struct yac_instance *instance, char const **comp_names, size_t num_comp_names)
Definition instance.c:1188
struct coupling_field * yac_instance_get_field(struct yac_instance *instance, const char *comp_name, const char *grid_name, const char *field_name)
Definition instance.c:1397
yac_interp_avg_weight_type
@ YAC_INTERP_AVG_DIST
@ YAC_INTERP_AVG_ARITHMETIC
@ YAC_INTERP_AVG_BARY
void * user_data
char * key
void yac_interp_method_callback_add_compute_weights_callback(yac_func_compute_weights compute_weights_callback, void *user_data, char const *key)
void(* yac_func_compute_weights)(double const tgt_coords[3], int src_cell_id, size_t src_cell_idx, int const **global_results_points, double **result_weights, size_t *result_count, void *user_data)
struct @8::@9 value
enum callback_type type
yac_interp_method_conserv_normalisation
@ YAC_INTERP_CONSERV_DESTAREA
@ YAC_INTERP_CONSERV_FRACAREA
yac_interp_ncc_weight_type
@ YAC_INTERP_NCC_DIST
distance weighted average of n source points
@ YAC_INTERP_NCC_AVG
average of n source points
yac_interp_nnn_weight_type
@ 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
@ YAC_INTERP_NNN_ZERO
all weights are set to zero
yac_interp_spmap_scale_type
@ YAC_INTERP_SPMAP_NONE
weights are not scaled
@ YAC_INTERP_SPMAP_INVTGTAREA
@ YAC_INTERP_SPMAP_SRCAREA
@ YAC_INTERP_SPMAP_FRACAREA
yac_interp_spmap_weight_type
@ YAC_INTERP_SPMAP_AVG
@ YAC_INTERP_SPMAP_DIST
void yac_interp_stack_config_add_check(struct yac_interp_stack_config *interp_stack_config, char const *constructor_key, char const *do_search_key)
void yac_interp_stack_config_add_user_file(struct yac_interp_stack_config *interp_stack_config, char const *filename, char const *src_grid_name, char const *tgt_grid_name)
void yac_interp_stack_config_add_spmap(struct yac_interp_stack_config *interp_stack_config, double spread_distance, double max_search_distance, enum yac_interp_spmap_weight_type weight_type, enum yac_interp_spmap_scale_type scale_type, double src_sphere_radius, double tgt_sphere_radius)
void yac_interp_stack_config_add_nnn(struct yac_interp_stack_config *interp_stack_config, enum yac_interp_nnn_weight_type type, size_t n, double scale)
void yac_interp_stack_config_add_fixed(struct yac_interp_stack_config *interp_stack_config, double value)
void yac_interp_stack_config_add_hcsbb(struct yac_interp_stack_config *interp_stack_config)
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_add_creep(struct yac_interp_stack_config *interp_stack_config, int creep_distance)
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)
void yac_interp_stack_config_add_ncc(struct yac_interp_stack_config *interp_stack_config, enum yac_interp_ncc_weight_type weight_type, int partial_coverage)
void yac_interp_stack_config_add_user_callback(struct yac_interp_stack_config *interp_stack_config, char const *func_compute_weights_key)
struct yac_interp_stack_config * yac_interp_stack_config_new()
void yac_interpolation_execute(struct yac_interpolation *interp, double ***src_fields, double **tgt_field)
int yac_interpolation_with_frac_mask(struct yac_interpolation *interpolation)
int yac_interpolation_execute_put_test(struct yac_interpolation *interp)
void yac_interpolation_execute_wait(struct yac_interpolation *interp)
void yac_interpolation_execute_frac(struct yac_interpolation *interp, double ***src_fields, double ***src_frac_masks, double **tgt_field)
void yac_interpolation_execute_get(struct yac_interpolation *interp, double **tgt_field)
void yac_interpolation_execute_get_async(struct yac_interpolation *interp, double **tgt_field)
void yac_interpolation_execute_put_frac(struct yac_interpolation *interp, double ***src_fields, double ***src_frac_masks)
void yac_interpolation_execute_put(struct yac_interpolation *interp, double ***src_fields)
int yac_interpolation_execute_get_test(struct yac_interpolation *interp)
enum yac_location yac_get_location(int const location)
Definition location.c:44
yac_location
Definition location.h:12
@ YAC_LOC_CORNER
Definition location.h:15
@ YAC_LOC_EDGE
Definition location.h:16
@ YAC_LOC_CELL
Definition location.h:14
void yac_mpi_handshake(MPI_Comm comm, size_t n, char const **group_names, MPI_Comm *group_comms)
#define xrealloc(ptr, size)
Definition ppm_xfuncs.h:67
#define xmalloc(size)
Definition ppm_xfuncs.h:66
double *** send_field_acc
Definition fields.c:39
double *** send_frac_mask_acc
Definition fields.c:40
enum yac_field_exchange_type exchange_type
Definition fields.c:31
unsigned num_puts
Definition fields.c:42
size_t num_interp_fields
Definition fields.c:23
size_t collection_size
number of vertical levels or bundles
Definition fields.c:24
Definition event.c:18
enum yac_reduction_type time_operation
Definition event.c:24
enum yac_action_type action
Definition event.c:25
struct yac_instance * instance
Definition yac.c:90
enum yac_location location
Definition yac.c:103
struct yac_basic_grid * grid
Definition yac.c:102
enum yac_location location
Definition yac.c:97
struct yac_basic_grid * grid
Definition yac.c:96
size_t coordinates_idx
Definition yac.c:98
size_t num_src_mask_names
Definition yac.c:134
char * weight_file
Definition yac.c:130
char * tgt_mask_name
Definition yac.c:136
char ** src_mask_names
Definition yac.c:135
double scale_summand
Definition yac.c:133
double scale_factor
Definition yac.c:132
enum yac_location location
Definition basic_grid.h:18
size_t coordinates_idx
Definition basic_grid.h:19
#define MAX(a, b)
static char * yac_version
Definition version.h:7
int const YAC_YEAR_OF_365_DAYS
Definition yac.c:62
int const YAC_ACTION_PUT_FOR_CHECKPOINT
Definition yac.c:42
int const YAC_REDUCTION_TIME_AVERAGE
Definition yac.c:47
void yac_cenddef_and_emit_config(int emit_flags, char **config)
Definition yac.c:2855
static int yac_lookup_pointer(void const *pointer)
Definition yac.c:181
#define NO_CHECK
void yac_cinit_comm_dummy(MPI_Comm comm)
Definition yac.c:412
void yac_cget_grid_names(int nbr_grids, const char **grid_names)
Definition yac.c:2989
void yac_cadd_interp_stack_config_ncc(int interp_stack_config_id, int weight_type, int partial_coverage)
Definition yac.c:3401
void yac_cget_ext_couple_config_scale_factor(int ext_couple_config_id, double *scale_factor)
Definition yac.c:1316
const char * yac_cget_field_metadata_instance(int yac_instance_id, const char *comp_name, const char *grid_name, const char *field_name)
Definition yac.c:1206
void yac_cput_frac(int const field_id, int const collection_size, double ***const send_field, double ***const send_frac_mask, int *info, int *ierr)
Definition yac.c:2425
int const YAC_NCC_AVG
Definition yac.c:69
void yac_cadd_interp_stack_config_spmap(int interp_stack_config_id, double spread_distance, double max_search_distance, int weight_type, int scale_type, double src_sphere_radius, double tgt_sphere_radius)
Definition yac.c:3458
#define SUM
static struct yac_interpolation * yac_cget_pre_processing(int const field_id, int collection_size, int *info, int *ierr)
Definition yac.c:1740
void yac_cenddef(void)
Definition yac.c:2840
static int yac_init(MPI_Comm comm)
Definition yac.c:343
static void get_send_field_pointers_ptr_(int const field_id, int const collection_size, double **send_field, double **send_frac_mask, double ****send_field_, double ****send_frac_mask_)
Definition yac.c:1971
void yac_cenable_field_frac_mask(const char *comp_name, const char *grid_name, const char *field_name, double frac_mask_fallback_value)
Definition yac.c:1128
int const YAC_ACTION_OUT_OF_BOUND
Definition yac.c:43
void yac_cget_ext_couple_config_mapping_side(int ext_couple_config_id, int *mapping_side)
Definition yac.c:1293
static void get_send_field_pointers(int const field_id, int const collection_size, double *send_field, double *send_frac_mask, double ****send_field_, double ****send_frac_mask_)
Definition yac.c:1871
void yac_cpredef_comp_instance(int yac_instance_id, char const *name, int *comp_id)
Definition yac.c:718
int const YAC_SPMAP_SRCAREA
Definition yac.c:85
char * yac_cget_start_datetime_instance(int yac_instance_id)
Definition yac.c:581
void yac_cdef_field_mask(char const *name, int const comp_id, int const *point_ids, int const *mask_ids, int const num_pointsets, int collection_size, const char *timestep, int time_unit, int *field_id)
Definition yac.c:1012
void yac_cset_global_index(int const *global_index, int location, int grid_id)
Definition yac.c:3244
int const YAC_NNN_RBF
Definition yac.c:75
void yac_cdef_datetime_instance(int yac_instance_id, const char *start_datetime, const char *end_datetime)
Definition yac.c:545
int yac_cget_role_from_field_id(int field_id)
Definition yac.c:3088
void yac_cget_(int const field_id, int const collection_size, double *recv_field, int *info, int *ierr)
Definition yac.c:1832
int yac_cget_nbr_grids_instance(int yac_instance_id)
Definition yac.c:2900
void yac_cfree_ext_couple_config(int ext_couple_config_id)
Definition yac.c:1241
const char * yac_cget_grid_metadata_instance(int yac_instance_id, const char *grid_name)
Definition yac.c:1193
char * yac_cget_end_datetime_instance(int yac_instance_id)
Definition yac.c:596
void yac_cdef_datetime(const char *start_datetime, const char *end_datetime)
Definition yac.c:554
int const YAC_SPMAP_INVTGTAREA
Definition yac.c:86
void yac_cget_ext_couple_config_mask_name(int ext_couple_config_id, char const **tgt_mask_name)
Definition yac.c:1394
void yac_get_comp_comm_f2c(int comp_id, MPI_Fint *comp_comm_f)
Definition yac.c:650
int const YAC_LOCATION_CELL
Definition yac.c:27
int const YAC_REDUCTION_TIME_MINIMUM
Definition yac.c:48
void yac_cset_ext_couple_config_tgt_mask_name(int ext_couple_config_id, char const *tgt_mask_name)
Definition yac.c:1387
void yac_cdef_couple_custom_instance_(int yac_instance_id, char const *src_comp_name, char const *src_grid_name, char const *src_field_name, char const *tgt_comp_name, char const *tgt_grid_name, char const *tgt_field_name, char const *coupling_timestep, int time_unit, int time_reduction, int interp_stack_config_id, int src_lag, int tgt_lag, struct yac_ext_couple_config *ext_couple_config)
Definition yac.c:1401
static int user_input_data_add_mask(struct yac_basic_grid *grid, enum yac_location location, int const *is_valid, size_t nbr_points, char const *name)
Definition yac.c:946
void yac_cdef_grid_metadata(const char *grid_name, const char *metadata)
Definition yac.c:1159
int const YAC_TIME_UNIT_MINUTE
Definition yac.c:53
void yac_cdef_grid_curve2d(const char *grid_name, int nbr_vertices[2], int cyclic[2], double *x_vertices, double *y_vertices, int *grid_id)
Definition yac.c:3190
void yac_cread_config_json(const char *yaml_filename)
Definition yac.c:471
void * yac_get_field_get_mask_c2f(int field_id)
Definition yac.c:2118
void yac_cget_grid_names_instance(int yac_instance_id, int nbr_grids, const char **grid_names)
Definition yac.c:2978
void yac_cset_ext_couple_config_scale_factor(int ext_couple_config_id, double scale_factor)
Definition yac.c:1309
static void yac_free_masks()
Definition yac.c:246
int const YAC_NCC_DIST
Definition yac.c:70
int const YAC_ACTION_GET_FOR_CHECKPOINT
Definition yac.c:41
void yac_cadd_interp_stack_config_creep(int interp_stack_config_id, int creep_distance)
Definition yac.c:3532
static void check_default_instance_id(char const *routine_name)
Definition yac.c:281
void yac_cput_frac_(int const field_id, int const collection_size, double *send_field, double *send_frac_mask, int *info, int *ierr)
Definition yac.c:1938
void yac_cdef_component_metadata(const char *comp_name, const char *metadata)
Definition yac.c:1145
int const YAC_TIME_UNIT_YEAR
Definition yac.c:57
static void yac_free_components()
Definition yac.c:256
void yac_cget_comps_comm_instance_f2c(int yac_instance_id, char const **comp_names, int num_comps, MPI_Fint *comps_comm_f)
Definition yac.c:698
void yac_cget_comp_rank_c2py(int comp_id, int *rank)
Definition yac.c:667
void * yac_get_field_put_mask_c2f(int field_id)
Definition yac.c:2110
int yac_cget_field_role(const char *comp_name, const char *grid_name, const char *field_name)
Definition yac.c:3163
void yac_ccleanup()
Definition yac.c:505
int const YAC_AVG_ARITHMETIC
Definition yac.c:65
void yac_cget_comp_size_c2py(int comp_id, int *size)
Definition yac.c:660
void yac_cadd_compute_weights_callback(yac_func_compute_weights compute_weights_callback, void *user_data, char const *key)
Definition yac.c:3555
void yac_cmpi_handshake(MPI_Comm comm, size_t n, char const **group_names, MPI_Comm *group_comms)
Definition yac.c:327
int const YAC_REDUCTION_TIME_MAXIMUM
Definition yac.c:49
void yac_cset_ext_couple_config_scale_summand_(struct yac_ext_couple_config *ext_couple_config, double scale_summand)
Definition yac.c:1323
int const YAC_TIME_UNIT_MILLISECOND
Definition yac.c:51
void yac_cexchange_frac(int const send_field_id, int const recv_field_id, int const collection_size, double ***const send_field, double ***const send_frac_mask, double **recv_field, int *send_info, int *recv_info, int *ierr)
Definition yac.c:2669
int yac_cget_field_id_instance(int yac_instance_id, const char *comp_name, const char *grid_name, const char *field_name)
Definition yac.c:2866
int yac_cget_comp_nbr_grids_instance(int yac_instance_id, const char *comp_name)
Definition yac.c:2913
void yac_cdef_grid_unstruct_ll(const char *grid_name, int nbr_vertices, int nbr_cells, int *num_vertices_per_cell, double *x_vertices, double *y_vertices, int *cell_to_vertex, int *grid_id)
Definition yac.c:3226
const char * yac_cget_timestep_from_field_id(int field_id)
Definition yac.c:3074
static struct user_input_data_component ** components
Definition yac.c:117
int yac_cget_nbr_fields(const char *comp_name, const char *grid_name)
Definition yac.c:2956
#define ASSIGN
int const YAC_NNN_GAUSS
Definition yac.c:74
void yac_cinit_comm_dummy_f2c(MPI_Fint comm_f)
Definition yac.c:422
void yac_csync_def_instance(int yac_instance_id)
Definition yac.c:2821
void yac_cset_ext_couple_config_src_mask_names_(struct yac_ext_couple_config *ext_couple_config, size_t num_src_mask_names, char const *const *src_mask_names)
Definition yac.c:1346
static void cleanup()
Definition yac.c:514
void yac_cpredef_comp(char const *name, int *comp_id)
Definition yac.c:751
int yac_cyaml_get_emitter_flag_default_c2f()
Definition yac.c:437
void yac_csync_def(void)
Definition yac.c:2826
static double ** get_recv_field_pointers(int const field_id, int const collection_size, double *recv_field)
Definition yac.c:1712
int const YAC_TIME_UNIT_HOUR
Definition yac.c:54
void yac_cinit(void)
Definition yac.c:402
int const YAC_YEAR_OF_360_DAYS
Definition yac.c:63
void yac_cfinalize_instance(int yac_instance_id)
Definition yac.c:524
static struct user_input_data_masks ** masks
Definition yac.c:123
static void init_ext_couple_config(struct yac_ext_couple_config *ext_couple_config)
Definition yac.c:1222
void yac_cfinalize()
Definition yac.c:533
const char * yac_cget_field_name_from_field_id(int field_id)
Definition yac.c:3067
void yac_cadd_interp_stack_config_check(int interp_stack_config_id, char const *constructor_key, char const *do_search_key)
Definition yac.c:3520
void yac_cenddef_instance(int yac_instance_id)
Definition yac.c:2834
void yac_cset_ext_couple_config_src_mask_names(int ext_couple_config_id, size_t num_src_mask_names, char const *const *src_mask_names)
Definition yac.c:1362
int yac_cget_nbr_comps_instance(int yac_instance_id)
Definition yac.c:2887
int yac_cget_nbr_fields_instance(int yac_instance_id, const char *comp_name, const char *grid_name)
Definition yac.c:2936
void yac_cget_ext_couple_config(int *ext_couple_config_id)
Definition yac.c:1233
static size_t num_masks
Definition yac.c:124
static void yac_get(int const field_id, int collection_size, double **recv_field, int is_async, int *info, int *ierr)
Definition yac.c:1792
size_t num_grids
Definition yac.c:115
void yac_cdef_grid_metadata_instance(int yac_instance_id, const char *grid_name, const char *metadata)
Definition yac.c:1150
void yac_cset_ext_couple_config_weight_file(int ext_couple_config_id, char const *weight_file)
Definition yac.c:1260
const char * yac_cget_component_metadata_instance(int yac_instance_id, const char *comp_name)
Definition yac.c:1180
void yac_cread_config_yaml_instance(int yac_instance_id, const char *yaml_filename)
Definition yac.c:448
static struct user_input_data_component * get_user_input_data_component(int comp_id, char const *routine)
Definition yac.c:620
int const YAC_LOCATION_CORNER
Definition yac.c:28
void yac_cdef_couple_custom(char const *src_comp_name, char const *src_grid_name, char const *src_field_name, char const *tgt_comp_name, char const *tgt_grid_name, char const *tgt_field_name, char const *coupling_timestep, int time_unit, int time_reduction, int interp_stack_config_id, int src_lag, int tgt_lag, int ext_couple_config_id)
Definition yac.c:1444
const char * yac_cget_field_timestep_instance(int yac_instance_id, const char *comp_name, const char *grid_name, const char *field_name)
Definition yac.c:3097
void yac_cset_ext_couple_config_scale_summand(int ext_couple_config_id, double scale_summand)
Definition yac.c:1332
void yac_cget_comp_comm(int comp_id, MPI_Comm *comp_comm)
Definition yac.c:638
const char * yac_cget_field_datetime(int field_id)
Definition yac.c:1654
int const YAC_SPMAP_AVG
Definition yac.c:81
int const YAC_CONSERV_DESTAREA
Definition yac.c:78
void yac_cget(int const field_id, int collection_size, double **recv_field, int *info, int *ierr)
Definition yac.c:1850
static size_t num_components
Definition yac.c:118
int const YAC_EXCHANGE_TYPE_SOURCE
Definition yac.c:32
void yac_cdef_comp_instance(int yac_instance_id, char const *comp_name, int *comp_id)
Definition yac.c:789
void yac_cupdate(int field_id)
Definition yac.c:1674
void yac_cget_action(int field_id, int *action)
Definition yac.c:1611
static void yac_free_interp_stack_configs()
Definition yac.c:269
void yac_cexchange_(int const send_field_id, int const recv_field_id, int const collection_size, double *send_field, double *recv_field, int *send_info, int *recv_info, int *ierr)
Definition yac.c:2528
int const YAC_REDUCTION_TIME_ACCUMULATE
Definition yac.c:46
int yac_cget_field_id(const char *comp_name, const char *grid_name, const char *field_name)
Definition yac.c:2879
void yac_cget_ext_couple_config_src_mask_names(int ext_couple_config_id, size_t *num_src_mask_names, char const *const **src_mask_names)
Definition yac.c:1370
const char * yac_cget_grid_name_from_field_id(int field_id)
Definition yac.c:3059
int yac_cget_collection_size_from_field_id(int field_id)
Definition yac.c:3081
void yac_cdef_grid_reg2d(const char *grid_name, int nbr_vertices[2], int cyclic[2], double *x_vertices, double *y_vertices, int *grid_id)
Definition yac.c:3172
void yac_cmpi_handshake_f2c(MPI_Fint comm, int n, char const **group_names, MPI_Fint *group_comms)
Definition yac.c:333
int const YAC_EXCHANGE_TYPE_NONE
Definition yac.c:31
void yac_cdef_couple_custom_instance(int yac_instance_id, char const *src_comp_name, char const *src_grid_name, char const *src_field_name, char const *tgt_comp_name, char const *tgt_grid_name, char const *tgt_field_name, char const *coupling_timestep, int time_unit, int time_reduction, int interp_stack_config_id, int src_lag, int tgt_lag, int ext_couple_config_id)
Definition yac.c:1429
static int yac_pointer_to_unique_id(void *pointer)
Definition yac.c:145
void check_mpi_initialised(char const *routine_name)
Definition yac.c:316
void yac_cdef_points_reg2d(int const grid_id, int const *nbr_points, int const located, double const *x_points, double const *y_points, int *point_id)
Definition yac.c:845
void yac_cget_comps_comm(const char **comp_names, int num_comps, MPI_Comm *comps_comm)
Definition yac.c:688
void yac_cexchange_ptr_(int const send_field_id, int const recv_field_id, int const collection_size, double **send_field, double **recv_field, int *send_info, int *recv_info, int *ierr)
Definition yac.c:2603
void yac_cinit_comm_instance(MPI_Comm comm, int *yac_instance_id)
Definition yac.c:364
void yac_cadd_interp_stack_config_nnn(int interp_stack_config_id, int type, size_t n, double scale)
Definition yac.c:3419
static struct user_input_data_points ** points
Definition yac.c:120
int const YAC_EXCHANGE_TYPE_TARGET
Definition yac.c:33
void yac_cread_config_json_instance(int yac_instance_id, const char *yaml_filename)
Definition yac.c:462
void yac_cset_ext_couple_config_scale_factor_(struct yac_ext_couple_config *ext_couple_config, double scale_factor)
Definition yac.c:1300
const char * yac_cget_grid_metadata(const char *grid_name)
Definition yac.c:1201
void yac_cenable_field_frac_mask_instance(int yac_instance_id, const char *comp_name, const char *grid_name, const char *field_name, double frac_mask_fallback_value)
Definition yac.c:1116
char * yac_cget_start_datetime(void)
Definition yac.c:588
void yac_ccheck_field_dimensions(int field_id, int collection_size, int num_interp_fields, int const *interp_field_sizes)
Definition yac.c:1550
int const YAC_TIME_UNIT_MONTH
Definition yac.c:56
int const YAC_TIME_UNIT_SECOND
Definition yac.c:52
int const YAC_ACTION_RESTART
Definition yac.c:38
void yac_cadd_interp_stack_config_conservative(int interp_stack_config_id, int order, int enforced_conserv, int partial_coverage, int normalisation)
Definition yac.c:3439
void yac_cput_frac_ptr_(int const field_id, int const collection_size, double **send_field, double **send_frac_mask, int *info, int *ierr)
Definition yac.c:2035
void yac_cset_ext_couple_config_mapping_side_(struct yac_ext_couple_config *ext_couple_config, int mapping_side)
Definition yac.c:1274
static void yac_free_points()
Definition yac.c:236
void yac_cdef_grid_unstruct(const char *grid_name, int nbr_vertices, int nbr_cells, int *num_vertices_per_cell, double *x_vertices, double *y_vertices, int *cell_to_vertex, int *grid_id)
Definition yac.c:3208
static int yac_instance_count
Definition yac.c:109
void yac_cexchange(int const send_field_id, int const recv_field_id, int const collection_size, double ***const send_field, double **recv_field, int *send_info, int *recv_info, int *ierr)
Definition yac.c:2804
void yac_cdef_points_unstruct(int const grid_id, int const nbr_points, int const located, double const *x_points, double const *y_points, int *point_id)
Definition yac.c:919
char * yac_cget_version(void)
Definition yac.c:614
static int pointer_lookup_table_size
Definition yac.c:112
int const YAC_LOCATION_EDGE
Definition yac.c:29
void yac_cput(int const field_id, int const collection_size, double ***const send_field, int *info, int *ierr)
Definition yac.c:2514
void yac_cget_async(int const field_id, int collection_size, double **recv_field, int *info, int *ierr)
Definition yac.c:1859
void yac_cread_config_yaml(const char *yaml_filename)
Definition yac.c:457
void yac_cset_ext_couple_config_weight_file_(struct yac_ext_couple_config *ext_couple_config, char const *weight_file)
Definition yac.c:1252
int yac_cget_default_instance_id()
Definition yac.c:359
static size_t num_interp_stack_configs
Definition yac.c:127
void yac_cexchange_frac_(int const send_field_id, int const recv_field_id, int const collection_size, double *send_field, double *send_frac_mask, double *recv_field, int *send_info, int *recv_info, int *ierr)
Definition yac.c:2561
const char * yac_cget_component_name_from_field_id(int field_id)
Definition yac.c:3052
void yac_cinit_comm_instance_f2c(MPI_Fint comm, int *yac_instance_id)
Definition yac.c:370
#define AGGREGATE(EXTRA_CHECK, ACCU_OP)
int yac_cget_field_collection_size(const char *comp_name, const char *grid_name, const char *field_name)
Definition yac.c:3145
int const YAC_SPMAP_FRACAREA
Definition yac.c:87
void yac_cdef_component_metadata_instance(int yac_instance_id, const char *comp_name, const char *metadata)
Definition yac.c:1137
void yac_cdef_couple_(char const *src_comp_name, char const *src_grid_name, char const *src_field_name, char const *tgt_comp_name, char const *tgt_grid_name, char const *tgt_field_name, char const *coupling_timestep, int time_unit, int time_reduction, int interp_stack_config_id, int src_lag, int tgt_lag, char const *weight_file, int mapping_side, double scale_factor, double scale_summand, int num_src_mask_names, char const *const *src_mask_names, char const *tgt_mask_name)
Definition yac.c:1528
void yac_cenddef_and_emit_config_instance(int yac_instance_id, int emit_flags, char **config)
Definition yac.c:2846
void yac_cexchange_frac_ptr_(int const send_field_id, int const recv_field_id, int const collection_size, double **send_field, double **send_frac_mask, double **recv_field, int *send_info, int *recv_info, int *ierr)
Definition yac.c:2633
char * yac_cget_end_datetime(void)
Definition yac.c:603
int const YAC_ACTION_NONE
Definition yac.c:35
int yac_cyaml_get_emitter_flag_json_c2f()
Definition yac.c:441
void yac_cdef_calendar(int calendar)
Definition yac.c:562
int const YAC_SPMAP_NONE
Definition yac.c:84
void yac_cset_core_mask(int const *is_core, int location, int grid_id)
Definition yac.c:3285
void yac_cinit_comm_f2c(MPI_Fint comm_f)
Definition yac.c:385
void yac_cwait(int field_id)
Definition yac.c:2090
void yac_cdef_couple_instance_(int yac_instance_id, char const *src_comp_name, char const *src_grid_name, char const *src_field_name, char const *tgt_comp_name, char const *tgt_grid_name, char const *tgt_field_name, char const *coupling_timestep, int time_unit, int time_reduction, int interp_stack_config_id, int src_lag, int tgt_lag, char const *weight_file, int mapping_side, double scale_factor, double scale_summand, int num_src_mask_names, char const *const *src_mask_names, char const *tgt_mask_name)
Definition yac.c:1490
void yac_cget_comp_names(int nbr_comps, const char **comp_names)
Definition yac.c:2972
static int yac_add_grid(const char *grid_name, struct yac_basic_grid_data grid_data)
Definition yac.c:205
void yac_cdef_comps(char const **comp_names, int num_comps, int *comp_ids)
Definition yac.c:781
const char * yac_cget_field_metadata(const char *comp_name, const char *grid_name, const char *field_name)
Definition yac.c:1215
int const YAC_ACTION_REDUCTION
Definition yac.c:36
int const YAC_ACTION_GET_FOR_RESTART
Definition yac.c:39
void yac_cput_(int const field_id, int const collection_size, double *send_field, int *info, int *ierr)
Definition yac.c:1917
void yac_cget_comps_comm_f2c(char const **comp_names, int num_comps, MPI_Fint *comps_comm_f)
Definition yac.c:708
int const YAC_PROLEPTIC_GREGORIAN
Definition yac.c:61
void yac_cget_comp_grid_names_instance(int yac_instance_id, const char *comp_name, int nbr_grids, const char **grid_names)
Definition yac.c:2994
double yac_cget_field_frac_mask_fallback_value(const char *comp_name, const char *grid_name, const char *field_name)
Definition yac.c:3137
void yac_cset_mask(int const *is_valid, int points_id)
Definition yac.c:993
void yac_cget_async_(int const field_id, int const collection_size, double *recv_field, int *info, int *ierr)
Definition yac.c:1841
void yac_cadd_interp_stack_config_hcsbb(int interp_stack_config_id)
Definition yac.c:3488
void yac_cget_comps_comm_instance(int yac_instance_id, char const **comp_names, int num_comps, MPI_Comm *comps_comm)
Definition yac.c:678
void yac_cadd_interp_stack_config_fixed(int interp_stack_config_id, double value)
Definition yac.c:3510
int const YAC_TIME_UNIT_DAY
Definition yac.c:55
static size_t num_points
Definition yac.c:121
void yac_get_(int const field_id, int const collection_size, double *recv_field, int is_async, int *info, int *ierr)
Definition yac.c:1814
static void yac_cupdate_(struct coupling_field *cpl_field, struct event *event, int is_source)
Definition yac.c:1662
int yac_cget_comp_nbr_grids(const char *comp_name)
Definition yac.c:2931
int const YAC_ACTION_COUPLING
Definition yac.c:37
double yac_cget_field_frac_mask_fallback_value_instance(int yac_instance_id, const char *comp_name, const char *grid_name, const char *field_name)
Definition yac.c:3116
static int user_input_data_add_points(struct yac_basic_grid *grid, enum yac_location location, yac_coordinate_pointer coordinates)
Definition yac.c:802
int const YAC_TIME_UNIT_ISO_FORMAT
Definition yac.c:58
int const YAC_AVG_DIST
Definition yac.c:66
int yac_cget_field_role_instance(int yac_instance_id, const char *comp_name, const char *grid_name, const char *field_name)
Definition yac.c:3152
static void yac_check_version(MPI_Comm comm)
Definition yac.c:290
void yac_cdef_mask(int const grid_id, int const nbr_points, int const located, int const *is_valid, int *mask_id)
Definition yac.c:984
static void * yac_unique_id_to_pointer(int id, char const *id_name)
Definition yac.c:164
int const YAC_CONSERV_FRACAREA
Definition yac.c:79
void yac_cadd_interp_stack_config_user_callback(int interp_stack_config_id, char const *func_compute_weights_key)
Definition yac.c:3542
void yac_cdef_points_curve2d(int const grid_id, int const *nbr_points, int const located, double const *x_points, double const *y_points, int *point_id)
Definition yac.c:881
void yac_cset_ext_couple_config_mapping_side(int ext_couple_config_id, int mapping_side)
Definition yac.c:1286
void yac_cdef_mask_named(int const grid_id, int const nbr_points, int const located, int const *is_valid, char const *name, int *mask_id)
Definition yac.c:965
void yac_ccleanup_instance(int yac_instance_id)
Definition yac.c:497
int yac_cget_field_collection_size_instance(int yac_instance_id, const char *comp_name, const char *grid_name, const char *field_name)
Definition yac.c:3127
static void check_y_vertices(double const *y_vertices, size_t count, char const *routine_name)
Definition yac.c:832
void yac_cfree_interp_stack_config(int interp_stack_config_id)
Definition yac.c:3362
int const YAC_CALENDAR_NOT_SET
Definition yac.c:60
int const YAC_NNN_AVG
Definition yac.c:72
void yac_cadd_interp_stack_config_user_file(int interp_stack_config_id, char const *filename, char const *src_grid_name, char const *tgt_grid_name)
Definition yac.c:3497
void yac_cget_ext_couple_config_scale_summand(int ext_couple_config_id, double *scale_summand)
Definition yac.c:1339
size_t yac_cget_grid_size(int located, int grid_id)
Definition yac.c:3325
void yac_cinit_instance(int *yac_instance_id)
Definition yac.c:390
void yac_ctest(int field_id, int *flag)
Definition yac.c:2066
void yac_cget_interp_stack_config(int *interp_stack_config_id)
Definition yac.c:3348
static void yac_free_pointer_unique_lookup()
Definition yac.c:196
void yac_cinit_dummy(void)
Definition yac.c:428
void yac_cadd_interp_stack_config_average(int interp_stack_config_id, int reduction_type, int partial_coverage)
Definition yac.c:3382
int const YAC_ACTION_PUT_FOR_RESTART
Definition yac.c:40
#define WEIGHT_ACC(ACC, EXTRA_CHECK)
int const YAC_NNN_ZERO
Definition yac.c:76
void yac_cdef_comp(char const *comp_name, int *comp_id)
Definition yac.c:795
static struct yac_interp_stack_config ** interp_stack_configs
Definition yac.c:126
int const YAC_SPMAP_DIST
Definition yac.c:82
void yac_cdef_field(char const *name, int const comp_id, int const *point_ids, int const num_pointsets, int collection_size, const char *timestep, int time_unit, int *field_id)
Definition yac.c:1085
size_t yac_cget_points_size(int points_id)
Definition yac.c:3336
void yac_cdef_couple_instance(int yac_instance_id, char const *src_comp_name, char const *src_grid_name, char const *src_field_name, char const *tgt_comp_name, char const *tgt_grid_name, char const *tgt_field_name, char const *coupling_timestep, int time_unit, int time_reduction, int interp_stack_config_id, int src_lag, int tgt_lag)
Definition yac.c:1459
void yac_cdef_couple(char const *src_comp_name, char const *src_grid_name, char const *src_field_name, char const *tgt_comp_name, char const *tgt_grid_name, char const *tgt_field_name, char const *coupling_timestep, int time_unit, int time_reduction, int interp_stack_config_id, int src_lag, int tgt_lag)
Definition yac.c:1476
int yac_cget_nbr_comps(void)
Definition yac.c:2895
static int default_instance_id
Definition yac.c:107
void yac_cdef_field_metadata_instance(int yac_instance_id, const char *comp_name, const char *grid_name, const char *field_name, const char *metadata)
Definition yac.c:1164
int const YAC_AVG_BARY
Definition yac.c:67
static void check_x_vertices(double const *x_vertices, size_t count, char const *routine_name)
Definition yac.c:822
void yac_cset_ext_couple_config_tgt_mask_name_(struct yac_ext_couple_config *ext_couple_config, char const *tgt_mask_name)
Definition yac.c:1379
void yac_cput_ptr_(int const field_id, int const collection_size, double **send_field, int *info, int *ierr)
Definition yac.c:2015
struct yac_basic_grid ** grids
Definition yac.c:114
int const YAC_NNN_DIST
Definition yac.c:73
void yac_cget_comp_grid_names(const char *comp_name, int nbr_grids, const char **grid_names)
Definition yac.c:3013
int yac_cget_nbr_grids()
Definition yac.c:2908
void yac_cget_field_names_instance(int yac_instance_id, const char *comp_name, const char *grid_name, int nbr_fields, const char **field_names)
Definition yac.c:3019
void yac_cdef_comps_instance(int yac_instance_id, char const **comp_names, int num_comps, int *comp_ids)
Definition yac.c:756
int const YAC_REDUCTION_TIME_NONE
Definition yac.c:45
void yac_cget_comp_names_instance(int yac_instance_id, int nbr_comps, const char **comp_names)
Definition yac.c:2961
void yac_cdef_field_metadata(const char *comp_name, const char *grid_name, const char *field_name, const char *metadata)
Definition yac.c:1173
static struct yac_interpolation * yac_cput_pre_processing(struct coupling_field *cpl_field, unsigned put_idx, int const collection_size, double ***send_field, double ****send_field_acc_, double ***send_frac_mask, double ****send_frac_mask_acc_, int *info, int *ierr)
Definition yac.c:2128
static void yac_ccleanup_instance_(int yac_instance_id)
Definition yac.c:478
const char * yac_cget_component_metadata(const char *comp_name)
Definition yac.c:1188
const char * yac_cget_field_timestep(const char *comp_name, const char *grid_name, const char *field_name)
Definition yac.c:3109
void yac_cget_field_names(const char *comp_name, const char *grid_name, int nbr_fields, const char **field_names)
Definition yac.c:3045
void ** pointer_lookup_table
Definition yac.c:111
void yac_cget_ext_couple_config_weight_file(int ext_couple_config_id, char const **weight_file)
Definition yac.c:1267
void yac_cinit_comm(MPI_Comm comm)
Definition yac.c:376
static void yac_free_grids()
Definition yac.c:225
#define YAC_MAX_CHARLEN
Definition yac.h:74
#define YAC_ASSERT_F(exp, format,...)
Definition yac_assert.h:18
#define YAC_ASSERT(exp, msg)
Definition yac_assert.h:15
void yac_mpi_finalize()
Definition yac_mpi.c:108
void yac_mpi_cleanup()
Definition yac_mpi.c:95
int yac_mpi_is_initialised()
Definition yac_mpi.c:32
void yac_yaxt_init(MPI_Comm comm)
Definition yac_mpi.c:40
void yac_mpi_init()
Definition yac_mpi.c:77
#define yac_mpi_call(call, comm)
Xt_int yac_int
Definition yac_types.h:15
double(* yac_coordinate_pointer)[3]
Definition yac_types.h:19