YAC 3.21.0
Yet Another Coupler
Loading...
Searching...
No Matches
interp_method_fixed.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 <limits.h>
11
17#include "instrument_internal.h"
18#include "yac_mpi_common.h"
19
20static size_t do_search_fixed(struct interp_method * method,
21 struct yac_interp_grid * interp_grid,
22 size_t * tgt_points, size_t count,
23 struct yac_interp_weights * weights,
24 int * interpolation_complete);
25static void delete_fixed(struct interp_method * method);
26
27static struct interp_method_vtable
31
37
38static size_t do_search_fixed (struct interp_method * method,
39 struct yac_interp_grid * interp_grid,
40 size_t * tgt_points, size_t count,
41 struct yac_interp_weights * weights,
42 int * interpolation_complete) {
43
44 if (*interpolation_complete) return 0;
45
46 YAC_INSTRUMENT_START(YAC_INSTR_INTERP_SEARCH_FIXED);
47
48 struct remote_points tgts = {
49 .data =
50 yac_interp_grid_get_tgt_remote_points(interp_grid, tgt_points, count),
51 .count = count};
52
54 weights, &tgts, ((struct interp_method_fixed *)method)->value);
55
56 free(tgts.data);
57
58 YAC_INSTRUMENT_STOP(YAC_INSTR_INTERP_SEARCH_FIXED);
59
60 return count;
61}
62
64
65 struct interp_method_fixed * method = xmalloc(1 * sizeof(*method));
66
68 method->value = value;
69
70 return (struct interp_method*)method;
71}
72
73static void delete_fixed(struct interp_method * method) {
74 free(method);
75}
76
77// --- Modular config struct and vtable for FIXED method ---
78
93
96 free(config);
97}
98
100 const struct yac_interp_method_config *config) {
102 struct yac_interp_method_config_fixed *copy =
103 xmalloc(sizeof(*copy));
104 copy->base.vtable = config_fixed->base.vtable;
105 copy->base.root_param_cache = NULL;
106 copy->config = config_fixed->config;
107 return (struct yac_interp_method_config *)copy;
108}
109
111 void const *a_, void const *b_) {
113 // Use memcmp for correct handling of NaNs in fixed values
115 return 0;
116}
117
118// Gets interpolation method typed_config_hcsbb_get_type
122
124 struct yac_interp_method_config const *config)
125{
126 const struct yac_interp_method_config_fixed *config_fixed =
128 return yac_interp_method_fixed_new(config_fixed->config.value);
129}
130
132 struct yac_interp_method_config const *config) {
133 struct yac_interp_method_config_fixed *config_fixed =
135
136 enum {
137 VALUE_HAS_DEFAULT = 1,
138 VALUE_IS_DEFINED = 1,
139 VALUE_ALLOW_NAN = 1,
140 VALUE_ALLOW_INF = 1,
141 };
142
143 double const value_min = -DBL_MAX;
144 double const value_max = DBL_MAX;
145
146 struct yac_param *value_param =
148 "user_value",
149 &config_fixed->config.value,
151 value_min, value_max, VALUE_ALLOW_NAN, VALUE_ALLOW_INF,
152 VALUE_HAS_DEFAULT,
153 VALUE_IS_DEFINED);
154
155 struct yac_param *root_param_array[] = {
156 value_param
157 };
158 enum {
159 ROOT_PARAM_ARRAY_SIZE =
160 sizeof(root_param_array) / sizeof(root_param_array[0])
161 };
162
164 "fixed", root_param_array, ROOT_PARAM_ARRAY_SIZE);
165}
166
175
177 struct yac_interp_method_config_fixed *config_fixed =
178 xmalloc(sizeof(*config_fixed));
180 config_fixed->base.root_param_cache = NULL;
181 config_fixed->config = (struct yac_interp_method_fixed_config){
183 };
184 return (struct yac_interp_method_config *)config_fixed;
185}
#define YAC_INSTRUMENT_START(ID)
Enter an instrumented region.
#define YAC_INSTRUMENT_STOP(ID)
Exit an instrumented region entered with YAC_INSTRUMENT_START(ID).
struct remote_point * yac_interp_grid_get_tgt_remote_points(struct yac_interp_grid *interp_grid, size_t *tgt_points, size_t count)
yac_interpolation_list
@ YAC_FIXED_VALUE
Assigns a fixed value to all targets.
struct @23::@24 value
#define DEF_INTERP_METHOD_CONFIG_COMPARE_TYPE(TYPE)
#define CHECK_DOUBLE_NAN(FIELD)
#define DEF_INTERP_METHOD_CONFIG_TYPE(TYPE)
static enum yac_interpolation_list config_fixed_get_type()
static struct yac_interp_method_config * config_fixed_copy(const struct yac_interp_method_config *config)
static struct interp_method_vtable interp_method_fixed_vtable
static void delete_fixed(struct interp_method *method)
static struct yac_param * config_fixed_get_param(struct yac_interp_method_config const *config)
static int config_fixed_compare(void const *a_, void const *b_)
static struct interp_method * config_fixed_generate(struct yac_interp_method_config const *config)
static void config_fixed_delete(struct yac_interp_method_config *config)
static size_t do_search_fixed(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)
struct yac_interp_method_config * yac_interp_method_config_default_fixed_new(void)
Creates a fixed-value interpolation method configuration with default parameters.
static struct yac_interp_method_config_vtable yac_interp_method_config_vtable_fixed
struct interp_method * yac_interp_method_fixed_new(double value)
#define YAC_INTERP_FIXED_VALUE_DEFAULT
void yac_interp_weights_add_fixed(struct yac_interp_weights *weights, struct remote_points *tgts, double fixed_value)
struct yac_param * yac_param_dble_new(const char *name, double *value_ptr, double default_value, double value_min, double value_max, int allow_nan, int allow_inf, int has_default, int is_defined)
Create a double parameter.
Definition param_dble.c:166
struct yac_param * yac_param_struct_new(const char *name, struct yac_param **subparams, size_t subparam_count)
Create a new struct parameter with a given name and subparameters.
#define xmalloc(size)
Definition ppm_xfuncs.h:66
struct interp_method_vtable * vtable
size_t(* do_search)(struct interp_method *method, struct yac_interp_grid *grid, size_t *tgt_points, size_t count, struct yac_interp_weights *weights, int *interpolation_complete)
structure containing the information (global id and location)
struct remote_point * data
Concrete implementation of yac_interp_method_config for the fixed value method.
struct yac_interp_method_fixed_config config
‍method-specific configuration
struct yac_interp_method_config base
‍base config object, must be first entry
void(* delete)(struct yac_interp_method_config *config)
struct yac_interp_method_config_vtable const * vtable
static struct yac_interp_method_config * config