YAC 3.7.1
Yet Another Coupler
Loading...
Searching...
No Matches
interp_method_check.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
13#include "utils_core.h"
14#include "ensure_array_size.h"
15#include "interp_method_check.h"
16
17static size_t do_search_check(struct interp_method * method,
18 struct yac_interp_grid * interp_grid,
19 size_t * tgt_points, size_t count,
20 struct yac_interp_weights * weights,
21 int * interpolation_complete);
22static void delete_check(struct interp_method * method);
23
24static struct interp_method_vtable
28
35
36static size_t do_search_check (struct interp_method * method,
37 struct yac_interp_grid * interp_grid,
38 size_t * tgt_points, size_t count,
39 struct yac_interp_weights * weights,
40 int * interpolation_complete) {
41
42 UNUSED(weights);
43 UNUSED(interpolation_complete);
44
45 struct interp_method_check * method_check =
46 (struct interp_method_check *)method;
47
48 yac_int * tgt_global_ids = xmalloc(count * sizeof(*tgt_global_ids));
49 yac_coordinate_pointer tgt_coordinates =
50 xmalloc(count * sizeof(*tgt_coordinates));
51
53 interp_grid, tgt_points, count, tgt_global_ids);
55 interp_grid, tgt_points, count, tgt_coordinates);
56
57 if (method_check->do_search_callback != NULL)
58 method_check->do_search_callback(
59 tgt_global_ids, (yac_const_coordinate_pointer)tgt_coordinates, count,
60 method_check->do_search_user_data);
61
62 free(tgt_coordinates);
63 free(tgt_global_ids);
64
65 return 0;
66}
67
69 func_constructor constructor_callback,
70 void * constructor_user_data,
72 void * do_search_user_data) {
73
74 struct interp_method_check * method = xmalloc(1 * sizeof(*method));
75
79
80 if (constructor_callback != NULL)
81 constructor_callback(constructor_user_data);
82
83 return (struct interp_method*)method;
84}
85
86static void delete_check(struct interp_method * method) {
87 free(method);
88}
89
94typedef void (*func_dummy)(void);
95static struct {
96 struct {
98 void * user_data;
101 char * key;
105
108 char const * key) {
109
110 // ensure that the lookup table does already contain an entry with the same
111 // key and type
112 for (size_t i = 0; i < callback_lookup_table_size; ++i)
114 strcmp(callback_lookup_table[i].key, key) ||
116 "ERROR(interp_method_check_add_callback): "
117 "key \"%s\" has been set for the same callback type (%d)",
118 key, (int)type)
119
122
124 xmalloc((strlen(key)+1) * sizeof(*key));
130}
131
133 char const * key, func_dummy * callback, enum callback_type type,
134 void ** user_data) {
135
136 *callback = NULL;
137 *user_data = NULL;
138 for (size_t i = 0;
140 (*callback == NULL) && (*user_data == NULL); ++i) {
141 if ((!strcmp(callback_lookup_table[i].key, key)) &&
143 *callback = callback_lookup_table[i].value.callback;
144 *user_data = callback_lookup_table[i].value.user_data;
145 return;
146 }
147 }
148}
149
151 func_constructor constructor_callback, void * user_data, char const * key) {
152
154 (func_dummy)constructor_callback, CONSTRUCTOR, user_data, key);
155}
156
158 char const * key, func_constructor * constructor_callback,
159 void ** user_data) {
160
162 key, (func_dummy*)constructor_callback, CONSTRUCTOR, user_data);
163}
164
171
178
#define UNUSED(x)
Definition core.h:73
#define ENSURE_ARRAY_SIZE(arrayp, curr_array_size, req_size)
void yac_interp_grid_get_tgt_global_ids(struct yac_interp_grid *interp_grid, size_t *tgt_points, size_t count, yac_int *tgt_global_ids)
void yac_interp_grid_get_tgt_coordinates(struct yac_interp_grid *interp_grid, size_t *tgt_points, size_t count, yac_coordinate_pointer tgt_coordinates)
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 * user_data
@ CONSTRUCTOR
@ DO_SEARCH
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_add_constructor_callback(func_constructor constructor_callback, void *user_data, char const *key)
void yac_interp_method_check_get_constructor_callback(char const *key, func_constructor *constructor_callback, void **user_data)
void yac_interp_method_check_add_do_search_callback(func_do_search do_search_callback, void *user_data, char const *key)
struct @14::@15 value
void(* func_dummy)(void)
char * key
enum callback_type type
static void interp_method_get_callback(char const *key, func_dummy *callback, enum callback_type type, void **user_data)
static struct @14 * callback_lookup_table
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)
static void delete_check(struct interp_method *method)
static void interp_method_check_add_callback(func_dummy callback, enum callback_type type, void *user_data, char const *key)
static size_t callback_lookup_table_size
static size_t do_search_check(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_interp_method_check_buf_free()
static struct interp_method_vtable interp_method_check_vtable
static size_t callback_lookup_table_array_size
func_dummy callback
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)
#define xmalloc(size)
Definition ppm_xfuncs.h:66
struct interp_method_vtable * vtable
func_do_search do_search_callback
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)
#define YAC_ASSERT_F(exp, format,...)
Definition yac_assert.h:19
Xt_int yac_int
Definition yac_types.h:15
double const (* yac_const_coordinate_pointer)[3]
Definition yac_types.h:20
double(* yac_coordinate_pointer)[3]
Definition yac_types.h:19