YetAnotherCoupler 3.5.2
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);
21static void delete_check(struct interp_method * method);
22
23static struct interp_method_vtable
27
34
35static size_t do_search_check (struct interp_method * method,
36 struct yac_interp_grid * interp_grid,
37 size_t * tgt_points, size_t count,
38 struct yac_interp_weights * weights) {
39
40 UNUSED(weights);
41
42 struct interp_method_check * method_check =
43 (struct interp_method_check *)method;
44
45 yac_int * tgt_global_ids = xmalloc(count * sizeof(*tgt_global_ids));
46 yac_coordinate_pointer tgt_coordinates =
47 xmalloc(count * sizeof(*tgt_coordinates));
48
50 interp_grid, tgt_points, count, tgt_global_ids);
52 interp_grid, tgt_points, count, tgt_coordinates);
53
54 if (method_check->do_search_callback != NULL)
55 method_check->do_search_callback(
56 tgt_global_ids, (yac_const_coordinate_pointer)tgt_coordinates, count,
57 method_check->do_search_user_data);
58
59 free(tgt_coordinates);
60 free(tgt_global_ids);
61
62 return 0;
63}
64
66 func_constructor constructor_callback,
67 void * constructor_user_data,
69 void * do_search_user_data) {
70
71 struct interp_method_check * method = xmalloc(1 * sizeof(*method));
72
76
77 if (constructor_callback != NULL)
78 constructor_callback(constructor_user_data);
79
80 return (struct interp_method*)method;
81}
82
83static void delete_check(struct interp_method * method) {
84 free(method);
85}
86
91typedef void (*func_dummy)(void);
92static struct {
93 struct {
95 void * user_data;
98 char * key;
102
105 char const * key) {
106
107 // ensure that the lookup table does already contain an entry with the same
108 // key and type
109 for (size_t i = 0; i < callback_lookup_table_size; ++i)
111 strcmp(callback_lookup_table[i].key, key) ||
113 "ERROR(interp_method_check_add_callback): "
114 "key \"%s\" has been set for the same callback type (%d)",
115 key, (int)type)
116
119
121 xmalloc((strlen(key)+1) * sizeof(*key));
127}
128
130 char const * key, func_dummy * callback, enum callback_type type,
131 void ** user_data) {
132
133 *callback = NULL;
134 *user_data = NULL;
135 for (size_t i = 0;
137 (*callback == NULL) && (*user_data == NULL); ++i) {
138 if ((!strcmp(callback_lookup_table[i].key, key)) &&
140 *callback = callback_lookup_table[i].value.callback;
141 *user_data = callback_lookup_table[i].value.user_data;
142 return;
143 }
144 }
145}
146
148 func_constructor constructor_callback, void * user_data, char const * key) {
149
151 (func_dummy)constructor_callback, CONSTRUCTOR, user_data, key);
152}
153
155 char const * key, func_constructor * constructor_callback,
156 void ** user_data) {
157
159 key, (func_dummy*)constructor_callback, CONSTRUCTOR, user_data);
160}
161
168
175
#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)
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)
struct @7::@8 value
void yac_interp_method_check_add_do_search_callback(func_do_search do_search_callback, void *user_data, char const *key)
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)
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 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)
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
void yac_interp_method_check_buf_free()
static struct interp_method_vtable interp_method_check_vtable
static size_t callback_lookup_table_array_size
static struct @7 * callback_lookup_table
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)
#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