YetAnotherCoupler 3.2.0
Loading...
Searching...
No Matches
interpolation.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// Get the definition of the 'restrict' keyword.
7#include "config.h"
8#endif
9
10#include <string.h>
11#include <math.h>
12
13#include "ppm/core.h"
14#include "utils_core.h"
16#include "interpolation_fixed.h"
21#include "yac_mpi_internal.h"
22
23double const YAC_FRAC_MASK_NO_VALUE = 133713371337.0;
24double const YAC_FRAC_MASK_UNDEF = -133713371337.0;
25
41
44 double scale_factor, double scale_summand) {
45
46 struct yac_interpolation * interp = xmalloc(1 * sizeof(*interp));
47
48 interp->interps = NULL;
49 interp->interp_count = 0;
50
51 interp->is_source = 0;
52 interp->is_target = 0;
54
55 interp->ref_count = 1;
56
58
60 isnormal(scale_factor),
61 "ERROR(yac_interpolation_new): \"%lf\" is not a valid scaling factor",
64 (scale_summand == 0.0) || isnormal(scale_summand),
65 "ERROR(yac_interpolation_new): \"%lf\" is not a valid scaling summand",
67
68 interp->scale_factor = scale_factor;
70
71 return interp;
72}
73
75 struct yac_interpolation * interp,
76 struct yac_interpolation_type * interp_type) {
77
78 if (interp_type == NULL) return;
79
80 interp->interps =
82 interp->interps,
83 (interp->interp_count + 1) * sizeof(*(interp->interps)));
84 interp->interps[interp->interp_count] = interp_type;
85 interp->interp_count++;
86
87 interp->is_source |= interp_type->vtable->is_source(interp_type);
88 interp->is_target |= interp_type->vtable->is_target(interp_type);
89}
90
92 struct yac_interpolation * interp, double value, size_t count,
93 size_t * pos) {
94
96 interp,
98}
99
101 struct yac_interpolation * interp, Xt_redist redist) {
102
104 interp, yac_interpolation_direct_new(interp->collection_size, redist));
105}
106
108 struct yac_interpolation * interp, Xt_redist * redists,
109 size_t num_src_fields) {
110
112 interp,
114 interp->collection_size, redists, num_src_fields));
115}
116
118 struct yac_interpolation * interp, Xt_redist * halo_redists,
119 size_t tgt_count, size_t * num_src_per_tgt,
120 size_t * src_field_idx, size_t * src_idx,
121 size_t num_src_fields, Xt_redist result_redist) {
122
124 interp,
126 interp->collection_size, halo_redists, tgt_count, num_src_per_tgt, NULL,
127 src_field_idx, src_idx, num_src_fields, result_redist,
129}
130
132 struct yac_interpolation * interp, Xt_redist * src_redists,
133 size_t * tgt_pos, size_t tgt_count, size_t * num_src_per_tgt,
134 size_t * src_field_idx, size_t * src_idx,
135 size_t num_src_fields) {
136
138 interp,
140 interp->collection_size, src_redists, tgt_pos, tgt_count, num_src_per_tgt,
141 NULL, src_field_idx, src_idx, num_src_fields,
143}
144
146 struct yac_interpolation * interp, Xt_redist * halo_redists,
147 size_t tgt_count, size_t * num_src_per_tgt, double * weights,
148 size_t * src_field_idx, size_t * src_idx,
149 size_t num_src_fields, Xt_redist result_redist) {
150
152 interp,
154 interp->collection_size, halo_redists, tgt_count, num_src_per_tgt,
155 weights, src_field_idx, src_idx, num_src_fields, result_redist,
157}
158
160 struct yac_interpolation * interp, Xt_redist * src_redists, size_t * tgt_pos,
161 size_t tgt_count, size_t * num_src_per_tgt, double * weights,
162 size_t * src_field_idx, size_t * src_idx,
163 size_t num_src_fields) {
164
166 interp,
168 interp->collection_size, src_redists, tgt_pos, tgt_count, num_src_per_tgt,
169 weights, src_field_idx, src_idx, num_src_fields,
171}
172
174 struct yac_interpolation * interp) {
175
176 struct yac_interpolation * interp_copy =
179 interp->scale_factor, interp->scale_summand);
180
181 interp_copy->interps =
182 xmalloc(interp->interp_count * sizeof(*interp_copy->interps));
183 interp_copy->interp_count = interp->interp_count;
184
185 for (size_t i = 0; i < interp->interp_count; ++i)
186 interp_copy->interps[i] =
187 interp->interps[i]->vtable->copy(interp->interps[i]);
188
189 interp_copy->is_source = interp->is_source;
190 interp_copy->is_target = interp->is_target;
191
192 return interp_copy;
193}
194
195// src_fields dimensions [collection_idx]
196// [field index]
197// [local_idx]
198// src_frac_masks dimensions [collection_idx]
199// [field index]
200// [local_idx]
201// tgt_field dimensions [collection_idx]
202// [local_idx]
204 struct yac_interpolation * interp, double *** src_fields,
205 double *** src_frac_masks, double ** tgt_field) {
206
209 (src_frac_masks == NULL),
210 "ERROR(yac_interpolation_execute_frac): "
211 "interpolation was not built for dynamic fractional masking, "
212 "use yac_interpolation_execute instead");
213
214 for (size_t i = 0; i < interp->interp_count; ++i)
215 interp->interps[i]->vtable->execute(
216 interp->interps[i], src_fields, src_frac_masks, tgt_field,
217 interp->frac_mask_fallback_value, interp->scale_factor,
218 interp->scale_summand);
219}
220
221// src_fields dimensions [collection_idx]
222// [field index]
223// [local_idx]
224// tgt_field dimensions [collection_idx]
225// [local_idx]
227 struct yac_interpolation * interp, double *** src_fields,
228 double ** tgt_field) {
229
232 "ERROR(yac_interpolation_execute): "
233 "interpolation was built for dynamic fractional masking, "
234 "use yac_interpolation_execute_frac instead");
235
236 yac_interpolation_execute_frac(interp, src_fields, NULL, tgt_field);
237}
238
239// src_fields dimensions [collection_idx]
240// [field index]
241// [local_idx]
242// src_frac_masks dimensions [collection_idx]
243// [field index]
244// [local_idx]
246 struct yac_interpolation * interp, double *** src_fields,
247 double *** src_frac_masks) {
248
251 (src_frac_masks == NULL),
252 "ERROR(yac_interpolation_execute_put_frac): "
253 "interpolation was built for dynamic fractional masking, "
254 "use yac_interpolation_execute_put instead");
255
256 if (!interp->is_source) return;
257
258 for (size_t i = 0; i < interp->interp_count; ++i)
259 interp->interps[i]->vtable->execute_put(
260 interp->interps[i], src_fields, src_frac_masks,
261 interp->is_target, interp->frac_mask_fallback_value,
262 interp->scale_factor, interp->scale_summand);
263}
264
265// src_fields dimensions [collection_idx]
266// [field index]
267// [local_idx]
269 struct yac_interpolation * interp, double *** src_fields) {
270
273 "ERROR(yac_interpolation_execute_put): "
274 "interpolation was built for dynamic fractional masking, "
275 "use yac_interpolation_execute_put_frac instead");
276
277 yac_interpolation_execute_put_frac(interp, src_fields, NULL);
278}
279
280// tgt_field dimensions [collection_idx]
281// [local_idx]
283 struct yac_interpolation * interp, double ** tgt_field) {
284
285 if (!interp->is_target) return;
286
287 for (size_t i = 0; i < interp->interp_count; ++i)
288 interp->interps[i]->vtable->execute_get(
289 interp->interps[i], tgt_field, interp->frac_mask_fallback_value,
290 interp->scale_factor, interp->scale_summand);
291}
292
294 struct yac_interpolation * interp, double ** tgt_field) {
295
296 if (!interp->is_target) return;
297
298 for (size_t i = 0; i < interp->interp_count; ++i)
299 interp->interps[i]->vtable->execute_get_async(
300 interp->interps[i], tgt_field, interp->frac_mask_fallback_value,
301 interp->scale_factor, interp->scale_summand);
302}
303
305
306 int test = 0;
307
308 for (size_t i = 0; (i < interp->interp_count) && !test; ++i)
309 test |=
310 interp->interps[i]->vtable->execute_put_test(
311 interp->interps[i]);
312
313 return test;
314}
315
317
318 int test = 0;
319
320 for (size_t i = 0; (i < interp->interp_count) && !test; ++i)
321 test |=
322 interp->interps[i]->vtable->execute_get_test(
323 interp->interps[i]);
324
325 return test;
326}
327
329
330 for (size_t i = 0; i < interp->interp_count; ++i)
331 interp->interps[i]->vtable->execute_wait(interp->interps[i]);
332}
333
335
336 interpolation->ref_count++;
337}
338
340
341 return interpolation->frac_mask_fallback_value != YAC_FRAC_MASK_NO_VALUE;
342}
343
345
346 if (interp == NULL) return;
347
348 if(--(interp->ref_count)) return;
349
350 for (size_t i = 0; i < interp->interp_count; ++i)
351 interp->interps[i]->vtable->delete(interp->interps[i]);
352 free(interp->interps);
353 free(interp);
354}
355
359
struct @8::@9 value
void yac_interpolation_add_sum_at_src(struct yac_interpolation *interp, Xt_redist *halo_redists, size_t tgt_count, size_t *num_src_per_tgt, size_t *src_field_idx, size_t *src_idx, size_t num_src_fields, Xt_redist result_redist)
struct yac_interpolation * yac_interpolation_copy(struct yac_interpolation *interp)
void yac_interpolation_inc_ref_count(struct yac_interpolation *interpolation)
void yac_interpolation_add_weight_sum_mvp_at_tgt(struct yac_interpolation *interp, Xt_redist *src_redists, size_t *tgt_pos, size_t tgt_count, size_t *num_src_per_tgt, double *weights, size_t *src_field_idx, size_t *src_idx, size_t num_src_fields)
struct yac_interpolation * yac_interpolation_new(size_t collection_size, double frac_mask_fallback_value, double scale_factor, double scale_summand)
void yac_interpolation_execute(struct yac_interpolation *interp, double ***src_fields, double **tgt_field)
int yac_interpolation_with_frac_mask(struct yac_interpolation *interpolation)
void yac_interpolation_add_direct_mf(struct yac_interpolation *interp, Xt_redist *redists, size_t num_src_fields)
void yac_interpolation_delete(struct yac_interpolation *interp)
void yac_interpolation_add_sum_at_tgt(struct yac_interpolation *interp, Xt_redist *src_redists, size_t *tgt_pos, size_t tgt_count, size_t *num_src_per_tgt, size_t *src_field_idx, size_t *src_idx, size_t num_src_fields)
int yac_interpolation_execute_put_test(struct yac_interpolation *interp)
void yac_interpolation_add_fixed(struct yac_interpolation *interp, double value, size_t count, size_t *pos)
void yac_interpolation_execute_wait(struct yac_interpolation *interp)
void yac_interpolation_execute_frac(struct yac_interpolation *interp, double ***src_fields, double ***src_frac_masks, double **tgt_field)
void yac_interpolation_execute_get(struct yac_interpolation *interp, double **tgt_field)
void yac_interpolation_execute_get_async(struct yac_interpolation *interp, double **tgt_field)
double const YAC_FRAC_MASK_UNDEF
void yac_interpolation_add_direct(struct yac_interpolation *interp, Xt_redist redist)
double yac_interpolation_get_const_frac_mask_no_value_c2f()
void yac_interpolation_execute_put_frac(struct yac_interpolation *interp, double ***src_fields, double ***src_frac_masks)
void yac_interpolation_execute_put(struct yac_interpolation *interp, double ***src_fields)
void yac_interpolation_add_weight_sum_mvp_at_src(struct yac_interpolation *interp, Xt_redist *halo_redists, size_t tgt_count, size_t *num_src_per_tgt, double *weights, size_t *src_field_idx, size_t *src_idx, size_t num_src_fields, Xt_redist result_redist)
int yac_interpolation_execute_get_test(struct yac_interpolation *interp)
double yac_interpolation_get_const_frac_mask_undef_c2f()
static void yac_interpolation_add(struct yac_interpolation *interp, struct yac_interpolation_type *interp_type)
double const YAC_FRAC_MASK_NO_VALUE
struct yac_interpolation_type * yac_interpolation_direct_new(size_t collection_size, Xt_redist redist_)
struct yac_interpolation_type * yac_interpolation_direct_mf_new(size_t collection_size, Xt_redist *redists, size_t num_src_fields)
struct yac_interpolation_type * yac_interpolation_fixed_new(size_t collection_size, double value, size_t count, size_t const *pos)
struct yac_interpolation_type * yac_interpolation_sum_mvp_at_src_new(size_t collection_size, Xt_redist *halo_redists, size_t tgt_count, size_t *num_src_per_tgt, double *weights, size_t *src_field_idx, size_t *src_idx, size_t num_src_fields, Xt_redist result_redist_, int with_frac_mask)
struct yac_interpolation_type * yac_interpolation_sum_mvp_at_tgt_new(size_t collection_size, Xt_redist *src_redists, size_t *tgt_pos, size_t tgt_count, size_t *num_src_per_tgt, double *weights, size_t *src_field_idx, size_t *src_idx, size_t num_src_fields, int with_frac_mask)
#define xrealloc(ptr, size)
Definition ppm_xfuncs.h:67
#define xmalloc(size)
Definition ppm_xfuncs.h:66
void(* execute_put)(struct yac_interpolation_type *interp, double ***src_fields, double ***src_frac_masks, int is_target, double frac_mask_fallback_value, double scale_factor, double scale_summand)
void(* execute_wait)(struct yac_interpolation_type *interp)
int(* is_source)(struct yac_interpolation_type *interp)
void(* delete)(struct yac_interpolation_type *interp)
struct yac_interpolation_type *(* copy)(struct yac_interpolation_type *interp)
int(* execute_get_test)(struct yac_interpolation_type *interp)
void(* execute_get)(struct yac_interpolation_type *interp, double **tgt_field, double frac_mask_fallback_value, double scale_factor, double scale_summand)
void(* execute)(struct yac_interpolation_type *interp, double ***src_fields, double ***src_frac_masks, double **tgt_field, double frac_mask_fallback_value, double scale_factor, double scale_summand)
int(* is_target)(struct yac_interpolation_type *interp)
int(* execute_put_test)(struct yac_interpolation_type *interp)
void(* execute_get_async)(struct yac_interpolation_type *interp, double **tgt_field, double frac_mask_fallback_value, double scale_factor, double scale_summand)
struct yac_interpolation_type_vtable const *const vtable
double frac_mask_fallback_value
struct yac_interpolation_type ** interps
#define YAC_ASSERT_F(exp, format,...)
Definition yac_assert.h:19
#define YAC_ASSERT(exp, msg)
Definition yac_assert.h:16