67 cpl_field->
name =
xmalloc((strlen(field_name) + 1));
68 strcpy(cpl_field->
name, field_name);
81 "ERROR: num_interp_fields > 0 but not interpolation field provided")
95 return field->collection_size;
100 return field->timestep;
105 return field->num_interp_fields;
112 return field->interp_fields[interp_field_idx].location;
128 return field->component_name;
134 return field->exchange_type;
150 struct coupling_field * field,
double init_value,
double *** acc) {
152 size_t num_interp_fields = field->num_interp_fields;
156 for (
size_t j = 0; j < num_interp_fields; j++) {
163 acc[h][j][m] = init_value;
172 char const * routine_name,
double **** acc) {
175 field->exchange_type ==
SOURCE,
176 "ERROR(%s): wrong field exchange type", routine_name)
179 put_idx < field->exchange_data.put.num_puts,
180 "ERROR(%s): put_idx is invalid", routine_name)
182 if (*acc != NULL)
return;
184 size_t num_interp_fields = field->num_interp_fields;
193 (*acc)[h] =
xmalloc(num_interp_fields *
sizeof(***acc));
195 for (
size_t j = 0; j < num_interp_fields; j++)
199 field->interp_fields[j], field->grid) *
sizeof(****acc));
210 field, put_idx,
"yac_get_coupling_field_put_op_send_field_acc",
211 &(field->exchange_data.put.puts[put_idx].send_field_acc));
213 return field->exchange_data.put.puts[put_idx].send_field_acc;
220 field, put_idx,
"yac_get_coupling_field_put_op_send_frac_mask_acc",
221 &(field->exchange_data.put.puts[put_idx].send_frac_mask_acc));
223 return field->exchange_data.put.puts[put_idx].send_frac_mask_acc;
229 int const * core_mask =
231 field->grid, field->interp_fields[field_idx].location);
236 if (core_mask != NULL) {
242 for (
size_t i = 0; (i < field_size) && !
flag; ++i)
243 flag = core_mask[i] != 1;
252 int const * field_mask =
254 field->grid, field->interp_fields[field_idx]);
259 if (field_mask != NULL) {
265 for (
size_t i = 0; (i < field_size) && !
flag; ++i)
266 flag = field_mask[i] != 1;
275 field->exchange_type ==
SOURCE,
276 "ERROR(yac_get_coupling_field_put_mask): "
277 "wrong field exchange type")
279 if (field->exchange_data.put.mask != NULL)
280 return field->exchange_data.put.mask;
282 size_t num_interp_fields = field->num_interp_fields;
286 for (
size_t i = 0; (i < num_interp_fields) && !has_mask; ++i)
296 for (
size_t i = 0; i < num_interp_fields; ++i) {
297 int const * core_mask =
299 field->grid, field->interp_fields[i].location);
300 int const * field_mask =
302 field->grid, field->interp_fields[i]);
306 for (
size_t j = 0; j < field_size; ++j)
307 mask[i][j] = ((core_mask == NULL) || (core_mask[j] != 0)) &&
308 ((field_mask == NULL) || (field_mask[j] != 0));
312 field->exchange_data.put.mask =
mask;
320 field->exchange_type ==
TARGET,
321 "ERROR(yac_get_coupling_field_put_mask): "
322 "wrong field exchange type")
324 if (field->exchange_data.get.mask != NULL)
325 return field->exchange_data.get.mask;
335 int const * core_mask =
337 field->grid, field->interp_fields[0].location);
338 int const * field_mask =
340 field->grid, field->interp_fields[0]);
344 for (
size_t i = 0; i < field_size; ++i)
345 mask[i] = ((core_mask == NULL) || (core_mask[i] != 0)) &&
346 ((field_mask == NULL) || (field_mask[i] != 0));
349 field->exchange_data.get.mask =
mask;
355 struct coupling_field * field,
unsigned put_idx,
double init_value) {
358 field->exchange_type ==
SOURCE,
359 "ERROR(yac_init_coupling_field_put_op_send_field_acc): "
360 "wrong field exchange type")
363 put_idx < field->exchange_data.put.num_puts,
364 "ERROR(yac_init_coupling_field_put_op_send_field_acc): "
365 "put_idx is invalid")
367 double *** send_field_acc =
368 (field->exchange_data.put.puts[put_idx].send_field_acc == NULL)?
370 field->exchange_data.put.puts[put_idx].send_field_acc;
376 struct coupling_field * field,
unsigned put_idx,
double init_value) {
379 field->exchange_type ==
SOURCE,
380 "ERROR(yac_init_coupling_field_put_op_send_frac_mask_acc): "
381 "wrong field exchange type")
384 put_idx < field->exchange_data.put.num_puts,
385 "ERROR(yac_init_coupling_field_put_op_send_frac_mask_acc): "
386 "put_idx is invalid")
388 double *** send_frac_mask_acc =
389 (field->exchange_data.put.puts[put_idx].send_frac_mask_acc == NULL)?
391 field->exchange_data.put.puts[put_idx].send_frac_mask_acc;
400 field->exchange_type ==
SOURCE,
401 "ERROR(yac_get_coupling_field_put_op_event): wrong field exchange type")
404 put_idx < field->exchange_data.put.num_puts,
405 "ERROR(yac_get_coupling_field_put_op_event): put_idx is invalid")
407 return field->exchange_data.put.puts[put_idx].event;
414 field->exchange_type ==
SOURCE,
415 "ERROR(yac_get_coupling_field_put_op_interpolation): "
416 "wrong field exchange type")
419 put_idx < field->exchange_data.put.num_puts,
420 "ERROR(yac_get_coupling_field_put_op_interpolation): "
421 "put_idx is invalid")
424 !field->exchange_data.put.puts[put_idx].use_raw_exchange,
425 "ERROR(yac_get_coupling_field_put_op_interpolation): "
426 "exchange is configured to use raw data exchange")
428 return field->exchange_data.put.puts[put_idx].interpolation;
436 field->exchange_type ==
SOURCE,
437 "ERROR(yac_get_coupling_field_put_op_interpolation_exchange): "
438 "wrong field exchange type")
441 put_idx < field->exchange_data.put.num_puts,
442 "ERROR(yac_get_coupling_field_put_op_interpolation_exchange): "
443 "put_idx is invalid")
446 field->exchange_data.put.puts[put_idx].use_raw_exchange,
447 "ERROR(yac_get_coupling_field_put_op_interpolation_exchange): "
448 "exchange is not configured to use raw data exchange")
450 return field->exchange_data.put.puts[put_idx].interpolation_exchange;
457 field->exchange_type ==
SOURCE,
458 "ERROR(yac_get_coupling_field_put_op_time_accumulation_count): "
459 "wrong field exchange type")
462 put_idx < field->exchange_data.put.num_puts,
463 "ERROR(yac_get_coupling_field_put_op_time_accumulation_count): "
464 "put_idx is invalid")
466 return field->exchange_data.put.puts[put_idx].time_accumulation_count;
473 field->exchange_type ==
SOURCE,
474 "ERROR(yac_get_coupling_field_put_op_use_raw_exchange): "
475 "wrong field exchange type")
478 put_idx < field->exchange_data.put.num_puts,
479 "ERROR(yac_get_coupling_field_put_op_use_raw_exchange): "
480 "put_idx is invalid")
482 return field->exchange_data.put.puts[put_idx].use_raw_exchange;
489 field->exchange_type ==
SOURCE,
490 "ERROR(yac_set_coupling_field_put_op_time_accumulation_count): "
491 "wrong field exchange type")
494 put_idx < field->exchange_data.put.num_puts,
495 "ERROR(yac_set_coupling_field_put_op_time_accumulation_count): "
496 "put_idx is invalid")
498 field->exchange_data.put.puts[put_idx].time_accumulation_count =
count;
504 field->exchange_type ==
SOURCE,
505 "ERROR(yac_get_coupling_field_num_puts): wrong field exchange type")
507 return field->exchange_data.put.num_puts;
514 field->exchange_type ==
TARGET,
515 "ERROR(yac_get_coupling_field_get_op_event): "
516 "wrong field exchange type")
518 return field->exchange_data.get.event;
525 field->exchange_type ==
TARGET,
526 "ERROR(yac_get_coupling_field_get_op_use_raw_exchange): "
527 "wrong field exchange type")
529 return field->exchange_data.get.use_raw_exchange;
536 field->exchange_type ==
TARGET,
537 "ERROR(yac_get_coupling_field_get_op_with_frac_mask): "
538 "wrong field exchange type")
541 field->exchange_data.get.interp_weights_data.frac_mask_fallback_value);
548 field->exchange_type ==
TARGET,
549 "ERROR(yac_get_coupling_field_get_op_interpolation): "
550 "wrong field exchange type")
553 !field->exchange_data.get.use_raw_exchange,
554 "ERROR(yac_get_coupling_field_get_op_interpolation): "
555 "exchange is configured to use raw data exchange")
557 return field->exchange_data.get.interpolation;
565 field->exchange_type ==
TARGET,
566 "ERROR(yac_get_coupling_field_get_op_interpolation_exchange): "
567 "wrong field exchange type")
570 field->exchange_data.get.use_raw_exchange,
571 "ERROR(yac_get_coupling_field_get_op_interpolation_exchange): "
572 "exchange is not configured to use raw data exchange")
574 return field->exchange_data.get.interpolation_exchange;
582 field->exchange_type ==
TARGET,
583 "ERROR(yac_get_coupling_field_get_op_interp_weights_data): "
584 "wrong field exchange type")
587 field->exchange_data.get.use_raw_exchange,
588 "ERROR(yac_get_coupling_field_get_op_interp_weights_data): "
589 "exchange is not configured to use raw data exchange")
592 field->exchange_data.get.interp_weights_data;
601 field->exchange_data.get.interp_weights_data.num_src_fields =
num_src_fields;
602 field->exchange_data.get.interp_weights_data.src_field_buffer_size =
605 field->exchange_data.get.interp_weights_data.src_field_buffer_size,
606 src_field_buffer_sizes,
num_src_fields *
sizeof(*src_field_buffer_sizes));
613 size_t const ** src_field_buffer_sizes) {
616 field->exchange_type ==
TARGET,
617 "ERROR(yac_get_coupling_field_get_op_interp_weights_data): "
618 "wrong field exchange type")
621 field->exchange_data.get.use_raw_exchange,
622 "ERROR(yac_get_coupling_field_get_op_interp_weights_data): "
623 "exchange is not configured to use raw data exchange")
626 field->exchange_data.get.interp_weights_data.num_src_fields;
627 if (src_field_buffer_sizes)
628 *src_field_buffer_sizes =
629 field->exchange_data.get.interp_weights_data.src_field_buffer_size;
636 int use_raw_exchange) {
639 field->exchange_type !=
TARGET,
640 "ERROR(yac_set_coupling_field_put_op_): "
641 "a get operation has already been set (field \"%s\")", field->name)
643 if (field->exchange_type ==
NOTHING) {
644 field->exchange_data.put.puts = NULL;
645 field->exchange_data.put.num_puts = 0;
646 field->exchange_type =
SOURCE;
647 field->exchange_data.put.mask = NULL;
650 unsigned num_puts = field->exchange_data.put.num_puts;
651 field->exchange_data.put.num_puts++;
653 field->exchange_data.put.puts =
654 xrealloc(field->exchange_data.put.puts, (num_puts + 1) *
655 sizeof(*(field->exchange_data.put.puts)));
657 field->exchange_data.put.puts[num_puts].event =
event;
658 field->exchange_data.put.puts[num_puts].interpolation = interpolation;
659 field->exchange_data.put.puts[num_puts].interpolation_exchange = interpolation_exchange;
660 field->exchange_data.put.puts[num_puts].time_accumulation_count = 0;
661 field->exchange_data.put.puts[num_puts].send_field_acc = NULL;
662 field->exchange_data.put.puts[num_puts].send_frac_mask_acc = NULL;
663 field->exchange_data.put.puts[num_puts].use_raw_exchange = use_raw_exchange;
671 field,
event, interpolation, NULL, 0);
679 field,
event, NULL, interpolation_exchange, 1);
687 int use_raw_exchange) {
690 field->exchange_type ==
NOTHING,
691 "ERROR(yac_set_coupling_field_get_op_): "
692 "a put or get operation has already been set (field \"%s\")", field->name)
694 field->exchange_type =
TARGET;
695 field->exchange_data.get.event =
event;
696 field->exchange_data.get.interpolation = interpolation;
697 field->exchange_data.get.interpolation_exchange = interpolation_exchange;
699 field->exchange_data.get.mask = NULL;
700 field->exchange_data.get.use_raw_exchange = use_raw_exchange;
709 .scaling_factor = 1.0,
710 .scaling_summand = 0.0,
712 .num_fixed_values = 0,
713 .fixed_values = NULL,
714 .num_tgt_per_fixed_value = NULL,
715 .tgt_idx_fixed = NULL,
719 .num_src_per_tgt = NULL,
721 .src_field_idx = NULL,
724 .src_field_buffer_size = NULL
728 field,
event, interpolation, NULL, dummy_interp_weights_data, 0);
751 "ERROR(yac_coupling_field_get_datetime): "
752 "datetime is not defined for non-exchanged fields "
753 "(field \"%s\")", cpl_field->
name);
754 struct event *
event =
778 double ***send_field_acc =
780 double ***send_frac_mask_acc =
783 if (send_field_acc != NULL) {
785 for (
size_t j = 0; j < num_interp_fields; ++j)
786 free(send_field_acc[h][j]);
787 free(send_field_acc[h]);
789 free(send_field_acc);
792 if (send_frac_mask_acc != NULL) {
794 for (
size_t j = 0; j < num_interp_fields; ++j)
795 free(send_frac_mask_acc[h][j]);
796 free(send_frac_mask_acc[h]);
798 free(send_frac_mask_acc);
804 interpolation_exchange,
"yac_coupling_field_delete");
809 for (
size_t i = 0; i < num_interp_fields; ++i)
820 "yac_coupling_field_delete");
827 free(cpl_field->
name);
#define YAC_ASSERT(exp, msg)
int const * yac_basic_grid_get_field_mask(struct yac_basic_grid *grid, struct yac_interp_field field)
size_t yac_basic_grid_get_data_size(struct yac_basic_grid *grid, enum yac_location location)
int const * yac_basic_grid_get_core_mask(struct yac_basic_grid *grid, enum yac_location location)
void yac_event_delete(struct event *event)
char * yac_get_event_current_datetime(struct event *event, char *datetime_str)
struct yac_interpolation_exchange * yac_get_coupling_field_put_op_interpolation_exchange(struct coupling_field *field, unsigned put_idx)
void yac_set_coupling_field_put_op(struct coupling_field *field, struct event *event, struct yac_interpolation *interpolation)
static void yac_set_coupling_field_get_op_(struct coupling_field *field, struct event *event, struct yac_interpolation *interpolation, struct yac_interpolation_exchange *interpolation_exchange, struct yac_interp_weights_data interp_weights_data, int use_raw_exchange)
unsigned yac_get_coupling_field_collection_size(struct coupling_field *field)
static int check_core_mask(struct coupling_field *field, size_t field_idx)
const char * yac_get_coupling_field_timestep(struct coupling_field *field)
unsigned yac_get_coupling_field_num_puts(struct coupling_field *field)
void yac_set_coupling_field_get_op(struct coupling_field *field, struct event *event, struct yac_interpolation *interpolation)
char const * yac_get_coupling_field_comp_name(struct coupling_field *field)
int yac_get_coupling_field_put_op_time_accumulation_count(struct coupling_field *field, unsigned put_idx)
double *** yac_get_coupling_field_put_op_send_frac_mask_acc(struct coupling_field *field, unsigned put_idx)
struct yac_basic_grid * yac_coupling_field_get_basic_grid(struct coupling_field *field)
static void yac_set_coupling_field_put_op_(struct coupling_field *field, struct event *event, struct yac_interpolation *interpolation, struct yac_interpolation_exchange *interpolation_exchange, int use_raw_exchange)
size_t yac_coupling_field_get_num_interp_fields(struct coupling_field *field)
struct yac_interpolation * yac_get_coupling_field_put_op_interpolation(struct coupling_field *field, unsigned put_idx)
enum yac_location yac_get_coupling_field_get_interp_field_location(struct coupling_field *field, size_t interp_field_idx)
struct event * yac_get_coupling_field_get_op_event(struct coupling_field *field)
static size_t get_interp_field_size(struct yac_interp_field field, struct yac_basic_grid *grid)
void yac_set_coupling_field_put_op_raw(struct coupling_field *field, struct event *event, struct yac_interpolation_exchange *interpolation_exchange)
size_t yac_coupling_field_get_data_size(struct coupling_field *field, enum yac_location location)
struct yac_interp_field const * yac_coupling_field_get_interp_fields(struct coupling_field *cpl_field)
struct coupling_field * yac_coupling_field_new(char const *field_name, char const *component_name, struct yac_basic_grid *grid, struct yac_interp_field *interp_fields, unsigned num_interp_fields, size_t collection_size, const char *timestep)
int * yac_get_coupling_field_get_mask(struct coupling_field *field)
static void init_put_op_acc(struct coupling_field *field, double init_value, double ***acc)
struct event * yac_get_coupling_field_put_op_event(struct coupling_field *field, unsigned put_idx)
char * yac_coupling_field_get_datetime(struct coupling_field *cpl_field)
void yac_init_coupling_field_put_op_send_field_acc(struct coupling_field *field, unsigned put_idx, double init_value)
struct yac_interpolation * yac_get_coupling_field_get_op_interpolation(struct coupling_field *field)
void yac_coupling_field_get_src_field_buffer_sizes(struct coupling_field *field, size_t *num_src_fields, size_t const **src_field_buffer_sizes)
void yac_set_coupling_field_put_op_time_accumulation_count(struct coupling_field *field, unsigned put_idx, int count)
int yac_get_coupling_field_get_op_use_raw_exchange(struct coupling_field *field)
struct yac_interpolation_exchange * yac_get_coupling_field_get_op_interpolation_exchange(struct coupling_field *field)
int yac_get_coupling_field_get_op_with_frac_mask(struct coupling_field *field)
enum yac_field_exchange_type yac_get_coupling_field_exchange_type(struct coupling_field *field)
const char * yac_get_coupling_field_name(struct coupling_field *field)
void yac_set_coupling_field_get_op_raw(struct coupling_field *field, struct event *event, struct yac_interpolation_exchange *interpolation_exchange, struct yac_interp_weights_data interp_weights_data)
static int check_field_mask(struct coupling_field *field, size_t field_idx)
void yac_coupling_field_delete(struct coupling_field *cpl_field)
int ** yac_get_coupling_field_put_mask(struct coupling_field *field)
struct yac_interp_weights_data yac_get_coupling_field_get_op_interp_weights_data(struct coupling_field *field)
void yac_init_coupling_field_put_op_send_frac_mask_acc(struct coupling_field *field, unsigned put_idx, double init_value)
static void get_put_op_acc(struct coupling_field *field, unsigned put_idx, char const *routine_name, double ****acc)
double *** yac_get_coupling_field_put_op_send_field_acc(struct coupling_field *field, unsigned put_idx)
int yac_get_coupling_field_put_op_use_raw_exchange(struct coupling_field *field, unsigned put_idx)
void yac_interp_weights_data_init(struct yac_interp_weights_data *interp_weights_data)
void yac_interp_weights_data_free(struct yac_interp_weights_data interp_weights_data)
void yac_interpolation_delete(struct yac_interpolation *interp)
double const YAC_FRAC_MASK_UNDEF
#define YAC_FRAC_MASK_VALUE_IS_VALID(value)
void yac_interpolation_exchange_delete(struct yac_interpolation_exchange *exchange, char const *routine_name)
#define xrealloc(ptr, size)
double *** send_field_acc
int time_accumulation_count
double *** send_frac_mask_acc
struct yac_interpolation_exchange * interpolation_exchange
struct yac_basic_grid * grid
struct coupling_field::@69::@71 get
char current_datetime[MAX_DATETIME_STR_LEN]
struct coupling_field::@69::@70::@72 * puts
union coupling_field::@69 exchange_data
struct yac_interp_field * interp_fields
enum yac_field_exchange_type exchange_type
struct yac_interp_weights_data interp_weights_data
struct coupling_field::@69::@70 put
size_t collection_size
number of vertical levels or bundles
struct yac_interpolation * interpolation
double frac_mask_fallback_value
double frac_mask_fallback_value
#define YAC_ASSERT_F(exp, format,...)