YetAnotherCoupler 3.2.0_a
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 struct interp_method_check * method_check =
41 (struct interp_method_check *)method;
42
43 yac_int * tgt_global_ids = xmalloc(count * sizeof(*tgt_global_ids));
44 yac_coordinate_pointer tgt_coordinates =
45 xmalloc(count * sizeof(*tgt_coordinates));
46
48 interp_grid, tgt_points, count, tgt_global_ids);
50 interp_grid, tgt_points, count, tgt_coordinates);
51
52 if (method_check->do_search_callback != NULL)
53 method_check->do_search_callback(
54 tgt_global_ids, (yac_const_coordinate_pointer)tgt_coordinates, count,
55 method_check->do_search_user_data);
56
57 free(tgt_coordinates);
58 free(tgt_global_ids);
59
60 return 0;
61}
62
64 func_constructor constructor_callback,
65 void * constructor_user_data,
67 void * do_search_user_data) {
68
69 struct interp_method_check * method = xmalloc(1 * sizeof(*method));
70
74
75 if (constructor_callback != NULL)
76 constructor_callback(constructor_user_data);
77
78 return (struct interp_method*)method;
79}
80
81static void delete_check(struct interp_method * method) {
82 free(method);
83}
84
89typedef void (*func_dummy)(void);
90static struct {
91 struct {
93 void * user_data;
96 char * key;
100
103 char const * key) {
104
105 // ensure that the lookup table does already contain an entry with the same
106 // key and type
107 for (size_t i = 0; i < callback_lookup_table_size; ++i)
109 strcmp(callback_lookup_table[i].key, key) ||
111 "ERROR(interp_method_check_add_callback): "
112 "key \"%s\" has been set for the same callback type (%d)",
113 key, (int)type)
114
117
119 xmalloc((strlen(key)+1) * sizeof(*key));
125}
126
128 char const * key, func_dummy * callback, enum callback_type type,
129 void ** user_data) {
130
131 *callback = NULL;
132 *user_data = NULL;
133 for (size_t i = 0;
135 (*callback == NULL) && (*user_data == NULL); ++i) {
136 if ((!strcmp(callback_lookup_table[i].key, key)) &&
138 *callback = callback_lookup_table[i].value.callback;
139 *user_data = callback_lookup_table[i].value.user_data;
140 return;
141 }
142 }
143}
144
146 func_constructor constructor_callback, void * user_data, char const * key) {
147
149 (func_dummy)constructor_callback, CONSTRUCTOR, user_data, key);
150}
151
153 char const * key, func_constructor * constructor_callback,
154 void ** user_data) {
155
157 key, (func_dummy*)constructor_callback, CONSTRUCTOR, user_data);
158}
159
166
#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
static struct @8 * callback_lookup_table
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 @8::@9 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)
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
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)
#define YAC_ASSERT_F(exp, format,...)
Definition yac_assert.h:18
Xt_int yac_int
Definition yac_types.h:15
double const (*const yac_const_coordinate_pointer)[3]
Definition yac_types.h:20
double(* yac_coordinate_pointer)[3]
Definition yac_types.h:19