YAC 3.13.0
Yet Another Coupler
Loading...
Searching...
No Matches
interpolation_gen_config.c
Go to the documentation of this file.
1// Copyright (c) 2025 The YAC Authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#include <stdlib.h>
6#include <string.h>
7
8#include <mpi.h>
9
10#include "ppm/ppm_xfuncs.h"
11
13#include "utils_core.h"
17#include "yac_mpi_internal.h"
18
57
60
61 struct yac_interpolation_gen_config * config = xmalloc(1 * sizeof(*config));
62
64 config->collection_selection = NULL; // unset
65
66 // fractional masking is deactivated by default
68 config->scaling_factor = 1.0;
69 config->scaling_summand = 0.0;
70 config->yaxt_exchanger_name = NULL;
71
72 return config;
73}
74
76 struct yac_interpolation_gen_config * config) {
77
78 if (config == NULL) return;
80 free(config->yaxt_exchanger_name);
81 free(config);
82}
83
85 struct yac_interpolation_gen_config const * src) {
86
87 if (src == NULL) return NULL;
88
89 struct yac_interpolation_gen_config * copy = xmalloc(1 * sizeof(*copy));
90
91 memcpy(copy, src, sizeof(*copy));
93 yac_collection_selection_copy(src->collection_selection);
94 if (src->yaxt_exchanger_name != NULL) {
95 copy->yaxt_exchanger_name = strdup(src->yaxt_exchanger_name);
96 }
97
98 return copy;
99}
100
101/* ---------------- Setters ---------------- */
102
104 struct yac_interpolation_gen_config * config,
106
108 config != NULL,
109 "ERROR(yac_interpolation_gen_config_set_reorder): config is NULL");
113 "ERROR(yac_interpolation_gen_config_set_reorder): invalid reorder value");
114
115 config->reorder = reorder;
116}
117
118
120 struct yac_interpolation_gen_config * config, int reorder) {
121
123 config != NULL,
124 "ERROR(yac_interpolation_gen_config_set_reorder): config is NULL");
128 "ERROR(yac_interpolation_gen_config_set_reorder): invalid reorder value");
129
132}
133
135 struct yac_interpolation_gen_config * config, size_t collection_size) {
136
138 config != NULL,
139 "ERROR(yac_interpolation_gen_config_set_collection_size): config is NULL");
141 collection_size != SIZE_MAX,
142 "ERROR(yac_interpolation_gen_config_set_collection_size): "
143 "collection_size must be != SIZE_MAX");
145 collection_size > 0,
146 "ERROR(yac_interpolation_gen_config_set_collection_size): "
147 "collection_size must be > 0");
148
150 config->collection_selection =
152}
153
155 struct yac_interpolation_gen_config * config,
157
159 config != NULL,
160 "ERROR(yac_interpolation_gen_config_set_collection_selection): config is NULL");
162 collection_selection != NULL,
163 "ERROR(yac_interpolation_gen_config_set_collection_selection): "
164 "collection_selection must be != NULL");
167 "ERROR(yac_interpolation_gen_config_set_collection_selection): "
168 "collection_size of collection_selection must be > 0");
169
171 config->collection_selection =
173}
174
176 struct yac_interpolation_gen_config * config,
178
180 config != NULL,
181 "ERROR(yac_interpolation_gen_config_set_frac_mask_fallback_value): "
182 "config is NULL");
185 "ERROR(yac_interpolation_gen_config_set_frac_mask_fallback_value): "
186 "%lf is not a valid fractional masking fallback value",
188
190}
191
193 struct yac_interpolation_gen_config * config, double scaling_factor) {
194
196 config != NULL,
197 "ERROR(yac_interpolation_gen_config_set_scaling_factor): config is NULL");
199 isnormal(scaling_factor) || (fabs(scaling_factor) == 0.0),
200 "ERROR(yac_interpolation_gen_config_set_scaling_factor): "
201 "%lf is not a valid scaling factor", scaling_factor);
202
204}
205
207 struct yac_interpolation_gen_config * config, double scaling_summand) {
208
210 config != NULL,
211 "ERROR(yac_interpolation_gen_config_set_scaling_summand): config is NULL");
213 isnormal(scaling_summand) || (fabs(scaling_summand) == 0.0),
214 "ERROR(yac_interpolation_gen_config_set_scaling_summand): "
215 "%lf is not a valid scaling summand", scaling_summand);
216
218}
219
221 struct yac_interpolation_gen_config * config, char const * name) {
222
224 config != NULL,
225 "ERROR(yac_interpolation_gen_config_set_yaxt_exchanger_name): "
226 "config is NULL");
227
228 free(config->yaxt_exchanger_name);
229 config->yaxt_exchanger_name = (name == NULL)?NULL:strdup(name);
230}
231
233 struct yac_interpolation_gen_config * config, char const * name) {
234
236 config != NULL,
237 "ERROR(yac_interpolation_gen_config_set_yaxt_exchanger_name_f2c): "
238 "config is NULL");
239
240 if ((name != NULL) && strlen(name) == 0) name = NULL;
242}
243
244/* ---------------- Getters ---------------- */
245
247 struct yac_interpolation_gen_config const * config) {
248
250 config != NULL,
251 "ERROR(yac_interpolation_gen_config_get_reorder): config is NULL");
252
253 return config->reorder;
254}
255
256struct yac_collection_selection const *
258 struct yac_interpolation_gen_config const * config) {
259
261 config != NULL,
262 "ERROR(yac_interpolation_gen_config_get_collection_selection): "
263 "config is NULL");
265 config->collection_selection != NULL,
266 "ERROR(yac_interpolation_gen_config_get_collection_selection): "
267 "collection_selection is unset");
268
269 return config->collection_selection;
270}
271
273 struct yac_interpolation_gen_config const * config) {
274
276 config != NULL,
277 "ERROR(yac_interpolation_gen_config_get_frac_mask_fallback_value): "
278 "config is NULL");
279
280 return config->frac_mask_fallback_value;
281}
282
284 struct yac_interpolation_gen_config const * config) {
285
287 config != NULL,
288 "ERROR(yac_interpolation_gen_config_get_scaling_factor): config is NULL");
289
290 return config->scaling_factor;
291}
292
294 struct yac_interpolation_gen_config const * config) {
295
297 config != NULL,
298 "ERROR(yac_interpolation_gen_config_get_scaling_summand): config is NULL");
299
300 return config->scaling_summand;
301}
302
304 struct yac_interpolation_gen_config const * config) {
305
307 config != NULL,
308 "ERROR(yac_interpolation_gen_config_get_yaxt_exchanger_name): "
309 "config is NULL");
310
311 return config->yaxt_exchanger_name;
312}
313
315 struct yac_interpolation_gen_config const * a,
316 struct yac_interpolation_gen_config const * b) {
317
318 // Same pointer or both NULL
319 int ret = (a == b);
320 if (ret) return 0;
321
322 // One is NULL, the other is not
323 ret = (a == NULL) - (b == NULL);
324 if (ret) return ret;
325
326 // Different reorder types
327 ret = (a->reorder > b->reorder) - (a->reorder < b->reorder);
328 if (ret) return ret;
329
330 // Different collection selections
331 ret =
334 if (ret) return ret;
335
336 // Different scaling factor
337 ret = (a->scaling_factor > b->scaling_factor) -
339 if (ret) return ret;
340
341 // Different scaling summand
342 ret = (a->scaling_summand > b->scaling_summand) -
344 if (ret) return ret;
345
346 // Different yaxt exchanger
348
349 // One is unset (default), the other is set
350 ret = (a->yaxt_exchanger_name == NULL) -
351 (b->yaxt_exchanger_name == NULL);
352 if (ret) return ret;
353
354 // Both exchangers are different
355 ret = strcmp(a->yaxt_exchanger_name, b->yaxt_exchanger_name);
356 if (ret) return ret;
357 }
358
359 // Different fractional mask values
360 // (use memcmp to compare frac_mask_fallback_value, because they can be nan)
361 ret =
362 memcmp(
364 sizeof(double));
365 // if (ret) return ret;
366
367 return ret;
368}
369
371 struct yac_interpolation_gen_config const *cfg, MPI_Comm comm) {
372
374 cfg != NULL, "ERROR(yac_interpolation_gen_config_pack): config is NULL");
375
376 int pack_size_int, pack_size_dble;
377 yac_mpi_call(MPI_Pack_size(1, MPI_INT, comm, &pack_size_int), comm);
378 yac_mpi_call(MPI_Pack_size(1, MPI_DOUBLE, comm, &pack_size_dble), comm);
379
380 return pack_size_int + // reorder
381 pack_size_dble + // frac_mask_fallback_value
382 pack_size_dble + // scaling_factor
383 pack_size_dble + // scaling_summand
385 (cfg != NULL)?cfg->collection_selection:NULL, comm) +
387 "yac_interpolation_gen_config_get_pack_size",
388 (cfg != NULL)?cfg->yaxt_exchanger_name:NULL, comm, 1);
389}
390
392 struct yac_interpolation_gen_config const * cfg,
393 void * buffer, int buffer_size, int * position, MPI_Comm comm) {
394
396 cfg != NULL, "ERROR(yac_interpolation_gen_config_pack): config is NULL");
397
398 int reorder = (int)cfg->reorder;
400 MPI_Pack(&reorder, 1, MPI_INT, buffer, buffer_size, position, comm), comm);
401
403 MPI_Pack(
404 &cfg->frac_mask_fallback_value, 1, MPI_DOUBLE, buffer, buffer_size,
405 position, comm), comm);
407 MPI_Pack(
408 &cfg->scaling_factor, 1, MPI_DOUBLE, buffer, buffer_size,
409 position, comm), comm);
411 MPI_Pack(
412 &cfg->scaling_summand, 1, MPI_DOUBLE, buffer, buffer_size,
413 position, comm), comm);
414
416 cfg->collection_selection, buffer, buffer_size, position, comm);
417
419 "yac_interpolation_gen_config_pack",
420 cfg->yaxt_exchanger_name, buffer, buffer_size, position, comm, 1);
421}
422
424 void const * buffer, int buffer_size, int *position, MPI_Comm comm) {
425
426 struct yac_interpolation_gen_config * cfg = xmalloc(1 * sizeof(*cfg));
427
428 int reorder_int;
430 MPI_Unpack(buffer, buffer_size, position, &reorder_int, 1, MPI_INT, comm),
431 comm);
432 cfg->reorder = (enum yac_interp_weights_reorder_type)reorder_int;
433
435 MPI_Unpack(
436 buffer, buffer_size, position,
437 &cfg->frac_mask_fallback_value, 1, MPI_DOUBLE, comm), comm);
439 MPI_Unpack(
440 buffer, buffer_size, position,
441 &cfg->scaling_factor, 1, MPI_DOUBLE, comm), comm);
443 MPI_Unpack(
444 buffer, buffer_size, position,
445 &cfg->scaling_summand, 1, MPI_DOUBLE, comm), comm);
446
448 yac_collection_selection_unpack(buffer, buffer_size, position, comm);
449
451 yac_string_unpack(buffer, buffer_size, position, comm);
452
453 return cfg;
454}
#define YAC_ASSERT(exp, msg)
size_t yac_collection_selection_get_collection_size(struct yac_collection_selection const *collection_selection)
Get the size of the collection selection.
struct yac_collection_selection * yac_collection_selection_unpack(void const *buffer, int buffer_size, int *position, MPI_Comm comm)
Unpack a collection selection from a contiguous MPI buffer.
size_t yac_collection_selection_get_pack_size(struct yac_collection_selection const *sel, MPI_Comm comm)
Compute the MPI pack size of a collection selection.
void yac_collection_selection_delete(struct yac_collection_selection *collection_selection)
Delete a collection selection object.
int yac_collection_selection_compare(struct yac_collection_selection const *a, struct yac_collection_selection const *b)
Compare two collection selections.
struct yac_collection_selection * yac_collection_selection_copy(const struct yac_collection_selection *collection_selection)
Selection of indices from a collection.
void yac_collection_selection_pack(struct yac_collection_selection const *sel, void *buffer, int buffer_size, int *position, MPI_Comm comm)
Pack a collection selection into a contiguous MPI buffer.
struct yac_collection_selection * yac_collection_selection_new(size_t collection_size, size_t const *selection_indices)
Create a new collection selection.
yac_interp_weights_reorder_type
@ YAC_MAPPING_ON_TGT
weights will be applied at target processes
@ YAC_MAPPING_ON_SRC
weights will be applied at source processes
double const YAC_FRAC_MASK_NO_VALUE
void yac_interpolation_gen_config_set_reorder(struct yac_interpolation_gen_config *config, enum yac_interp_weights_reorder_type reorder)
Set the reordering strategy for interpolation weights.
void yac_interpolation_gen_config_set_collection_size(struct yac_interpolation_gen_config *config, size_t collection_size)
Set the number of contiguous fields (starting at "0") in the field collection.
void yac_interpolation_gen_config_set_yaxt_exchanger_name_f2c(struct yac_interpolation_gen_config *config, char const *name)
enum yac_interp_weights_reorder_type yac_interpolation_gen_config_get_reorder(struct yac_interpolation_gen_config const *config)
Get the configured reordering strategy.
int yac_interpolation_gen_config_compare(struct yac_interpolation_gen_config const *a, struct yac_interpolation_gen_config const *b)
Compare two interpolation configuration structures.
void yac_interpolation_gen_config_set_reorder_f2c(struct yac_interpolation_gen_config *config, int reorder)
double yac_interpolation_gen_config_get_frac_mask_fallback_value(struct yac_interpolation_gen_config const *config)
Get the configured fractional mask fallback value.
void yac_interpolation_gen_config_set_collection_selection(struct yac_interpolation_gen_config *config, struct yac_collection_selection const *collection_selection)
Set the collection selection of source field in the source field collection.
void yac_interpolation_gen_config_set_scaling_factor(struct yac_interpolation_gen_config *config, double scaling_factor)
Set the multiplicative scaling factor.
double yac_interpolation_gen_config_get_scaling_factor(struct yac_interpolation_gen_config const *config)
Get the configured scaling factor.
struct yac_collection_selection const * yac_interpolation_gen_config_get_collection_selection(struct yac_interpolation_gen_config const *config)
Get the configured collection selection.
size_t yac_interpolation_gen_config_get_pack_size(struct yac_interpolation_gen_config const *cfg, MPI_Comm comm)
Get the MPI packing size of an interpolation generation configuration.
void yac_interpolation_gen_config_set_yaxt_exchanger_name(struct yac_interpolation_gen_config *config, char const *name)
Set the name of the Yaxt exchanger.
const char * yac_interpolation_gen_config_get_yaxt_exchanger_name(struct yac_interpolation_gen_config const *config)
Get the configured Yaxt exchanger name.
void yac_interpolation_gen_config_delete(struct yac_interpolation_gen_config *config)
Release a interpolation generation configuration structure allocated by yac_interpolation_gen_config_...
void yac_interpolation_gen_config_set_frac_mask_fallback_value(struct yac_interpolation_gen_config *config, double frac_mask_fallback_value)
Set the fractional mask fallback value.
struct yac_interpolation_gen_config * yac_interpolation_gen_config_copy(struct yac_interpolation_gen_config const *src)
Create a copy of an interpolation generation configuration.
struct yac_interpolation_gen_config * yac_interpolation_gen_config_new(void)
Allocate and initialise an interpolation generation configuration structure.
void yac_interpolation_gen_config_pack(struct yac_interpolation_gen_config const *cfg, void *buffer, int buffer_size, int *position, MPI_Comm comm)
Pack an interpolation generation configuration into an MPI buffer.
void yac_interpolation_gen_config_set_scaling_summand(struct yac_interpolation_gen_config *config, double scaling_summand)
Set the additive scaling summand.
double yac_interpolation_gen_config_get_scaling_summand(struct yac_interpolation_gen_config const *config)
Get the configured scaling summand.
struct yac_interpolation_gen_config * yac_interpolation_gen_config_unpack(void const *buffer, int buffer_size, int *position, MPI_Comm comm)
Unpack an interpolation generation configuration from an MPI buffer.
Defines internal basic interpolation definitions.
#define YAC_FRAC_MASK_VALUE_IS_VALID(value)
Test whether a fractional mask value is valid.
Definition __init__.py:1
add versions of standard API functions not returning on error
#define xmalloc(size)
Definition ppm_xfuncs.h:66
Configuration structure for interpolation generation.
struct yac_collection_selection * collection_selection
enum yac_interp_weights_reorder_type reorder
int collection_size
double * buffer
char const * name
Definition toy_scrip.c:114
#define YAC_ASSERT_F(exp, format,...)
Definition yac_assert.h:19
size_t yac_string_get_pack_size(char const *caller, char const *string, MPI_Comm comm, int allow_null)
Compute number of bytes required to pack a string for MPI transport.
Definition yac_mpi.c:646
char * yac_string_unpack(void const *buffer, int buffer_size, int *position, MPI_Comm comm)
Unpack a C string from a buffer packed with yac_string_pack.
Definition yac_mpi.c:697
void yac_string_pack(char const *caller, char const *string, void *buffer, int buffer_size, int *position, MPI_Comm comm, int allow_null)
Pack a C string into a provided buffer using MPI_Pack semantics.
Definition yac_mpi.c:667
#define yac_mpi_call(call, comm)