YAC 3.7.1
Yet Another Coupler
Loading...
Searching...
No Matches
interp_stack_config.c
Go to the documentation of this file.
1// Copyright (c) 2024 The YAC Authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifdef HAVE_CONFIG_H
6#include "config.h"
7#endif
8
9#include <math.h>
10#include <string.h>
11
12#include "geometry.h"
13#include "yac_mpi_internal.h"
14#include "interp_stack_config.h"
15
17 struct {
20 struct {
25 struct {
30 struct {
32 int order;
34 int partial_coverage;
37 struct {
44 struct {
47 struct {
53 struct {
55 double value;
57 struct {
62 struct {
66 struct {
70 struct {
75};
76
81
104
106 struct yac_interp_stack_config * interp_stack) {
107
108 struct yac_interp_stack_config * interp_stack_copy =
109 xmalloc(1 * sizeof(*interp_stack_copy));
110 interp_stack_copy->size = interp_stack->size;
111 interp_stack_copy->config =
112 xmalloc(interp_stack_copy->size * sizeof(*(interp_stack_copy->config)));
113 for (size_t i = 0; i < interp_stack_copy->size; ++i)
115 interp_stack_copy->config + i, interp_stack->config + i);
116 return interp_stack_copy;
117}
118
119static inline void check_interpolation_type(
120 enum yac_interpolation_list type, char const * routine) {
121
123 (type == YAC_AVERAGE) ||
126 (type == YAC_CONSERVATIVE) ||
128 (type == YAC_FIXED_VALUE) ||
130 (type == YAC_USER_FILE) ||
131 (type == YAC_CHECK) ||
132 (type == YAC_CREEP) ||
133 (type == YAC_USER_CALLBACK) ||
135 (type == YAC_UNDEFINED),
136 "ERROR(%s): invalid interpolation type", routine)
137}
138
140 struct yac_spmap_cell_area_config a, struct yac_spmap_cell_area_config b) {
141
142 int ret;
143 if ((ret = ((int)(a.cell_area_provider) > (int)(b.cell_area_provider)) -
144 ((int)(a.cell_area_provider) < (int)(b.cell_area_provider))))
145 return ret;
146
147 switch (a.cell_area_provider) {
148 default:
150 return
151 ((int)(a.sphere_radius) > (int)(b.sphere_radius)) -
152 ((int)(a.sphere_radius) < (int)(b.sphere_radius));
153 }
155 if ((ret = strcmp(a.file_config.filename, b.file_config.filename)))
156 return ret;
157 if ((ret = strcmp(a.file_config.varname, b.file_config.varname)))
158 return ret;
159 return
160 ((int)(a.file_config.min_global_id) >
161 (int)(b.file_config.min_global_id)) -
162 ((int)(a.file_config.min_global_id) <
163 (int)(b.file_config.min_global_id));
164 }
165 }
166}
167
170
171 int ret;
172 if ((ret = ((int)(a.type) > (int)(b.type)) - ((int)(a.type) < (int)(b.type))))
173 return ret;
174 if ((ret = yac_spmap_cell_area_config_compare(a.src, b.src))) return ret;
175 if ((ret = yac_spmap_cell_area_config_compare(a.tgt, b.tgt))) return ret;
176 return 0;
177}
178
180 void const * a_, void const * b_) {
181
182 union yac_interp_stack_config_entry const * a =
183 (union yac_interp_stack_config_entry const *)a_;
184 union yac_interp_stack_config_entry const * b =
185 (union yac_interp_stack_config_entry const *)b_;
186
188 a->general.type, "yac_interp_stack_config_entry_compare");
190 b->general.type, "yac_interp_stack_config_entry_compare");
193 "ERROR(yac_interp_stack_config_entry_compare): "
194 "interpolation type is undefined");
195
196 if (a->general.type != b->general.type)
197 return (a->general.type > b->general.type) -
198 (a->general.type < b->general.type);
199
200 switch(a->general.type) {
201 default:
203 return 0;
204 case (YAC_AVERAGE): {
210 }
212 case (YAC_N_NEAREST_NEIGHBOR): {
213 if (a->n_nearest_neighbor.config.n !=
215 return (a->n_nearest_neighbor.config.n >
227 return (a->n_nearest_neighbor.config.type >
231 switch (a->n_nearest_neighbor.config.type) {
237 case (YAC_INTERP_NNN_RBF):
242 default:
243 return 0;
244 };
245 }
246 case (YAC_CONSERVATIVE): {
247 if (a->conservative.order !=
249 return (a->conservative.order >
250 b->conservative.order) -
251 (a->conservative.order <
255 return (a->conservative.enforced_conserv >
261 return (a->conservative.partial_coverage >
265 return (a->conservative.normalisation >
269 }
271 if (fabs(a->spmap.spread_distance -
273 return (a->spmap.spread_distance >
277 if (fabs(a->spmap.max_search_distance -
279 return (a->spmap.max_search_distance >
283 if (a->spmap.weight_type != b->spmap.weight_type)
284 return (a->spmap.weight_type >
285 b->spmap.weight_type) -
286 (a->spmap.weight_type <
287 b->spmap.weight_type);
288 return
291 }
292 case (YAC_FIXED_VALUE): {
293 return (a->fixed.value >
294 b->fixed.value) -
295 (a->fixed.value <
296 b->fixed.value);
297 }
298 case (YAC_USER_FILE): {
300 return (a->user_file.on_missing_file >
305 return (a->user_file.on_success >
309 return strcmp(a->user_file.filename, b->user_file.filename);
310 }
311 case (YAC_CHECK): {
312 int ret;
313 if ((ret = strncmp(a->check.constructor_key, b->check.constructor_key,
314 sizeof(a->check.constructor_key)))) return ret;
315 return
316 strncmp(
318 sizeof(a->check.do_search_key));
319 };
320 case (YAC_CREEP): {
321 return
324 }
325 case (YAC_USER_CALLBACK): {
328 }
340 }
341 };
342}
343
344int yac_interp_stack_config_compare(void const * a_, void const * b_) {
345
346 struct yac_interp_stack_config const * a =
347 (struct yac_interp_stack_config const *)a_;
348 struct yac_interp_stack_config const * b =
349 (struct yac_interp_stack_config const *)b_;
350
351 int ret;
352 if ((ret = (a->size > b->size) - (a->size < b->size))) return ret;
353
354 size_t stack_size = a->size;
355 for (size_t method_idx = 0; method_idx < stack_size; ++method_idx)
356 if ((ret =
358 &(a->config[method_idx]), &(b->config[method_idx]))))
359 return ret;
360 return 0;
361}
362
364 struct yac_interp_stack_config * interp_stack) {
365
366 size_t interp_stack_size = interp_stack->size;
367 struct interp_method ** method_stack =
368 xmalloc((interp_stack_size + 1) * sizeof(*method_stack));
369 method_stack[interp_stack_size] = NULL;
370
371 for (size_t i = 0; i < interp_stack_size; ++i) {
372
374 interp_stack->config[i].general.type, "yac_interp_stack_config_generate");
376 interp_stack->config[i].general.type != YAC_UNDEFINED,
377 "ERROR(yac_interp_stack_config_generate): "
378 "unsupported interpolation method")
379 switch((int)(interp_stack->config[i].general.type)) {
380 default:
381 case(YAC_AVERAGE): {
383 interp_stack->config[i].average.reduction_type;
384 int partial_coverage =
385 (int)interp_stack->config[i].average.partial_coverage;
386 method_stack[i] =
387 yac_interp_method_avg_new(weight_type, partial_coverage);
388 break;
389 }
390 case(YAC_CONSERVATIVE): {
391 int order =
392 interp_stack->config[i].conservative.order;
393 int enforced_conserv =
394 interp_stack->config[i].conservative.enforced_conserv;
395 int partial_coverage =
396 interp_stack->config[i].conservative.partial_coverage;
397 enum yac_interp_method_conserv_normalisation normalisation =
398 interp_stack->config[i].conservative.normalisation;
399
400 method_stack[i] =
402 order, enforced_conserv, partial_coverage, normalisation);
403 break;
404 }
405 case(YAC_FIXED_VALUE): {
406 double fixed_value =
407 interp_stack->config[i].fixed.value;
408 method_stack[i] = yac_interp_method_fixed_new(fixed_value);
409 break;
410 }
411 case(YAC_USER_FILE): {
412 char const * weight_file_name =
413 interp_stack->config[i].user_file.filename;
415 interp_stack->config[i].user_file.on_missing_file;
417 interp_stack->config[i].user_file.on_success;
418 method_stack[i] =
421 break;
422 }
423 case(YAC_CHECK): {
424 func_constructor constructor_callback;
425 void * constructor_user_data;
427 void * do_search_user_data;
428
430 interp_stack->config[i].check.constructor_key,
431 &constructor_callback, &constructor_user_data);
433 interp_stack->config[i].check.do_search_key,
434 &do_search_callback, &do_search_user_data);
435
436 method_stack[i] =
438 constructor_callback, constructor_user_data,
439 do_search_callback, do_search_user_data);
440 break;
441 }
442 case (YAC_N_NEAREST_NEIGHBOR): {
443 method_stack[i] =
445 interp_stack->config[i].
446 n_nearest_neighbor.config);
447 break;
448 }
449 case (YAC_BERNSTEIN_BEZIER): {
450 method_stack[i] =
452 break;
453 }
455 method_stack[i] =
457 interp_stack->config[i].
458 radial_basis_function.config);
459 break;
460 }
462 method_stack[i] =
464 interp_stack->config[i].spmap.spread_distance,
465 interp_stack->config[i].spmap.max_search_distance,
466 interp_stack->config[i].spmap.weight_type,
467 interp_stack->config[i].spmap.scale_config);
468 break;
469 }
470 case (YAC_CREEP): {
471 method_stack[i] =
473 interp_stack->config[i].creep.creep_distance);
474 break;
475 }
476 case(YAC_USER_CALLBACK): {
478 void * user_data;
482
483 method_stack[i] =
485 break;
486 }
488 method_stack[i] =
490 interp_stack->config[i].nearest_corner_cells.weight_type,
492 break;
493 }
494 };
495 }
496
497 return method_stack;
498}
499
501 char const * string, MPI_Comm comm) {
502
503 int strlen_pack_size, string_pack_size;
504 yac_mpi_call(MPI_Pack_size(1, MPI_INT, comm, &strlen_pack_size), comm);
505
507 string != NULL, "ERROR(yac_interp_stack_config_get_string_pack_size): "
508 "string is NULL");
509
511 MPI_Pack_size(
512 (int)(strlen(string)), MPI_CHAR, comm, &string_pack_size), comm);
513
514 return (size_t)strlen_pack_size + (size_t)string_pack_size;
515}
516
518 struct yac_spmap_cell_area_config cell_area_config, MPI_Comm comm) {
519
520 int int_pack_size, dbl_pack_size;
521 yac_mpi_call(MPI_Pack_size(1, MPI_INT, comm, &int_pack_size), comm);
522 yac_mpi_call(MPI_Pack_size(1, MPI_DOUBLE, comm, &dbl_pack_size), comm);
523
524 size_t pack_size = (size_t)int_pack_size; // cell_area_provider
525
526 switch (cell_area_config.cell_area_provider) {
527 default:
529 pack_size += (size_t)dbl_pack_size; // sphere_radius
530 break;
531 }
533 pack_size +=
535 cell_area_config.file_config.filename, comm) + // filename
537 cell_area_config.file_config.varname, comm) + // varname
538 int_pack_size; // min_global_id
539 break;
540 }
541 }
542
543 return pack_size;
544}
545
547 union yac_interp_stack_config_entry * entry, MPI_Comm comm) {
548
549 int int_pack_size, dbl_pack_size;
550 yac_mpi_call(MPI_Pack_size(1, MPI_INT, comm, &int_pack_size), comm);
551 yac_mpi_call(MPI_Pack_size(1, MPI_DOUBLE, comm, &dbl_pack_size), comm);
552
554 entry->general.type,
555 "yac_interp_stack_config_get_entry_pack_size");
557 entry->general.type != YAC_UNDEFINED,
558 "ERROR(yac_interp_stack_config_get_entry_pack_size): "
559 "invalid interpolation type")
560 switch (entry->general.type) {
561 default:
562 case (YAC_AVERAGE):
563 return (size_t)int_pack_size + // type
564 (size_t)int_pack_size + // reduction_type
565 (size_t)int_pack_size; // partial_coverage
568 return (size_t)int_pack_size + // type
569 (size_t)int_pack_size + // weight_type
570 (size_t)int_pack_size + // n
571 (size_t)dbl_pack_size + // max_search_distance
572 (size_t)dbl_pack_size; // scale
573 case (YAC_CONSERVATIVE):
574 return (size_t)int_pack_size + // type
575 (size_t)int_pack_size + // order
576 (size_t)int_pack_size + // enforced_conserv
577 (size_t)int_pack_size + // partial_coverage
578 (size_t)int_pack_size; // normalisation
580 return (size_t)int_pack_size + // type
581 (size_t)dbl_pack_size + // spread_distance
582 (size_t)dbl_pack_size + // max_search_distance
583 (size_t)int_pack_size + // weight_type
584 (size_t)int_pack_size + // scale_type
586 entry->spmap.scale_config.src, comm) +
588 entry->spmap.scale_config.tgt, comm);
589 case (YAC_FIXED_VALUE):
590 return (size_t)int_pack_size + // type
591 (size_t)dbl_pack_size; // value
593 return (size_t)int_pack_size; // type
594 case (YAC_USER_FILE):
595 return (size_t)int_pack_size + // type
596 (size_t)int_pack_size + // on_missing_file
597 (size_t)int_pack_size + // on_success
599 entry->user_file.filename, comm);
600 case (YAC_CHECK):
601 return (size_t)int_pack_size + // type
603 entry->check.constructor_key, comm) + // constructor_key
605 entry->check.do_search_key, comm); // do_search_key
606 case (YAC_CREEP):
607 return (size_t)int_pack_size + // type
608 (size_t)int_pack_size; // creep_distance
609 case (YAC_USER_CALLBACK):
610 return (size_t)int_pack_size + // type
613 // func_compute_weights_key
615 return (size_t)int_pack_size + // type
616 (size_t)int_pack_size + // weight_type
617 (size_t)int_pack_size; // partial_coverage
618 }
619}
620
622 struct yac_interp_stack_config * interp_stack, MPI_Comm comm) {
623
624 int size_pack_size;
625 yac_mpi_call(MPI_Pack_size(1, MPI_INT, comm, &size_pack_size), comm);
626
627 size_t config_pack_size = 0;
628
629 for (size_t i = 0; i < interp_stack->size; ++i)
630 config_pack_size +=
632 interp_stack->config + i, comm);
633
634 return (size_t)size_pack_size + config_pack_size;
635}
636
638 char const * string, void * buffer, int buffer_size, int * position,
639 MPI_Comm comm) {
640
641 size_t len = (string == NULL)?0:strlen(string);
642
644 len <= INT_MAX, "ERROR(yac_interp_stack_config_pack_string): string too long")
645
646 int len_int = (int)len;
647
649 MPI_Pack(
650 &len_int, 1, MPI_INT, buffer, buffer_size, position, comm), comm);
651
652 if (len > 0)
654 MPI_Pack(
655 string, len_int, MPI_CHAR, buffer, buffer_size, position, comm),
656 comm);
657}
658
660 struct yac_spmap_cell_area_config cell_area_config,
661 void * buffer, int buffer_size, int * position, MPI_Comm comm) {
662
663 int cell_area_provider = (int)(cell_area_config.cell_area_provider);
665 MPI_Pack(
666 &cell_area_provider, 1, MPI_INT, buffer, buffer_size, position, comm), comm);
667
668 switch (cell_area_config.cell_area_provider) {
669 default:
672 MPI_Pack(
673 &(cell_area_config.sphere_radius), 1, MPI_DOUBLE,
674 buffer, buffer_size, position, comm), comm);
675 break;
676 }
679 cell_area_config.file_config.filename,
680 buffer, buffer_size, position, comm);
682 cell_area_config.file_config.varname,
683 buffer, buffer_size, position, comm);
685 (cell_area_config.file_config.min_global_id >= -INT_MAX) &&
686 (cell_area_config.file_config.min_global_id <= INT_MAX),
687 "ERRROR(yac_spmap_cell_area_config_pack): invalid minimum global id");
688 int min_global_id = (int)(cell_area_config.file_config.min_global_id);
690 MPI_Pack(
691 &min_global_id, 1, MPI_INT, buffer, buffer_size, position, comm),
692 comm);
693 break;
694 }
695 }
696}
697
699 union yac_interp_stack_config_entry * entry,
700 void * buffer, int buffer_size, int * position, MPI_Comm comm) {
701
702 int type = (int)(entry->general.type);
704 MPI_Pack(&type, 1, MPI_INT, buffer, buffer_size, position, comm), comm);
705
707 entry->general.type,
708 "yac_interp_stack_config_pack_entry");
710 entry->general.type != YAC_UNDEFINED,
711 "ERROR(yac_interp_stack_config_pack_entry): "
712 "invalid interpolation type")
713 switch (entry->general.type) {
714 default:
715 case (YAC_AVERAGE): {
716 int reduction_type = (int)(entry->average.reduction_type);
718 MPI_Pack(
719 &reduction_type, 1, MPI_INT, buffer, buffer_size, position, comm),
720 comm);
722 MPI_Pack(
723 &(entry->average.partial_coverage), 1, MPI_INT,
724 buffer, buffer_size, position, comm), comm);
725 break;
726 }
728 case (YAC_N_NEAREST_NEIGHBOR): {
730 entry->n_nearest_neighbor.config.n <= INT_MAX,
731 "ERROR(yac_interp_stack_config_pack_entry): "
732 "n_nearest_neighbor.config.n bigger than INT_MAX")
733 int type = (int)(entry->n_nearest_neighbor.config.type);
735 MPI_Pack(
736 &type, 1, MPI_INT, buffer, buffer_size, position, comm), comm);
737 int n = (int)(entry->n_nearest_neighbor.config.n);
739 MPI_Pack(
740 &n, 1, MPI_INT, buffer, buffer_size, position, comm), comm);
742 MPI_Pack(
744 MPI_DOUBLE, buffer, buffer_size, position, comm), comm);
746 MPI_Pack(
747 &(entry->n_nearest_neighbor.config.data.rbf_scale), 1, MPI_DOUBLE,
748 buffer, buffer_size, position, comm), comm);
749 break;
750 }
751 case (YAC_CONSERVATIVE): {
753 MPI_Pack(
754 &(entry->conservative.order), 1, MPI_INT,
755 buffer, buffer_size, position, comm), comm);
757 MPI_Pack(
758 &(entry->conservative.enforced_conserv), 1, MPI_INT,
759 buffer, buffer_size, position, comm), comm);
761 MPI_Pack(
762 &(entry->conservative.partial_coverage), 1, MPI_INT,
763 buffer, buffer_size, position, comm), comm);
764 int normalisation = (int)(entry->conservative.normalisation);
766 MPI_Pack(
767 &normalisation, 1, MPI_INT, buffer, buffer_size, position, comm),
768 comm);
769 break;
770 }
773 MPI_Pack(
774 &(entry->spmap.spread_distance), 1, MPI_DOUBLE,
775 buffer, buffer_size, position, comm), comm);
777 MPI_Pack(
778 &(entry->spmap.max_search_distance), 1, MPI_DOUBLE,
779 buffer, buffer_size, position, comm), comm);
780 int weight_type = (int)(entry->spmap.weight_type);
782 MPI_Pack(
783 &weight_type, 1, MPI_INT, buffer, buffer_size, position, comm),
784 comm);
785 int scale_type = (int)(entry->spmap.scale_config.type);
787 MPI_Pack(
788 &scale_type, 1, MPI_INT, buffer, buffer_size, position, comm),
789 comm);
791 entry->spmap.scale_config.src, buffer, buffer_size, position, comm);
793 entry->spmap.scale_config.tgt, buffer, buffer_size, position, comm);
794 break;
795 }
796 case (YAC_FIXED_VALUE): {
798 MPI_Pack(
799 &(entry->fixed.value), 1, MPI_DOUBLE,
800 buffer, buffer_size, position, comm), comm);
801 break;
802 }
804 break;
805 case (YAC_USER_FILE): {
806 int on_missing_file = (int)(entry->user_file.on_missing_file);
808 MPI_Pack(
809 &on_missing_file, 1, MPI_INT, buffer, buffer_size, position, comm),
810 comm);
811 int on_success = (int)(entry->user_file.on_success);
813 MPI_Pack(
814 &on_success, 1, MPI_INT, buffer, buffer_size, position, comm),
815 comm);
817 entry->user_file.filename, buffer, buffer_size, position, comm);
818 break;
819 }
820 case (YAC_CHECK): {
822 entry->check.constructor_key, buffer, buffer_size, position, comm);
824 entry->check.do_search_key, buffer, buffer_size, position, comm);
825 break;
826 }
827 case (YAC_CREEP): {
829 MPI_Pack(
830 &(entry->creep.creep_distance), 1, MPI_INT,
831 buffer, buffer_size, position, comm), comm);
832 break;
833 }
834 case (YAC_USER_CALLBACK): {
837 buffer, buffer_size, position, comm);
838 break;
839 }
841 int weight_type = (int)(entry->nearest_corner_cells.weight_type);
843 MPI_Pack(
844 &weight_type, 1, MPI_INT, buffer, buffer_size, position, comm),
845 comm);
847 MPI_Pack(
848 &(entry->nearest_corner_cells.partial_coverage), 1, MPI_INT,
849 buffer, buffer_size, position, comm), comm);
850 break;
851 }
852 }
853}
854
856 struct yac_interp_stack_config * interp_stack,
857 void * buffer, int buffer_size, int * position, MPI_Comm comm) {
858
859 int stack_size = (int)(interp_stack->size);
861 MPI_Pack(
862 &stack_size, 1, MPI_INT,
863 buffer, buffer_size, position, comm), comm);
864
865 for (size_t i = 0; i < interp_stack->size; ++i)
867 interp_stack->config + i, buffer, buffer_size, position, comm);
868}
869
871 void * buffer, int buffer_size, int * position,
872 char * string, int max_string_len, MPI_Comm comm) {
873
874 int string_len;
876 MPI_Unpack(
877 buffer, buffer_size, position, &string_len, 1, MPI_INT, comm), comm);
878
880 string_len >= 0,
881 "ERROR(yac_interp_stack_config_unpack_n_string): invalid string length")
882
884 string_len < max_string_len,
885 "ERROR(yac_interp_stack_config_unpack_n_string): string length to long")
886
887 if (string_len > 0)
889 MPI_Unpack(
890 buffer, buffer_size, position, string, string_len, MPI_CHAR, comm),
891 comm);
892 string[string_len] = '\0';
893}
894
896 void * buffer, int buffer_size, int * position, MPI_Comm comm) {
897
898 int string_len;
900 MPI_Unpack(
901 buffer, buffer_size, position, &string_len, 1, MPI_INT, comm), comm);
902
904 string_len >= 0,
905 "ERROR(yac_interp_stack_config_unpack_string): invalid string length")
906
907 char * string = NULL;
908 if (string_len > 0) {
909 string = xmalloc((size_t)(string_len + 1) * sizeof(*string));
911 MPI_Unpack(
912 buffer, buffer_size, position, string, string_len, MPI_CHAR, comm),
913 comm);
914 string[string_len] = '\0';
915 }
916 return string;
917}
918
920 void * buffer, int buffer_size, int * position,
921 struct yac_spmap_cell_area_config * cell_area_config, MPI_Comm comm) {
922
923 int cell_area_provider;
925 MPI_Unpack(
926 buffer, buffer_size, position, &cell_area_provider, 1, MPI_INT, comm),
927 comm);
928 cell_area_config->cell_area_provider =
929 (enum yac_interp_spmap_cell_area_provider)cell_area_provider;
930
931 switch (cell_area_config->cell_area_provider) {
932 default:
935 MPI_Unpack(
936 buffer, buffer_size, position,
937 &(cell_area_config->sphere_radius), 1, MPI_DOUBLE, comm), comm);
938 cell_area_config->file_config.filename = NULL;
939 cell_area_config->file_config.varname = NULL;
940 cell_area_config->file_config.min_global_id = 0;
941 break;
942 }
944 cell_area_config->sphere_radius = 0.0;
945 cell_area_config->file_config.filename =
947 buffer, buffer_size, position, comm);
948 cell_area_config->file_config.varname =
950 buffer, buffer_size, position, comm);
951 int min_global_id;
953 MPI_Unpack(
954 buffer, buffer_size, position, &min_global_id, 1, MPI_INT, comm),
955 comm);
956 cell_area_config->file_config.min_global_id = (size_t)min_global_id;
957 }
958 }
959}
960
962 void * buffer, int buffer_size, int * position,
963 union yac_interp_stack_config_entry * entry, MPI_Comm comm) {
964
965 int type;
967 MPI_Unpack(
968 buffer, buffer_size, position, &type, 1, MPI_INT, comm), comm);
969
971
973 entry->general.type,
974 "yac_interp_stack_config_unpack_entry");
976 entry->general.type != YAC_UNDEFINED,
977 "ERROR(yac_interp_stack_config_unpack_entry): "
978 "invalid interpolation type")
979 switch (type) {
980 default:
981 case (YAC_AVERAGE): {
982 int reduction_type;
984 MPI_Unpack(
985 buffer, buffer_size, position, &reduction_type, 1, MPI_INT, comm),
986 comm);
987 entry->average.reduction_type =
988 (enum yac_interp_avg_weight_type)reduction_type;
990 MPI_Unpack(
991 buffer, buffer_size, position, &(entry->average.partial_coverage),
992 1, MPI_INT, comm), comm);
993 break;
994 }
996 case (YAC_N_NEAREST_NEIGHBOR): {
997 int type;
999 MPI_Unpack(
1000 buffer, buffer_size, position, &type, 1, MPI_INT, comm), comm);
1003 int n;
1005 MPI_Unpack(
1006 buffer, buffer_size, position, &n, 1, MPI_INT, comm), comm);
1007 YAC_ASSERT(
1008 n >= 0,
1009 "ERROR(yac_interp_stack_config_unpack_entry): "
1010 "invalid n_nearest_neighbor.config.n")
1011 entry->n_nearest_neighbor.config.n = (size_t)n;
1013 MPI_Unpack(
1014 buffer, buffer_size, position,
1016 1, MPI_DOUBLE, comm), comm);
1018 MPI_Unpack(
1019 buffer, buffer_size, position,
1021 1, MPI_DOUBLE, comm), comm);
1022 break;
1023 }
1024 case (YAC_CONSERVATIVE): {
1026 MPI_Unpack(
1027 buffer, buffer_size, position,
1028 &(entry->conservative.order), 1, MPI_INT, comm), comm);
1030 MPI_Unpack(
1031 buffer, buffer_size, position,
1032 &(entry->conservative.enforced_conserv), 1, MPI_INT, comm), comm);
1034 MPI_Unpack(
1035 buffer, buffer_size, position,
1036 &(entry->conservative.partial_coverage), 1, MPI_INT, comm), comm);
1037 int normalisation;
1039 MPI_Unpack(
1040 buffer, buffer_size, position, &normalisation, 1, MPI_INT, comm),
1041 comm);
1043 (enum yac_interp_method_conserv_normalisation)normalisation;
1044 break;
1045 }
1046 case (YAC_SOURCE_TO_TARGET_MAP): {
1048 MPI_Unpack(
1049 buffer, buffer_size, position,
1050 &(entry->spmap.spread_distance), 1, MPI_DOUBLE, comm), comm);
1052 MPI_Unpack(
1053 buffer, buffer_size, position,
1054 &(entry->spmap.max_search_distance), 1, MPI_DOUBLE, comm), comm);
1055 int weight_type;
1057 MPI_Unpack(
1058 buffer, buffer_size, position, &weight_type, 1, MPI_INT, comm),
1059 comm);
1060 entry->spmap.weight_type =
1062 int scale_type;
1064 MPI_Unpack(
1065 buffer, buffer_size, position, &scale_type, 1, MPI_INT, comm),
1066 comm);
1067 entry->spmap.scale_config.type =
1068 (enum yac_interp_spmap_scale_type)scale_type;
1070 buffer, buffer_size, position, &(entry->spmap.scale_config.src), comm);
1072 buffer, buffer_size, position, &(entry->spmap.scale_config.tgt), comm);
1073 break;
1074 }
1075 case (YAC_FIXED_VALUE): {
1077 MPI_Unpack(
1078 buffer, buffer_size, position,
1079 &(entry->fixed.value), 1, MPI_DOUBLE, comm), comm);
1080 break;
1081 }
1082 case (YAC_BERNSTEIN_BEZIER):
1083 break;
1084 case (YAC_USER_FILE): {
1085 int on_missing_file;
1087 MPI_Unpack(
1088 buffer, buffer_size, position, &on_missing_file, 1, MPI_INT, comm),
1089 comm);
1090 entry->user_file.on_missing_file =
1092 int on_success;
1094 MPI_Unpack(
1095 buffer, buffer_size, position, &on_success, 1, MPI_INT, comm),
1096 comm);
1097 entry->user_file.on_success =
1100 buffer, buffer_size, position,
1102 break;
1103 }
1104 case (YAC_CHECK): {
1106 buffer, buffer_size, position,
1109 buffer, buffer_size, position,
1111 break;
1112 }
1113 case (YAC_CREEP): {
1115 MPI_Unpack(
1116 buffer, buffer_size, position,
1117 &(entry->creep.creep_distance), 1, MPI_INT, comm), comm);
1118 break;
1119 }
1120 case (YAC_USER_CALLBACK): {
1122 buffer, buffer_size, position,
1125 break;
1126 }
1127 case (YAC_NEAREST_CORNER_CELLS): {
1128 int weight_type;
1130 MPI_Unpack(
1131 buffer, buffer_size, position, &weight_type, 1, MPI_INT, comm),
1132 comm);
1136 MPI_Unpack(
1137 buffer, buffer_size, position,
1139 1, MPI_INT, comm), comm);
1140 break;
1141 }
1142 }
1143}
1144
1146 void * buffer, int buffer_size, int * position, MPI_Comm comm) {
1147
1148 int stack_size;
1150 MPI_Unpack(
1151 buffer, buffer_size, position, &stack_size, 1, MPI_INT, comm), comm);
1152
1153 YAC_ASSERT(
1154 stack_size >= 0,
1155 "ERROR(yac_interp_stack_config_unpack_interp_stack): invalid stack size")
1156
1157 struct yac_interp_stack_config * interp_stack =
1159
1160 interp_stack->size = (size_t)stack_size;
1161 interp_stack->config =
1162 xmalloc((size_t)stack_size * sizeof(*interp_stack->config));
1163
1164 for (int i = 0; i < stack_size; ++i)
1166 buffer, buffer_size, position, interp_stack->config + (size_t)i, comm);
1167
1168 return interp_stack;
1169}
1170
1172
1173 struct yac_interp_stack_config * interp_stack_config =
1174 xmalloc(1 * sizeof(*interp_stack_config));
1175 interp_stack_config->config = NULL;
1176 interp_stack_config->size = 0;
1177
1178 return interp_stack_config;
1179}
1180
1182 union yac_interp_stack_config_entry * entry) {
1183
1184 if (entry->general.type == YAC_SOURCE_TO_TARGET_MAP) {
1185 free((void*)entry->spmap.scale_config.src.file_config.filename);
1186 free((void*)entry->spmap.scale_config.src.file_config.varname);
1187 free((void*)entry->spmap.scale_config.tgt.file_config.filename);
1188 free((void*)entry->spmap.scale_config.tgt.file_config.varname);
1189 }
1190}
1191
1193 struct yac_interp_stack_config * interp_stack_config) {
1194 for (size_t i = 0; i < interp_stack_config->size; ++i)
1195 yac_interp_stack_config_entry_free(interp_stack_config->config + i);
1196 free(interp_stack_config->config);
1197 free(interp_stack_config);
1198}
1199
1200static union yac_interp_stack_config_entry *
1202 struct yac_interp_stack_config * interp_stack_config) {
1203
1204 interp_stack_config->size++;
1205 interp_stack_config->config =
1206 xrealloc(
1207 interp_stack_config->config,
1208 interp_stack_config->size * sizeof(*(interp_stack_config->config)));
1209
1210 return interp_stack_config->config + (interp_stack_config->size - 1);
1211}
1212
1224
1226 struct yac_interp_stack_config * interp_stack_config,
1228
1229 YAC_ASSERT(
1233 "ERROR(yac_interp_stack_config_add_average_f2c): "
1234 "reduction_type must be one of "
1235 "YAC_INTERP_AVG_ARITHMETIC/YAC_INTERP_AVG_DIST/YAC_INTERP_AVG_BARY");
1236
1238 interp_stack_config, (enum yac_interp_avg_weight_type)reduction_type,
1240}
1241
1253
1255 struct yac_interp_stack_config * interp_stack_config,
1256 int weight_type, int partial_coverage) {
1257
1258 YAC_ASSERT(
1261 "ERROR(yac_interp_stack_config_add_ncc_f2c): "
1262 "weight_type must be one of "
1263 "YAC_INTERP_NCC_AVG/YAC_INTERP_NCC_DIST");
1264
1266 interp_stack_config, (enum yac_interp_ncc_weight_type)weight_type,
1268}
1269
1271 struct yac_interp_stack_config * interp_stack_config,
1272 enum yac_interp_nnn_weight_type type, size_t n,
1273 double max_search_distance, double scale) {
1274
1275 union yac_interp_stack_config_entry * entry =
1276 yac_interp_stack_config_add_entry(interp_stack_config);
1277
1278 if (type == YAC_INTERP_NNN_RBF) {
1281 (struct yac_nnn_config){
1282 .type = YAC_INTERP_NNN_RBF, .n = n,
1283 .max_search_distance = max_search_distance,
1284 .data.rbf_scale = scale};
1285 } else {
1287 entry->n_nearest_neighbor.config =
1288 (struct yac_nnn_config){
1289 .type = type, .n = n, .max_search_distance = max_search_distance,
1290 .data.rbf_scale = scale};
1291 }
1292}
1293
1295 struct yac_interp_stack_config * interp_stack_config,
1296 size_t n, double max_search_distance, double scale) {
1297
1299 interp_stack_config, YAC_INTERP_NNN_RBF, n, max_search_distance, scale);
1300}
1302 struct yac_interp_stack_config * interp_stack_config,
1303 int type, size_t n, double max_search_distance, double scale) {
1304
1305 YAC_ASSERT(
1306 (type == YAC_INTERP_NNN_AVG) ||
1309 (type == YAC_INTERP_NNN_RBF) ||
1311 "ERROR(yac_interp_stack_config_add_nnn_f2c): "
1312 "type must be one of YAC_INTERP_NNN_AVG/YAC_INTERP_NNN_DIST/"
1313 "YAC_INTERP_NNN_GAUSS/YAC_INTERP_NNN_RBF/YAC_INTERP_NNN_ZERO.")
1314
1316 interp_stack_config, (enum yac_interp_nnn_weight_type)type, n,
1317 max_search_distance, scale);
1318}
1319
1321 struct yac_interp_stack_config * interp_stack_config,
1322 int order, int enforced_conserv, int partial_coverage,
1323 enum yac_interp_method_conserv_normalisation normalisation) {
1324
1325 union yac_interp_stack_config_entry * entry =
1326 yac_interp_stack_config_add_entry(interp_stack_config);
1327
1329 entry->conservative.order = order;
1333}
1334
1336 struct yac_interp_stack_config * interp_stack_config,
1338 int normalisation) {
1339
1340 YAC_ASSERT(
1343 "ERROR(yac_interp_stack_config_add_conservative_f2c): "
1344 "type must be one of "
1345 "YAC_INTERP_CONSERV_DESTAREA/YAC_INTERP_CONSERV_FRACAREA.")
1346
1348 interp_stack_config, order, enforced_conserv, partial_coverage,
1350}
1351
1352static struct yac_spmap_cell_area_config yac_spmap_cell_area_config_set(
1353 double sphere_radius, char const * filename,
1354 char const * varname, int min_global_id, char const * type) {
1355
1357 (sphere_radius == 0.0) ||
1358 ((sphere_radius != 0.0) &&
1359 ((filename == NULL) && (varname == NULL))),
1360 "ERROR(yac_spmap_cell_area_config_set): "
1361 "%s sphere_radius != 0.0, but filename and varname are not NULL", type);
1363 (sphere_radius != 0.0) ||
1364 ((sphere_radius == 0.0) &&
1365 ((filename != NULL) && (strlen(filename) > 0) && (filename[0] != '\0') &&
1366 (varname != NULL) && (strlen(varname) > 0) && (varname[0] != '\0'))),
1367 "ERROR(yac_spmap_cell_area_config_set): "
1368 "%s sphere_radius == 0.0, but filename and/or varname are invalid", type);
1369
1370 struct yac_spmap_cell_area_config cell_area_config;
1371 if (sphere_radius != 0.0)
1372 cell_area_config.cell_area_provider = YAC_INTERP_SPMAP_CELL_AREA_YAC;
1373 else
1374 cell_area_config.cell_area_provider = YAC_INTERP_SPMAP_CELL_AREA_FILE;
1375
1376 switch (cell_area_config.cell_area_provider) {
1377 default:
1379
1381 sphere_radius > 0.0,
1382 "ERROR(yac_spmap_cell_area_config_set): "
1383 "invalid %s sphere_radius (%.6lf)", type, sphere_radius)
1384 cell_area_config.sphere_radius = sphere_radius;
1385 cell_area_config.file_config.filename = NULL;
1386 cell_area_config.file_config.varname = NULL;
1387 cell_area_config.file_config.min_global_id = 0;
1388 break;
1389 }
1391
1392 cell_area_config.sphere_radius = 0.0;
1393 cell_area_config.file_config.filename = strdup(filename);
1394 cell_area_config.file_config.varname = strdup(varname);
1395 cell_area_config.file_config.min_global_id = (yac_int)min_global_id;
1396 break;
1397 }
1398 }
1399 return cell_area_config;
1400}
1401
1403 struct yac_interp_stack_config * interp_stack_config,
1404 double spread_distance, double max_search_distance,
1406 enum yac_interp_spmap_scale_type scale_type,
1407 double src_sphere_radius, char const * src_filename,
1408 char const * src_varname, int src_min_global_id,
1409 double tgt_sphere_radius, char const * tgt_filename,
1410 char const * tgt_varname, int tgt_min_global_id) {
1411
1412 union yac_interp_stack_config_entry * entry =
1413 yac_interp_stack_config_add_entry(interp_stack_config);
1414
1418 entry->spmap.weight_type = weight_type;
1419 entry->spmap.scale_config.type = scale_type;
1420 entry->spmap.scale_config.src =
1422 src_sphere_radius, src_filename,
1423 src_varname, src_min_global_id, "source");
1424 entry->spmap.scale_config.tgt =
1426 tgt_sphere_radius, tgt_filename,
1427 tgt_varname, tgt_min_global_id, "target");
1428}
1429
1431 struct yac_interp_stack_config * interp_stack_config,
1432 double spread_distance, double max_search_distance,
1433 int weight_type, int scale_type,
1434 double src_sphere_radius, char const * src_filename,
1435 char const * src_varname, int src_min_global_id,
1436 double tgt_sphere_radius, char const * tgt_filename,
1437 char const * tgt_varname, int tgt_min_global_id) {
1438
1439 YAC_ASSERT(
1442 "ERROR(yac_interp_stack_config_add_spmap_f2c): "
1443 "weight_type must be one of "
1444 "YAC_INTERP_SPMAP_AVG/YAC_INTERP_SPMAP_DIST.")
1445
1446 YAC_ASSERT(
1447 (scale_type == YAC_INTERP_SPMAP_NONE) ||
1448 (scale_type == YAC_INTERP_SPMAP_SRCAREA) ||
1449 (scale_type == YAC_INTERP_SPMAP_INVTGTAREA) ||
1450 (scale_type == YAC_INTERP_SPMAP_FRACAREA),
1451 "ERROR(yac_interp_stack_config_add_spmap_f2c): "
1452 "scale_type must be one of "
1453 "YAC_INTERP_SPMAP_NONE/YAC_INTERP_SPMAP_SRCAREA/"
1454 "YAC_INTERP_SPMAP_INVTGTAREA/YAC_INTERP_SPMAP_FRACAREA.")
1455
1456 if (src_filename && (src_filename[0] == '\0')) src_filename = NULL;
1457 if (src_varname && (src_varname[0] == '\0')) src_varname = NULL;
1458 if (tgt_filename && (tgt_filename[0] == '\0')) tgt_filename = NULL;
1459 if (tgt_varname && (tgt_varname[0] == '\0')) tgt_varname = NULL;
1460
1462 interp_stack_config, spread_distance, max_search_distance,
1464 (enum yac_interp_spmap_scale_type)scale_type,
1465 src_sphere_radius, src_filename, src_varname, src_min_global_id,
1466 tgt_sphere_radius, tgt_filename, tgt_varname, tgt_min_global_id);
1467}
1468
1470 struct yac_interp_stack_config * interp_stack_config) {
1471
1472 union yac_interp_stack_config_entry * entry =
1473 yac_interp_stack_config_add_entry(interp_stack_config);
1474
1476}
1477
1478static void check_string(
1479 char const * string, char const * file, int line, char const * routine,
1480 char const * variable) {
1481
1483 string != NULL, "ERROR(%s:%d:%s): %s is NULL",
1484 file, line, routine, variable)
1486 strlen(string) < YAC_MAX_FILE_NAME_LENGTH,
1487 "ERROR(%s:%d:%s): %s is too long", file, line, routine, variable)
1488}
1489
1491 struct yac_interp_stack_config * interp_stack_config,
1492 char const * filename,
1495
1497 filename, __FILE__, __LINE__,
1498 "yac_interp_stack_config_add_user_file", "filename");
1499
1500 union yac_interp_stack_config_entry * entry =
1501 yac_interp_stack_config_add_entry(interp_stack_config);
1502
1503 entry->user_file.type = YAC_USER_FILE;
1506 strcpy(entry->user_file.filename, filename);
1507}
1508
1510 struct yac_interp_stack_config * interp_stack_config,
1511 char const * filename, int on_missing_file, int on_success) {
1512
1513 if (filename && (filename[0] == '\0')) filename = NULL;
1514 YAC_ASSERT(
1517 "ERROR(yac_interp_stack_config_add_user_file_f2c): "
1518 "on_missing_file must be one of "
1519 "YAC_INTERP_FILE_MISSING_ERROR/YAC_INTERP_FILE_MISSING_CONT.")
1520 YAC_ASSERT(
1523 "ERROR(yac_interp_stack_config_add_user_file_f2c): "
1524 "on_success must be one of "
1525 "YAC_INTERP_FILE_SUCCESS_STOP/YAC_INTERP_FILE_SUCCESS_CONT.")
1526
1528 interp_stack_config, filename,
1531}
1532
1534 struct yac_interp_stack_config * interp_stack_config, double value) {
1535
1536 union yac_interp_stack_config_entry * entry =
1537 yac_interp_stack_config_add_entry(interp_stack_config);
1538
1539 entry->fixed.type = YAC_FIXED_VALUE;
1540 entry->fixed.value = value;
1541}
1542
1544 struct yac_interp_stack_config * interp_stack_config,
1545 char const * constructor_key, char const * do_search_key) {
1546
1549 "ERROR(yac_interp_stack_config_add_check): "
1550 "constructor_key name \"%s\" is too long "
1551 "(has to be smaller than %d)", constructor_key, YAC_MAX_ROUTINE_NAME_LENGTH);
1554 "ERROR(yac_interp_stack_config_add_check): "
1555 "do_search_key name \"%s\" is too long "
1556 "(has to be smaller than %d)", do_search_key, YAC_MAX_ROUTINE_NAME_LENGTH);
1557
1558 union yac_interp_stack_config_entry * entry =
1559 yac_interp_stack_config_add_entry(interp_stack_config);
1560
1561 entry->check.type = YAC_CHECK;
1562 if (constructor_key) {
1563 strcpy(entry->check.constructor_key, constructor_key);
1564 } else {
1565 memset(entry->check.constructor_key, '\0',
1566 sizeof(entry->check.constructor_key));
1567 }
1568 if (do_search_key) {
1569 strcpy(entry->check.do_search_key, do_search_key);
1570 } else {
1571 memset(entry->check.do_search_key, '\0',
1572 sizeof(entry->check.do_search_key));
1573 }
1574}
1575
1577 struct yac_interp_stack_config * interp_stack_config, int creep_distance) {
1578
1579 union yac_interp_stack_config_entry * entry =
1580 yac_interp_stack_config_add_entry(interp_stack_config);
1581
1582 entry->creep.type = YAC_CREEP;
1584}
1585
1587 struct yac_interp_stack_config * interp_stack_config,
1588 char const * func_compute_weights_key) {
1589
1591 func_compute_weights_key, __FILE__, __LINE__,
1592 "yac_interp_stack_config_add_user_callback",
1593 "func_compute_weights_key");
1594
1595 union yac_interp_stack_config_entry * entry =
1596 yac_interp_stack_config_add_entry(interp_stack_config);
1597
1599 strcpy(
1601}
1602
1604 struct yac_interp_stack_config * interp_stack) {
1605
1606 return interp_stack->size;
1607}
1608
1611 struct yac_interp_stack_config * interp_stack,
1612 size_t interp_stack_idx) {
1613
1614 YAC_ASSERT(
1615 interp_stack_idx < interp_stack->size,
1616 "ERROR(yac_interp_stack_config_get_entry): "
1617 "invalid interpolation stack index");
1618
1619 return interp_stack->config + interp_stack_idx;
1620}
1621
1622
1624 union yac_interp_stack_config_entry const * interp_stack_entry) {
1625
1626 return interp_stack_entry->general.type;
1627}
1628
1630 union yac_interp_stack_config_entry const * interp_stack_entry,
1632 int * partial_coverage) {
1633
1634 YAC_ASSERT(
1635 interp_stack_entry->general.type == YAC_AVERAGE,
1636 "ERROR(yac_interp_stack_config_entry_get_average): "
1637 "wrong interpolation stack entry type");
1638
1639 *reduction_type = interp_stack_entry->average.reduction_type;
1640 *partial_coverage = interp_stack_entry->average.partial_coverage;
1641}
1642
1644 union yac_interp_stack_config_entry const * interp_stack_entry,
1646
1647 YAC_ASSERT(
1648 (interp_stack_entry->general.type == YAC_NEAREST_CORNER_CELLS),
1649 "ERROR(yac_interp_stack_config_entry_get_ncc): "
1650 "wrong interpolation stack entry type");
1651
1652 *type = interp_stack_entry->nearest_corner_cells.weight_type;
1654 interp_stack_entry->nearest_corner_cells.partial_coverage;
1655}
1656
1658 union yac_interp_stack_config_entry const * interp_stack_entry,
1659 enum yac_interp_nnn_weight_type * type, size_t * n,
1660 double * max_search_distance, double * scale) {
1661
1662 YAC_ASSERT(
1663 (interp_stack_entry->general.type == YAC_N_NEAREST_NEIGHBOR) ||
1664 (interp_stack_entry->general.type == YAC_RADIAL_BASIS_FUNCTION),
1665 "ERROR(yac_interp_stack_config_entry_get_nnn): "
1666 "wrong interpolation stack entry type");
1667
1668 *type = interp_stack_entry->n_nearest_neighbor.config.type;
1669 *n = interp_stack_entry->n_nearest_neighbor.config.n;
1671 interp_stack_entry->n_nearest_neighbor.config.max_search_distance;
1672 *scale = interp_stack_entry->n_nearest_neighbor.config.data.rbf_scale;
1673}
1674
1676 union yac_interp_stack_config_entry const * interp_stack_entry,
1677 int * order, int * enforced_conserv, int * partial_coverage,
1679
1680 YAC_ASSERT(
1681 interp_stack_entry->general.type == YAC_CONSERVATIVE,
1682 "ERROR(yac_interp_stack_config_entry_get_conservative): "
1683 "wrong interpolation stack entry type");
1684
1685 *order = interp_stack_entry->conservative.order;
1686 *enforced_conserv = interp_stack_entry->conservative.enforced_conserv;
1687 *partial_coverage = interp_stack_entry->conservative.partial_coverage;
1688 *normalisation = interp_stack_entry->conservative.normalisation;
1689}
1690
1692 union yac_interp_stack_config_entry const * interp_stack_entry,
1693 double * spread_distance, double * max_search_distance,
1695 enum yac_interp_spmap_scale_type * scale_type,
1696 double * src_sphere_radius, char const ** src_filename,
1697 char const ** src_varname, int * src_min_global_id,
1698 double * tgt_sphere_radius, char const ** tgt_filename,
1699 char const ** tgt_varname, int * tgt_min_global_id) {
1700
1701 YAC_ASSERT(
1702 interp_stack_entry->general.type == YAC_SOURCE_TO_TARGET_MAP,
1703 "ERROR(yac_interp_stack_config_entry_get_spmap): "
1704 "wrong interpolation stack entry type");
1705
1706 *spread_distance = interp_stack_entry->spmap.spread_distance;
1707 *max_search_distance = interp_stack_entry->spmap.max_search_distance;
1708 *weight_type = interp_stack_entry->spmap.weight_type;
1709 *scale_type = interp_stack_entry->spmap.scale_config.type;
1710 *src_sphere_radius = interp_stack_entry->spmap.scale_config.src.sphere_radius;
1711 *src_filename =
1712 interp_stack_entry->spmap.scale_config.src.file_config.filename;
1713 *src_varname =
1714 interp_stack_entry->spmap.scale_config.src.file_config.varname;
1715 *src_min_global_id =
1716 interp_stack_entry->spmap.scale_config.src.file_config.min_global_id;
1717 *tgt_sphere_radius = interp_stack_entry->spmap.scale_config.tgt.sphere_radius;
1718 *tgt_filename =
1719 interp_stack_entry->spmap.scale_config.tgt.file_config.filename;
1720 *tgt_varname =
1721 interp_stack_entry->spmap.scale_config.tgt.file_config.varname;
1722 *tgt_min_global_id =
1723 interp_stack_entry->spmap.scale_config.tgt.file_config.min_global_id;
1724}
1725
1727 union yac_interp_stack_config_entry const * interp_stack_entry,
1728 char const ** filename,
1731
1732 YAC_ASSERT(
1733 interp_stack_entry->general.type == YAC_USER_FILE,
1734 "ERROR(yac_interp_stack_config_entry_get_user_file): "
1735 "wrong interpolation stack entry type");
1736
1737 *filename = interp_stack_entry->user_file.filename;
1738 *on_missing_file = interp_stack_entry->user_file.on_missing_file;
1739 *on_success = interp_stack_entry->user_file.on_success;
1740}
1741
1743 union yac_interp_stack_config_entry const * interp_stack_entry,
1744 double * value) {
1745
1746 YAC_ASSERT(
1747 interp_stack_entry->general.type == YAC_FIXED_VALUE,
1748 "ERROR(yac_interp_stack_config_entry_get_fixed): "
1749 "wrong interpolation stack entry type");
1750
1751 *value = interp_stack_entry->fixed.value;
1752}
1753
1755 union yac_interp_stack_config_entry const * interp_stack_entry,
1756 char const ** constructor_key, char const ** do_search_key) {
1757
1758 YAC_ASSERT(
1759 interp_stack_entry->general.type == YAC_CHECK,
1760 "ERROR(yac_interp_stack_config_entry_get_check): "
1761 "wrong interpolation stack entry type");
1762
1763 *constructor_key = interp_stack_entry->check.constructor_key;
1764 *do_search_key = interp_stack_entry->check.do_search_key;
1765}
1766
1768 union yac_interp_stack_config_entry const * interp_stack_entry,
1769 int * creep_distance) {
1770
1771 YAC_ASSERT(
1772 interp_stack_entry->general.type == YAC_CREEP,
1773 "ERROR(yac_interp_stack_config_entry_get_creep): "
1774 "wrong interpolation stack entry type");
1775
1776 *creep_distance = interp_stack_entry->creep.creep_distance;
1777}
1778
1780 union yac_interp_stack_config_entry const * interp_stack_entry,
1781 char const ** func_compute_weights_key) {
1782
1783 YAC_ASSERT(
1784 interp_stack_entry->general.type == YAC_USER_CALLBACK,
1785 "ERROR(yac_interp_stack_config_entry_get_user_callback): "
1786 "wrong interpolation stack entry type");
1787
1789 interp_stack_entry->user_callback.func_compute_weights_key;
1790}
#define YAC_ASSERT(exp, msg)
enum yac_interp_file_on_missing_file on_missing_file
enum yac_interp_file_on_success on_success
#define yac_angle_tol
Definition geometry.h:26
struct interp_method * yac_interp_method_avg_new(enum yac_interp_avg_weight_type weight_type, int partial_coverage)
yac_interp_avg_weight_type
@ YAC_INTERP_AVG_DIST
@ YAC_INTERP_AVG_ARITHMETIC
@ YAC_INTERP_AVG_BARY
void * user_data
void yac_interp_method_callback_get_compute_weights_callback(char const *key, yac_func_compute_weights *compute_weights_callback, void **user_data)
struct interp_method * yac_interp_method_callback_new(yac_func_compute_weights compute_weights_callback, void *user_data)
static size_t do_search_callback(struct interp_method *method, struct yac_interp_grid *interp_grid, size_t *tgt_points, size_t count, struct yac_interp_weights *weights, int *interpolation_complete)
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)
void yac_interp_method_check_get_do_search_callback(char const *key, func_do_search *do_search_callback, void **user_data)
void yac_interp_method_check_get_constructor_callback(char const *key, func_constructor *constructor_callback, void **user_data)
struct @14::@15 value
enum callback_type type
struct interp_method * yac_interp_method_check_new(func_constructor constructor_callback, void *constructor_user_data, func_do_search do_search_callback, void *do_search_user_data)
void(* func_do_search)(yac_int const *global_ids, double const (*coordinates_xyz)[3], size_t count, void *user_data)
void(* func_constructor)(void *user_data)
struct interp_method * yac_interp_method_conserv_new(int order, int enforced_conserv, int partial_coverage, enum yac_interp_method_conserv_normalisation normalisation)
yac_interp_method_conserv_normalisation
@ YAC_INTERP_CONSERV_DESTAREA
@ YAC_INTERP_CONSERV_FRACAREA
struct interp_method * yac_interp_method_creep_new(int creep_distance)
struct interp_method * yac_interp_method_file_new(char const *weight_file_name, enum yac_interp_file_on_missing_file on_missing_file, enum yac_interp_file_on_success on_success)
yac_interp_file_on_missing_file
@ YAC_INTERP_FILE_MISSING_CONT
continue on missing file
@ YAC_INTERP_FILE_MISSING_ERROR
abort on missing file
yac_interp_file_on_success
@ YAC_INTERP_FILE_SUCCESS_CONT
@ YAC_INTERP_FILE_SUCCESS_STOP
struct interp_method * yac_interp_method_fixed_new(double value)
struct interp_method * yac_interp_method_hcsbb_new()
struct interp_method * yac_interp_method_ncc_new(enum yac_interp_ncc_weight_type weight_type, int partial_coverage)
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
struct interp_method * yac_interp_method_nnn_new(struct yac_nnn_config config)
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
struct interp_method * yac_interp_method_spmap_new(double spread_distance, double max_search_distance, enum yac_interp_spmap_weight_type weight_type, struct yac_spmap_scale_config scale_config)
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_cell_area_provider
@ YAC_INTERP_SPMAP_CELL_AREA_FILE
@ YAC_INTERP_SPMAP_CELL_AREA_YAC
yac_interp_spmap_weight_type
@ YAC_INTERP_SPMAP_AVG
@ YAC_INTERP_SPMAP_DIST
void yac_interp_stack_config_entry_get_creep(union yac_interp_stack_config_entry const *interp_stack_entry, int *creep_distance)
void yac_interp_stack_config_add_check(struct yac_interp_stack_config *interp_stack_config, char const *constructor_key, char const *do_search_key)
size_t yac_interp_stack_config_get_size(struct yac_interp_stack_config *interp_stack)
int yac_interp_stack_config_compare(void const *a_, void const *b_)
static union yac_interp_stack_config_entry * yac_interp_stack_config_add_entry(struct yac_interp_stack_config *interp_stack_config)
static void yac_spmap_cell_area_config_unpack(void *buffer, int buffer_size, int *position, struct yac_spmap_cell_area_config *cell_area_config, MPI_Comm comm)
static void yac_spmap_cell_area_config_pack(struct yac_spmap_cell_area_config cell_area_config, void *buffer, int buffer_size, int *position, MPI_Comm comm)
static struct yac_spmap_cell_area_config yac_spmap_cell_area_config_set(double sphere_radius, char const *filename, char const *varname, int min_global_id, char const *type)
union yac_interp_stack_config_entry const * yac_interp_stack_config_get_entry(struct yac_interp_stack_config *interp_stack, size_t interp_stack_idx)
static void yac_interp_stack_config_pack_string(char const *string, void *buffer, int buffer_size, int *position, MPI_Comm comm)
enum yac_interpolation_list yac_interp_stack_config_entry_get_type(union yac_interp_stack_config_entry const *interp_stack_entry)
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, char const *src_filename, char const *src_varname, int src_min_global_id, double tgt_sphere_radius, char const *tgt_filename, char const *tgt_varname, int tgt_min_global_id)
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_rbf(struct yac_interp_stack_config *interp_stack_config, size_t n, double max_search_distance, double scale)
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)
static void yac_interp_stack_config_pack_entry(union yac_interp_stack_config_entry *entry, void *buffer, int buffer_size, int *position, MPI_Comm comm)
void yac_interp_stack_config_add_creep(struct yac_interp_stack_config *interp_stack_config, int creep_distance)
static size_t yac_interp_stack_config_get_string_pack_size(char const *string, MPI_Comm comm)
void yac_interp_stack_config_entry_get_user_file(union yac_interp_stack_config_entry const *interp_stack_entry, char const **filename, enum yac_interp_file_on_missing_file *on_missing_file, enum yac_interp_file_on_success *on_success)
static int yac_spmap_cell_area_config_compare(struct yac_spmap_cell_area_config a, struct yac_spmap_cell_area_config b)
static size_t yac_spmap_cell_area_config_get_pack_size(struct yac_spmap_cell_area_config cell_area_config, MPI_Comm comm)
static int yac_spmap_scale_config_compare(struct yac_spmap_scale_config a, struct yac_spmap_scale_config b)
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 max_search_distance, double scale)
void yac_interp_stack_config_add_spmap_f2c(struct yac_interp_stack_config *interp_stack_config, double spread_distance, double max_search_distance, int weight_type, int scale_type, double src_sphere_radius, char const *src_filename, char const *src_varname, int src_min_global_id, double tgt_sphere_radius, char const *tgt_filename, char const *tgt_varname, int tgt_min_global_id)
void yac_interp_stack_config_entry_get_ncc(union yac_interp_stack_config_entry const *interp_stack_entry, enum yac_interp_ncc_weight_type *type, int *partial_coverage)
void yac_interp_stack_config_add_conservative_f2c(struct yac_interp_stack_config *interp_stack_config, int order, int enforced_conserv, int partial_coverage, int normalisation)
static void yac_interp_stack_config_unpack_entry(void *buffer, int buffer_size, int *position, union yac_interp_stack_config_entry *entry, MPI_Comm comm)
struct yac_interp_stack_config * yac_interp_stack_config_unpack(void *buffer, int buffer_size, int *position, MPI_Comm comm)
void yac_interp_stack_config_add_ncc_f2c(struct yac_interp_stack_config *interp_stack_config, int weight_type, int partial_coverage)
static void check_interpolation_type(enum yac_interpolation_list type, char const *routine)
void yac_interp_stack_config_delete(struct yac_interp_stack_config *interp_stack_config)
void yac_interp_stack_config_entry_get_user_callback(union yac_interp_stack_config_entry const *interp_stack_entry, char const **func_compute_weights_key)
struct yac_interp_stack_config * yac_interp_stack_config_copy(struct yac_interp_stack_config *interp_stack)
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_entry_get_check(union yac_interp_stack_config_entry const *interp_stack_entry, char const **constructor_key, char const **do_search_key)
static int yac_interp_stack_config_entry_compare(void const *a_, void const *b_)
struct interp_method ** yac_interp_stack_config_generate(struct yac_interp_stack_config *interp_stack)
void yac_interp_stack_config_entry_get_conservative(union yac_interp_stack_config_entry const *interp_stack_entry, int *order, int *enforced_conserv, int *partial_coverage, enum yac_interp_method_conserv_normalisation *normalisation)
static char * yac_interp_stack_config_unpack_string(void *buffer, int buffer_size, int *position, MPI_Comm comm)
void yac_interp_stack_config_entry_get_average(union yac_interp_stack_config_entry const *interp_stack_entry, enum yac_interp_avg_weight_type *reduction_type, int *partial_coverage)
size_t yac_interp_stack_config_get_pack_size(struct yac_interp_stack_config *interp_stack, MPI_Comm comm)
void yac_interp_stack_config_add_average_f2c(struct yac_interp_stack_config *interp_stack_config, int reduction_type, int partial_coverage)
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_nnn_f2c(struct yac_interp_stack_config *interp_stack_config, int type, size_t n, double max_search_distance, double scale)
void yac_interp_stack_config_add_user_file(struct yac_interp_stack_config *interp_stack_config, char const *filename, enum yac_interp_file_on_missing_file on_missing_file, enum yac_interp_file_on_success on_success)
void yac_interp_stack_config_entry_get_nnn(union yac_interp_stack_config_entry const *interp_stack_entry, enum yac_interp_nnn_weight_type *type, size_t *n, double *max_search_distance, double *scale)
void yac_interp_stack_config_add_user_callback(struct yac_interp_stack_config *interp_stack_config, char const *func_compute_weights_key)
static void yac_interp_stack_config_unpack_n_string(void *buffer, int buffer_size, int *position, char *string, int max_string_len, MPI_Comm comm)
struct yac_interp_stack_config * yac_interp_stack_config_new()
static void yac_interp_stack_config_entry_free(union yac_interp_stack_config_entry *entry)
void yac_interp_stack_config_pack(struct yac_interp_stack_config *interp_stack, void *buffer, int buffer_size, int *position, MPI_Comm comm)
static void check_string(char const *string, char const *file, int line, char const *routine, char const *variable)
static void yac_interp_stack_config_entry_copy(union yac_interp_stack_config_entry *to, union yac_interp_stack_config_entry *from)
void yac_interp_stack_config_entry_get_fixed(union yac_interp_stack_config_entry const *interp_stack_entry, double *value)
void yac_interp_stack_config_entry_get_spmap(union yac_interp_stack_config_entry const *interp_stack_entry, 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, char const **src_filename, char const **src_varname, int *src_min_global_id, double *tgt_sphere_radius, char const **tgt_filename, char const **tgt_varname, int *tgt_min_global_id)
static size_t yac_interp_stack_config_get_entry_pack_size(union yac_interp_stack_config_entry *entry, MPI_Comm comm)
void yac_interp_stack_config_add_user_file_f2c(struct yac_interp_stack_config *interp_stack_config, char const *filename, int on_missing_file, int on_success)
yac_interpolation_list
@ YAC_N_NEAREST_NEIGHBOR
@ YAC_CREEP
@ YAC_USER_FILE
@ YAC_USER_CALLBACK
@ YAC_SOURCE_TO_TARGET_MAP
@ YAC_CONSERVATIVE
@ YAC_FIXED_VALUE
@ YAC_UNDEFINED
@ YAC_CHECK
@ YAC_BERNSTEIN_BEZIER
@ YAC_NEAREST_CORNER_CELLS
@ YAC_RADIAL_BASIS_FUNCTION
@ YAC_AVERAGE
#define YAC_MAX_ROUTINE_NAME_LENGTH
#define YAC_MAX_FILE_NAME_LENGTH
#define xrealloc(ptr, size)
Definition ppm_xfuncs.h:67
#define xmalloc(size)
Definition ppm_xfuncs.h:66
union yac_interp_stack_config_entry * config
union yac_nnn_config::@28 data
enum yac_interp_nnn_weight_type type
struct yac_spmap_scale_config::yac_spmap_cell_area_config::yac_spmap_cell_area_file_config file_config
struct yac_spmap_scale_config::yac_spmap_cell_area_config src
struct yac_spmap_scale_config::yac_spmap_cell_area_config tgt
enum yac_interp_spmap_scale_type type
char const * weight_file_name
double * buffer
static void compute_weights_callback(double const tgt_coords[3], int src_cell_id, size_t src_cell_idx, int const **global_results_points, double **result_weights, size_t *result_count, void *user_data)
struct yac_interp_stack_config_entry::@30 average
enum yac_interp_ncc_weight_type weight_type
double value
char do_search_key[YAC_MAX_ROUTINE_NAME_LENGTH]
double max_search_distance
struct yac_interp_stack_config_entry::@33 spmap
enum yac_interpolation_list type
struct yac_interp_stack_config_entry::@38 creep
int partial_coverage
struct yac_nnn_config config
struct yac_interp_stack_config_entry::@40 nearest_corner_cells
int creep_distance
int enforced_conserv
enum yac_interp_file_on_missing_file on_missing_file
struct yac_interp_stack_config_entry::@29 general
struct yac_interp_stack_config_entry::@31 n_nearest_neighbor
int order
double spread_distance
char constructor_key[YAC_MAX_ROUTINE_NAME_LENGTH]
enum yac_interp_avg_weight_type reduction_type
enum yac_interp_method_conserv_normalisation normalisation
struct yac_interp_stack_config_entry::@36 fixed
char filename[YAC_MAX_FILE_NAME_LENGTH]
enum yac_interp_spmap_weight_type weight_type
struct yac_interp_stack_config_entry::@34 hcsbb
struct yac_interp_stack_config_entry::@35 user_file
enum yac_interp_file_on_success on_success
struct yac_interp_stack_config_entry::@31 radial_basis_function
struct yac_interp_stack_config_entry::@32 conservative
struct yac_interp_stack_config_entry::@37 check
struct yac_interp_stack_config_entry::@39 user_callback
char func_compute_weights_key[YAC_MAX_ROUTINE_NAME_LENGTH]
struct yac_spmap_scale_config scale_config
#define YAC_ASSERT_F(exp, format,...)
Definition yac_assert.h:19
#define yac_mpi_call(call, comm)
Xt_int yac_int
Definition yac_types.h:15