YAC 3.21.0
Yet Another Coupler
Loading...
Searching...
No Matches
interp_method_hcsbb.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
18#include "geometry.h"
19#include "ensure_array_size.h"
20#include "instrument_internal.h"
21#include "yac_mpi_common.h"
22
23// the default values for HCSBB_GAUSS_NNN, HCSBB_D_NNN, and HCSBB_GAUSS_ORDER
24// were determined empirically
25
26#ifndef HCSBB_GAUSS_NNN
27#define HCSBB_GAUSS_NNN (4)
28#endif
29#ifndef HCSBB_D_NNN
30#define HCSBB_D_NNN (7)
31#endif
32
33#ifndef HCSBB_GAUSS_ORDER
34#define HCSBB_GAUSS_ORDER (6)
35#endif
36// static size_t const num_gauss_points[] = {1,1,3,4,6,7,12,13,16,19,25,27,33};
37// -> HCSBB_NUM_GAUSS_POINTS = num_gauss_points[HCSBB_GAUSS_ORDER]
38#if HCSBB_GAUSS_ORDER == 0
39#define HCSBB_NUM_GAUSS_POINTS (1)
40#elif HCSBB_GAUSS_ORDER == 1
41#define HCSBB_NUM_GAUSS_POINTS (1)
42#elif HCSBB_GAUSS_ORDER == 2
43#define HCSBB_NUM_GAUSS_POINTS (3)
44#elif HCSBB_GAUSS_ORDER == 3
45#define HCSBB_NUM_GAUSS_POINTS (4)
46#elif HCSBB_GAUSS_ORDER == 4
47#define HCSBB_NUM_GAUSS_POINTS (6)
48#elif HCSBB_GAUSS_ORDER == 5
49#define HCSBB_NUM_GAUSS_POINTS (7)
50#elif HCSBB_GAUSS_ORDER == 6
51#define HCSBB_NUM_GAUSS_POINTS (12)
52#elif HCSBB_GAUSS_ORDER == 7
53#define HCSBB_NUM_GAUSS_POINTS (13)
54#elif HCSBB_GAUSS_ORDER == 8
55#define HCSBB_NUM_GAUSS_POINTS (16)
56#elif HCSBB_GAUSS_ORDER == 9
57#define HCSBB_NUM_GAUSS_POINTS (19)
58#else
59#define HCSBB_NUM_GAUSS_POINTS (-1)
60#error "interpolation_method_hcsbb: the specified gauss order is currently not supported."
61#endif
62
63// number spherical Bernstein-Bezier coefficients
64// n_c = = ((degree + 2) * (degree + 1)) / 2
65// sbb_degree = 3
66#define HCSBB_NUM_SBB_COEFFS (10)
67
68// This tolerence needs to be lower than the
69// one being used to find matching cells.
70#define SB_COORD_TOL (1.0e-6)
71
72static size_t do_search_hcsbb(struct interp_method * method,
73 struct yac_interp_grid * interp_grid,
74 size_t * tgt_points, size_t count,
75 struct yac_interp_weights * weights,
76 int * interpolation_complete);
77static void delete_hcsbb(struct interp_method * method);
78
79static struct interp_method_vtable
83
89
94
95 double bnd_triangle[3][3];
96
97 size_t * src_points;
99
104 double * weights;
105};
106
107struct weight_vector_data {
108 double weight;
109 size_t point_id;
110};
111
116
118
120 size_t n;
121};
122
124 ON_VERTEX = 0,
127 ON_TRIANGLE = 2,
129};
130
141
143
150 struct weight_vector c[2]; // c_210, c_120;
151
154
156 struct {
158 double coordinate_xyz[3];
162
166
169 double g[3];
170};
171
173
176
179};
180
182
183 size_t tgt_point;
184 double coordinate_xyz[3];
185
187 size_t src_points[3]; // sorted by global ids
188 double sb_coords[3];
189
192 union {
195 size_t idx;
197};
198
200 double coords[3][3]; // this need to be the first element in this struct
202};
203
204// compute the spherical barycentric coordinates of the given vertices with
205// respect to the given triangle
207 double * sb_coords, size_t num_vertices, double triangle[3][3],
208 char const * caller) {
209
210 double A[3][3];
211 lapack_int n = 3, nrhs = (lapack_int) num_vertices, lda = n, ldx = n, ipiv[3];
212 memcpy(A, triangle, sizeof(A));
213
214 // for a vertex v the spherical barycentric coordinates b are defined as
215 // follows
216 // A * b = v
217 // where: A is the matrix consisting of the vertex coordinates of the three
218 // corners of the triangle
219 // we compute b by solving this linear system using LAPACK
221 !LAPACKE_dgesv(
222 LAPACK_COL_MAJOR, n, nrhs, &A[0][0], lda, ipiv, sb_coords, ldx),
223 "(called from %s) internal error (could not solve linear 3x3 system)\n"
224 "(vector: (% .6e;% .6e;% .6e)\n"
225 " triangle: ((% .6e;% .6e;% .6e),\n"
226 " (% .6e;% .6e;% .6e),\n"
227 " (% .6e;% .6e;% .6e))",
228 caller, sb_coords[0], sb_coords[1], sb_coords[2],
229 triangle[0][0], triangle[0][1], triangle[0][2],
230 triangle[1][0], triangle[1][1], triangle[1][2],
231 triangle[2][0], triangle[2][1], triangle[2][2])
232}
233
234static inline int compare_size_t(const void * a, const void * b) {
235
236 size_t const * a_ = a, * b_ = b;
237
238 return (*a_ > *b_) - (*b_ > *a_);
239}
240
241static inline int compare_2_size_t(const void * a, const void * b) {
242
243 size_t const * a_ = a, * b_ = b;
244 int ret;
245 if ((ret = (a_[0] > b_[0]) - (b_[0] > a_[0]))) return ret;
246 else return (a_[1] > b_[1]) - (b_[1] > a_[1]);
247}
248
249static inline int compare_3_size_t(const void * a, const void * b) {
250
251 size_t const * a_ = a, * b_ = b;
252 int ret;
253 if ((ret = (a_[0] > b_[0]) - (b_[0] > a_[0]))) return ret;
254 if ((ret = (a_[1] > b_[1]) - (b_[1] > a_[1]))) return ret;
255 else return (a_[2] > b_[2]) - (b_[2] > a_[2]);
256}
257
258static inline int compare_HCSBB_D_NNN_size_t(const void * a, const void * b) {
259
260 size_t const * a_ = a, * b_ = b;
261 int ret;
262 for (size_t i = 0; i < HCSBB_D_NNN; ++i)
263 if ((ret = (a_[i] > b_[i]) - (b_[i] > a_[i])))
264 return ret;
265 return 0;
266}
267
268// Go through the source field triangles for all target points and check for
269// duplicated vertices, edges, and triangles. Some computation for each
270// require source field vertex, edge, and triangle can be done independent of
271// the actual target point, and hence needs to be done only once.
273 struct tgt_point_search_data * tgt_point_data, size_t num_edges,
274 size_t num_triangles,
275 size_t **unique_vertices, size_t * num_unique_vertices,
276 size_t (**unique_edge_to_unique_vertex)[2], size_t * num_unique_edges,
277 size_t (**unique_triangle_to_unique_edge)[3], size_t * num_unique_triangles) {
278
279 size_t (*edge_vertices)[2] =
280 xmalloc((num_edges + 3 * num_triangles) * sizeof(*edge_vertices));
281 size_t (*triangle_vertices)[3] =
282 xmalloc(num_triangles * sizeof(*triangle_vertices));
283
284 // get all edges and triangles
285 for (size_t i = 0; i < num_edges; ++i, ++tgt_point_data)
286 memcpy(edge_vertices[i], tgt_point_data->src_points, 2 * sizeof(size_t));
287 for (size_t i = 0; i < num_triangles; ++i, ++tgt_point_data) {
288 edge_vertices[3*i+num_edges+0][0] = tgt_point_data->src_points[0];
289 edge_vertices[3*i+num_edges+0][1] = tgt_point_data->src_points[1];
290 edge_vertices[3*i+num_edges+1][0] = tgt_point_data->src_points[0];
291 edge_vertices[3*i+num_edges+1][1] = tgt_point_data->src_points[2];
292 edge_vertices[3*i+num_edges+2][0] = tgt_point_data->src_points[1];
293 edge_vertices[3*i+num_edges+2][1] = tgt_point_data->src_points[2];
294 memcpy(
295 triangle_vertices[i], tgt_point_data->src_points, 3 * sizeof(size_t));
296 }
297
298 // sort edge end triangle data
299 qsort(edge_vertices, num_edges + 3 * num_triangles,
300 sizeof(*edge_vertices), compare_2_size_t);
301 qsort(triangle_vertices, num_triangles,
302 sizeof(*triangle_vertices), compare_3_size_t);
303
304 *num_unique_edges = num_edges + 3 * num_triangles;
305 *num_unique_triangles = num_triangles;
306
307 // remove duplicated edges and vertices
308 yac_remove_duplicates_size_t_2(edge_vertices, num_unique_edges);
309 yac_remove_duplicates_size_t_3(triangle_vertices, num_unique_triangles);
310
311 // get all unique vertices
312 *num_unique_vertices = 2 * (*num_unique_edges);
313 size_t * vertices = xmalloc((*num_unique_vertices) * sizeof(*vertices));
314 memcpy(
315 vertices, &(edge_vertices[0][0]), *num_unique_vertices * sizeof(*vertices));
316 qsort(vertices, *num_unique_vertices, sizeof(*vertices), compare_size_t);
317 yac_remove_duplicates_size_t(vertices, num_unique_vertices);
318 *unique_vertices =
319 xrealloc(vertices, *num_unique_vertices * sizeof(*vertices));
320
321 size_t (*triangle_edges)[3] =
322 xmalloc(3 * (*num_unique_triangles) * sizeof(*triangle_edges));
323 for (size_t i = 0; i < *num_unique_triangles; ++i) {
324 // edge across first vertex
325 triangle_edges[3*i+0][0] = triangle_vertices[i][1];
326 triangle_edges[3*i+0][1] = triangle_vertices[i][2];
327 triangle_edges[3*i+0][2] = 3*i+0;
328 // edge across second vertex
329 triangle_edges[3*i+1][0] = triangle_vertices[i][0];
330 triangle_edges[3*i+1][1] = triangle_vertices[i][2];
331 triangle_edges[3*i+1][2] = 3*i+1;
332 // edge across third vertex
333 triangle_edges[3*i+2][0] = triangle_vertices[i][0];
334 triangle_edges[3*i+2][1] = triangle_vertices[i][1];
335 triangle_edges[3*i+2][2] = 3*i+2;
336 }
337
338 // sort triangle edges
339 qsort(triangle_edges, 3 * (*num_unique_triangles),
340 sizeof(*triangle_edges), compare_2_size_t);
341
342 // look up triangle edges in the unique edges
343 *unique_triangle_to_unique_edge =
344 xmalloc(*num_unique_triangles * sizeof(**unique_triangle_to_unique_edge));
345 for (size_t i = 0, j = 0; i < 3 * (*num_unique_triangles); ++i) {
346 size_t * curr_edge = triangle_edges[i];
347 while (compare_2_size_t(curr_edge, edge_vertices[j])) ++j;
348 (&(*unique_triangle_to_unique_edge)[0][0])[curr_edge[2]] = j;
349 }
350 free(triangle_edges);
351
352 tgt_point_data -= num_edges + num_triangles;
353 for (size_t i = 0, j = 0; i < num_edges; ++i, ++tgt_point_data) {
354 while (compare_2_size_t(edge_vertices[j], tgt_point_data->src_points)) ++j;
355 YAC_ASSERT(j < *num_unique_edges, "edge ids missmatch")
356 tgt_point_data->interp_data.idx = j;
357 }
358 for (size_t i = 0, j = 0; i < num_triangles; ++i, ++tgt_point_data) {
359 while (compare_3_size_t(triangle_vertices[j], tgt_point_data->src_points))
360 ++j;
361 YAC_ASSERT(j < *num_unique_triangles, "triangle ids missmatch")
362 tgt_point_data->interp_data.idx = j;
363 }
364 free(triangle_vertices);
365
366 // generate unique_edge_to_unique_vertex
367 *unique_edge_to_unique_vertex =
368 xmalloc(*num_unique_edges * sizeof(**unique_edge_to_unique_vertex));
369 size_t * reorder_idx =
370 xmalloc(2 * (*num_unique_edges) * sizeof(*reorder_idx));
371 for (size_t i = 0; i < 2 * (*num_unique_edges); ++i) reorder_idx[i] = i;
373 &(edge_vertices[0][0]), 2 * (*num_unique_edges), reorder_idx);
374 for (size_t i = 0, j = 0; i < 2 * (*num_unique_edges); ++i) {
375 size_t curr_vertex = (&(edge_vertices[0][0]))[i];
376 while (curr_vertex != (*unique_vertices)[j]) ++j;
377 (&(*unique_edge_to_unique_vertex[0][0]))[reorder_idx[i]] = j;
378 }
379 free(edge_vertices);
380 free(reorder_idx);
381}
382
385 double (*gauss_points)[3], size_t * nnn_search_results,
386 double w_nnn[][HCSBB_NUM_GAUSS_POINTS], size_t * src_point_buffer,
387 yac_int * global_id_buffer, yac_const_coordinate_pointer src_point_coords,
388 const_yac_int_pointer src_point_global_ids) {
389
390 // get all unique nnn_search result points
391 memcpy(src_point_buffer, nnn_search_results,
392 HCSBB_GAUSS_NNN * HCSBB_NUM_GAUSS_POINTS * sizeof(*src_point_buffer));
393 qsort(src_point_buffer, HCSBB_GAUSS_NNN * HCSBB_NUM_GAUSS_POINTS,
394 sizeof(*src_point_buffer), compare_size_t);
395 size_t num_unique_result_points = HCSBB_GAUSS_NNN * HCSBB_NUM_GAUSS_POINTS;
396 yac_remove_duplicates_size_t(src_point_buffer, &num_unique_result_points);
397
398 // sort result points by their global ids
399 for (size_t i = 0; i < num_unique_result_points; ++i)
400 global_id_buffer[i] = src_point_global_ids[src_point_buffer[i]];
402 global_id_buffer, num_unique_result_points, src_point_buffer);
403
405 xmalloc(num_unique_result_points * sizeof(*src_point_buffer));
406 memcpy(gauss_nnn_patch->src_points, src_point_buffer,
407 num_unique_result_points * sizeof(*src_point_buffer));
408 gauss_nnn_patch->num_src_points = num_unique_result_points;
409
410 // compute w_nnn
411 {
412 for (size_t i = 0; i < num_unique_result_points; ++i)
413 for (size_t j = 0; j < HCSBB_NUM_GAUSS_POINTS; ++j)
414 w_nnn[i][j] = 0.0;
415
416 double inv_distances[HCSBB_GAUSS_NNN];
417 size_t reorder_idx[HCSBB_GAUSS_NNN];
418 for (size_t i = 0; i < HCSBB_NUM_GAUSS_POINTS; ++i) {
419
420 size_t * curr_result_points = nnn_search_results + i * HCSBB_GAUSS_NNN;
421 double * curr_gauss_points = gauss_points[i];
422 double distance_sum = 0.0;
423 size_t j;
424
425 // for all results of the current request point
426 for (j = 0; j < HCSBB_GAUSS_NNN; ++j) {
427
428 double distance =
430 curr_gauss_points,
431 (double*)(src_point_coords[curr_result_points[j]]));
432
433 // if src and tgt point are at the same location
434 if (distance < yac_angle_tol) break;
435
436 double inv_distance = 1.0 / (distance * distance);
437 inv_distances[j] = inv_distance;
438 distance_sum += inv_distance;
439 }
440
441 // if there is no source point that exactly matches the target point
442 if (j == HCSBB_GAUSS_NNN) {
443
444 yac_int curr_global_ids[HCSBB_GAUSS_NNN];
445 for (size_t k = 0; k < HCSBB_GAUSS_NNN; ++k)
446 curr_global_ids[k] = src_point_global_ids[curr_result_points[k]];
447 for (size_t l = 0; l < HCSBB_GAUSS_NNN; ++l) reorder_idx[l] = l;
448
449 // sort current results by their global ids
451 curr_global_ids, HCSBB_GAUSS_NNN, reorder_idx);
452
453 distance_sum = 1.0 / distance_sum;
454 for (size_t k = 0, l = 0; k < HCSBB_GAUSS_NNN; ++k) {
455 yac_int curr_global_id = curr_global_ids[k];
456 while (curr_global_id != global_id_buffer[l]) ++l;
457 w_nnn[l][i] = inv_distances[reorder_idx[k]] * distance_sum;
458 }
459
460 } else {
461
462 yac_int curr_global_id = src_point_global_ids[curr_result_points[j]];
463 size_t l = 0;
464 while (curr_global_id != global_id_buffer[l]) ++l;
465 w_nnn[l][i] = 1.0;
466 }
467 }
468 }
469
470 double (*w_g)[HCSBB_NUM_GAUSS_POINTS] =
472
473 // compute and store w_g * w_nnn
474 double (*weights)[HCSBB_NUM_SBB_COEFFS] =
475 xmalloc(num_unique_result_points * sizeof(*weights));
476 gauss_nnn_patch->weights = (double*)weights;
477 for (size_t i = 0; i < num_unique_result_points; ++i) {
478 for (size_t j = 0; j < HCSBB_NUM_SBB_COEFFS; ++j) {
479 double accu = 0.0;
480 for (size_t l = 0; l < HCSBB_NUM_GAUSS_POINTS; ++l)
481 accu += w_g[j][l] * w_nnn[i][l];
482 weights[i][j] = accu;
483 }
484 }
485
486 free(w_g);
487}
488
489// computes the directional derivatives of the spherical Bernstein basis
490// polynomials for degree = 3 in the given direction
491// the polynomials B_ijk are ordered in the following order:
492// B_003, B_012, B_021, B_030, B_102, B_111, B_120, B_201, B_210, B_300
494 double bnd_triangle[3][3], double direction[3], double coordinate_xyz[3],
495 double d_sbb_polynomials[HCSBB_NUM_SBB_COEFFS]) {
496
497 double sb_coords[2][3] =
498 {{coordinate_xyz[0], coordinate_xyz[1], coordinate_xyz[2]},
499 {direction[0], direction[1], direction[2]}};
500
501 // compute the spherical barycentric coordinates of the point and the
502 // direction
504 &(sb_coords[0][0]), 2, bnd_triangle, "compute_d_sbb_polynomials_3d");
505
506#define POW_0(x) (1.0)
507#define POW_1(x) ((x))
508#define POW_2(x) ((x)*(x))
509#define POW_3(x) ((x)*(x)*(x))
510#define FAC_0 (1.0)
511#define FAC_1 (1.0)
512#define FAC_2 (2.0)
513#define FAC_3 (6.0)
514#define SB_COORD_P (sb_coords[0])
515#define SB_COORD_D (sb_coords[1])
516
517 d_sbb_polynomials[0] =
518 // SB_COORD_D[0] * (0.0 * FAC_3 / (FAC_0 * FAC_0 * FAC_3)) *
519 // (POW_0(SB_COORD_P[0]) * POW_0(SB_COORD_P[1]) * POW_3(SB_COORD_P[2])) +
520 // SB_COORD_D[1] * (0.0 * FAC_3 / (FAC_0 * FAC_0 * FAC_3)) *
521 // (POW_0(SB_COORD_P[0]) * POW_0(SB_COORD_P[1]) * POW_3(SB_COORD_P[2])) +
522 SB_COORD_D[2] * (3.0 * FAC_3 / (FAC_0 * FAC_0 * FAC_3)) *
524 d_sbb_polynomials[1] =
525 // SB_COORD_D[0] * (0.0 * FAC_3 / (FAC_0 * FAC_1 * FAC_2)) *
526 // (POW_0(SB_COORD_P[0]) * POW_1(SB_COORD_P[1]) * POW_2(SB_COORD_P[2])) +
527 SB_COORD_D[1] * (1.0 * FAC_3 / (FAC_0 * FAC_1 * FAC_2)) *
528 (POW_0(SB_COORD_P[0]) * POW_0(SB_COORD_P[1]) * POW_2(SB_COORD_P[2])) +
529 SB_COORD_D[2] * (2.0 * FAC_3 / (FAC_0 * FAC_1 * FAC_2)) *
531 d_sbb_polynomials[2] =
532 // SB_COORD_D[0] * (0.0 * FAC_3 / (FAC_0 * FAC_2 * FAC_1)) *
533 // (POW_0(SB_COORD_P[0]) * POW_2(SB_COORD_P[1]) * POW_1(SB_COORD_P[2])) +
534 SB_COORD_D[1] * (2.0 * FAC_3 / (FAC_0 * FAC_2 * FAC_1)) *
535 (POW_0(SB_COORD_P[0]) * POW_1(SB_COORD_P[1]) * POW_1(SB_COORD_P[2])) +
536 SB_COORD_D[2] * (1.0 * FAC_3 / (FAC_0 * FAC_2 * FAC_1)) *
538 d_sbb_polynomials[3] =
539 // SB_COORD_D[0] * (0.0 * FAC_3 / (FAC_0 * FAC_3 * FAC_0)) *
540 // (POW_0(SB_COORD_P[0]) * POW_3(SB_COORD_P[1]) * POW_0(SB_COORD_P[2])) +
541 SB_COORD_D[1] * (3.0 * FAC_3 / (FAC_0 * FAC_3 * FAC_0)) *
543 // SB_COORD_D[2] * (0.0 * FAC_3 / (FAC_0 * FAC_3 * FAC_0)) *
544 // (POW_0(SB_COORD_P[0]) * POW_3(SB_COORD_P[1]) * POW_0(SB_COORD_P[2]));
545 d_sbb_polynomials[4] =
546 SB_COORD_D[0] * (1.0 * FAC_3 / (FAC_1 * FAC_0 * FAC_2)) *
547 (POW_0(SB_COORD_P[0]) * POW_0(SB_COORD_P[1]) * POW_2(SB_COORD_P[2])) +
548 // SB_COORD_D[1] * (0.0 * FAC_3 / (FAC_1 * FAC_0 * FAC_2)) *
549 // (POW_1(SB_COORD_P[0]) * POW_0(SB_COORD_P[1]) * POW_2(SB_COORD_P[2])) +
550 SB_COORD_D[2] * (2.0 * FAC_3 / (FAC_1 * FAC_0 * FAC_2)) *
552 d_sbb_polynomials[5] =
553 SB_COORD_D[0] * (1.0 * FAC_3 / (FAC_1 * FAC_1 * FAC_1)) *
554 (POW_0(SB_COORD_P[0]) * POW_1(SB_COORD_P[1]) * POW_1(SB_COORD_P[2])) +
555 SB_COORD_D[1] * (1.0 * FAC_3 / (FAC_1 * FAC_1 * FAC_1)) *
556 (POW_1(SB_COORD_P[0]) * POW_0(SB_COORD_P[1]) * POW_1(SB_COORD_P[2])) +
557 SB_COORD_D[2] * (1.0 * FAC_3 / (FAC_1 * FAC_1 * FAC_1)) *
559 d_sbb_polynomials[6] =
560 SB_COORD_D[0] * (1.0 * FAC_3 / (FAC_1 * FAC_2 * FAC_0)) *
561 (POW_0(SB_COORD_P[0]) * POW_2(SB_COORD_P[1]) * POW_0(SB_COORD_P[2])) +
562 SB_COORD_D[1] * (2.0 * FAC_3 / (FAC_1 * FAC_2 * FAC_0)) *
564 // SB_COORD_D[2] * (0.0 * FAC_3 / (FAC_1 * FAC_2 * FAC_0)) *
565 // (POW_1(SB_COORD_P[0]) * POW_2(SB_COORD_P[1]) * POW_0(SB_COORD_P[2]));
566 d_sbb_polynomials[7] =
567 SB_COORD_D[0] * (2.0 * FAC_3 / (FAC_2 * FAC_0 * FAC_1)) *
568 (POW_1(SB_COORD_P[0]) * POW_0(SB_COORD_P[1]) * POW_1(SB_COORD_P[2])) +
569 // SB_COORD_D[1] * (0.0 * FAC_3 / (FAC_2 * FAC_0 * FAC_1)) *
570 // (POW_2(SB_COORD_P[0]) * POW_0(SB_COORD_P[1]) * POW_1(SB_COORD_P[2])) +
571 SB_COORD_D[2] * (1.0 * FAC_3 / (FAC_2 * FAC_0 * FAC_1)) *
573 d_sbb_polynomials[8] =
574 SB_COORD_D[0] * (2.0 * FAC_3 / (FAC_2 * FAC_1 * FAC_0)) *
575 (POW_1(SB_COORD_P[0]) * POW_1(SB_COORD_P[1]) * POW_0(SB_COORD_P[2])) +
576 SB_COORD_D[1] * (1.0 * FAC_3 / (FAC_2 * FAC_1 * FAC_0)) *
578 // SB_COORD_D[2] * (0.0 * FAC_3 / (FAC_2 * FAC_1 * FAC_0)) *
579 // (POW_2(SB_COORD_P[0]) * POW_1(SB_COORD_P[1]) * POW_0(SB_COORD_P[2]));
580 d_sbb_polynomials[9] =
581 SB_COORD_D[0] * (3.0 * FAC_3 / (FAC_3 * FAC_0 * FAC_0)) *
583 // SB_COORD_D[1] * (0.0 * FAC_3 / (FAC_3 * FAC_0 * FAC_0)) *
584 // (POW_3(SB_COORD_P[0]) * POW_0(SB_COORD_P[1]) * POW_0(SB_COORD_P[2])) +
585 // SB_COORD_D[2] * (0.0 * FAC_3 / (FAC_3 * FAC_0 * FAC_0)) *
586 // (POW_3(SB_COORD_P[0]) * POW_0(SB_COORD_P[1]) * POW_0(SB_COORD_P[2]));
587
588#undef SB_COORD_P
589#undef SB_COORD_D
590#undef POW_0
591#undef POW_1
592#undef POW_2
593#undef POW_3
594#undef FAC_0
595#undef FAC_1
596#undef FAC_2
597#undef FAC_3
598}
599
601 struct gauss_nnn_patch * gauss_nnn_patch, double coordinate_xyz[3],
602 double direction[3], struct weight_vector_data * weights,
603 double mult_factor) {
604
605 // compute w_p
606 double d_sbb_vertex_polynomials[HCSBB_NUM_SBB_COEFFS];
608 gauss_nnn_patch->bnd_triangle, direction, coordinate_xyz,
609 d_sbb_vertex_polynomials);
610
611 // compute w_p * (w_g * w_nnn)
612 size_t * src_points = gauss_nnn_patch->src_points;
613 size_t num_src_points = gauss_nnn_patch->num_src_points;
614 double * d_data_weights = gauss_nnn_patch->weights;
615 for (size_t i = 0, k = 0; i < num_src_points; ++i) {
616
617 double weight = 0.0;
618 for (size_t j = 0; j < HCSBB_NUM_SBB_COEFFS; ++j, ++k)
619 weight += d_sbb_vertex_polynomials[j] * d_data_weights[k];
620
621 weights[i].weight = weight * mult_factor;
622 weights[i].point_id = src_points[i];
623 }
624}
625
627 struct edge_interp_data * edge_data, size_t num_edges) {
628
629 size_t edge_weight_vector_data_buffer_size = 0;
630 // count total number of weight_vector_data elements required
631 for (size_t i = 0; i < num_edges; ++i)
632 edge_weight_vector_data_buffer_size +=
633 2 + edge_data[i].vertex_d_data[0]->gauss_nnn_patch->num_src_points +
635
636 // 2 -> two corner weights
637 // 2*(HCSBB_NUM_GAUSS_POINTS*HCSBB_GAUSS_NNN+1)
638 // -> maximum number of weights per edge coefficient
639 struct weight_vector_data * curr_edge_weight_vector_data =
640 (edge_weight_vector_data_buffer_size > 0)?
641 xmalloc(edge_weight_vector_data_buffer_size *
642 sizeof(*curr_edge_weight_vector_data)):NULL;
643
644 for (size_t i = 0; i < num_edges; ++i) {
645
646 struct edge_interp_data * curr_edge = edge_data + i;
647 struct vertex_interp_data * curr_vertex_d_data[2] = {
648 curr_edge->vertex_d_data[0], curr_edge->vertex_d_data[1]};
649
650 double direction[3] = {
651 curr_vertex_d_data[1]->coordinate_xyz[0] -
652 curr_vertex_d_data[0]->coordinate_xyz[0],
653 curr_vertex_d_data[1]->coordinate_xyz[1] -
654 curr_vertex_d_data[0]->coordinate_xyz[1],
655 curr_vertex_d_data[1]->coordinate_xyz[2] -
656 curr_vertex_d_data[0]->coordinate_xyz[2]};
657
658 // c_210 and c_120
659 for (size_t j = 0; j < 2; ++j) {
660
661 size_t n = curr_vertex_d_data[j]->gauss_nnn_patch->num_src_points + 1;
662
664 curr_vertex_d_data[j]->gauss_nnn_patch,
665 curr_vertex_d_data[j]->coordinate_xyz, direction,
666 curr_edge_weight_vector_data, 1.0/3.0);
667
668 curr_edge_weight_vector_data[n-1].weight = 1.0;
669 curr_edge_weight_vector_data[n-1].point_id =
670 curr_edge->vertex_d_data[j]->src_point;
671 curr_edge->c[j].data = curr_edge_weight_vector_data;
672 curr_edge->c[j].n = n;
673
674 direction[0] *= -1, direction[1] *= -1, direction[2] *= -1;
675
676 curr_edge_weight_vector_data += n;
677 }
678 }
679}
680
682 void const * a, void const * b) {
683
684 struct weight_vector_data const * weight_a =
685 ((struct weight_vector_data_pos const *)a)->weight;
686 struct weight_vector_data const * weight_b =
687 ((struct weight_vector_data_pos const *)b)->weight;
688
689 int ret = (weight_a->point_id > weight_b->point_id) -
690 (weight_a->point_id < weight_b->point_id);
691 if (ret) return ret;
692 double abs_weight_a = fabs(weight_a->weight);
693 double abs_weight_b = fabs(weight_b->weight);
694 ret = (abs_weight_a > abs_weight_b) - (abs_weight_a < abs_weight_b);
695 if (ret) return ret;
696 return (weight_a->weight > weight_b->weight) -
697 (weight_a->weight < weight_b->weight);
698}
699
701 void const * a, void const * b) {
702
703 struct weight_vector_data const * weight_a =
704 (struct weight_vector_data const *)a;
705 struct weight_vector_data const * weight_b =
706 (struct weight_vector_data const *)b;
707
708 return (weight_a->point_id > weight_b->point_id) -
709 (weight_a->point_id < weight_b->point_id);
710}
711
713 void const * a, void const * b) {
714
715 return ((struct weight_vector_data_pos const *)a)->pos -
716 ((struct weight_vector_data_pos const *)b)->pos;
717}
718
720 struct weight_vector_data * weights, size_t * n,
722
723 size_t n_ = *n;
724
725 if (n_ <= 1) return;
726
727 for (size_t i = 0; i < n_; ++i) {
728 buffer[i].weight = weights + i;
729 buffer[i].pos = i;
730 }
731
733
734 size_t new_n = 1;
735 struct weight_vector_data_pos * prev_weight_data_pos = buffer;
736 struct weight_vector_data * prev_weight_data = prev_weight_data_pos->weight;
737 struct weight_vector_data_pos * curr_weight_data_pos = buffer + 1;
738 for (size_t i = 1; i < n_; ++i, ++curr_weight_data_pos) {
739
740 struct weight_vector_data * curr_weight_data = curr_weight_data_pos->weight;
741 if (!compare_weight_vector_data_point(prev_weight_data, curr_weight_data)) {
742 prev_weight_data->weight += curr_weight_data->weight;
743 if (prev_weight_data_pos->pos > curr_weight_data_pos->pos)
744 prev_weight_data_pos->pos = curr_weight_data_pos->pos;
745 } else {
746 ++new_n;
747 ++prev_weight_data_pos;
748 *prev_weight_data_pos = *curr_weight_data_pos;
749 prev_weight_data = prev_weight_data_pos->weight;
750 }
751 }
752
753 if (n_ == new_n) return;
754
755 qsort(buffer, new_n, sizeof(*buffer), compare_weight_vector_data_pos_pos);
756
757 for (size_t i = 0; i < new_n; ++i) weights[i] = *(buffer[i].weight);
758
759 *n = new_n;
760}
761
763 struct triangle_interp_data * triangle_data, size_t num_triangles) {
764
765 // maximum number of coefficients per c_111 alpha value
766 // 6 edge coefficients (HCSBB_GAUSS_NNN * HCSBB_NUM_GAUSS_POINTS + 1)
767 // 2 corner coefficients (1)
768 // 1 middle point coefficient (HCSBB_GAUSS_NNN * HCSBB_NUM_GAUSS_POINTS)
769 struct weight_vector_data * weight_vector_data_buffer =
770 xmalloc((6 * (HCSBB_GAUSS_NNN * HCSBB_NUM_GAUSS_POINTS + 1) + 2 * 1 +
772 sizeof(*weight_vector_data_buffer));
773 struct weight_vector_data_pos * weight_vector_data_pos_buffer =
774 xmalloc((6 * (HCSBB_GAUSS_NNN * HCSBB_NUM_GAUSS_POINTS + 1) + 2 * 1 +
776 sizeof(*weight_vector_data_pos_buffer));
777
778 struct triangle_interp_data * curr_triangle = triangle_data;
779 for (size_t i = 0; i < num_triangles; ++i, ++curr_triangle) {
780
781 // z_w0/3 = B_020(w0) * (b_0(g0)*c_120 + b_1(g0)*c_030 + b_2(g0)*c_021) +
782 // B_011(w0) * (b_0(g0)*a_1 b_1(g0)*c_021 + b_2(g0)*c_012) +
783 // B_002(w0) * (b_0(g0)*c_102 + b_1(g0)*c_012 + b_2(g0)*c_003)
784 // w0 = ||v_1+v_2|| -> middle point of edge 0
785 // g0 = v_2 x v_1 -> vector, which is a tangent of the sphere in w0 and
786 // perpendicular to w0
787 // z_w0 = D_g0 f(w0) -> directional derivative of f in w0 in the direction
788 // of g0
789 // =>
790 // a_0 = (D_g f(w0)/3 -
791 // B_020(w0) * (b_0(g0)*c_120 + b_1(g0)*c_030 + b_2(g0)*c_021) -
792 // B_011(w0) * ( b_1(g0)*c_021 + b_2(g0)*c_012) -
793 // B_002(w0) * (b_0(g0)*c_102 + b_1(g0)*c_012 + b_2(g0)*c_003)) /
794 // (B_011(w0) * b_0(g0))
795 // a_1 = (D_g f(w1)/3 -
796 // B_200(w1) * (b_0(g1)*c_300 + b_1(g1)*c_210 + b_2(g1)*c_201) -
797 // B_101(w1) * (b_0(g1)*c_201 + b_2(g1)*c_102) -
798 // B_002(w1) * (b_0(g1)*c_102 + b_1(g1)*c_012 + b_2(g1)*c_003)) /
799 // (B_101(w1) * b_1(g1))
800 // a_2 = (D_g f(w2)/3 -
801 // B_200(w2) * (b_0(g2)*c_300 + b_1(g2)*c_210 + b_2(g2)*c_201) -
802 // B_110(w2) * (b_0(g2)*c_210 + b_1(g2)*c_120 ) -
803 // B_020(w2) * (b_0(g2)*c_120 + b_1(g2)*c_030 + b_2(g2)*c_021)) /
804 // (B_110(w2) * b_2(g2))
805
806 struct edge_interp_data ** curr_edges = curr_triangle->edges;
807 struct vertex_interp_data * vertex_d_data[3] = {
808 curr_edges[2]->vertex_d_data[0],
809 curr_edges[2]->vertex_d_data[1],
810 curr_edges[1]->vertex_d_data[1]};
811 size_t src_points[3] = {
812 vertex_d_data[0]->src_point,
813 vertex_d_data[1]->src_point,
814 vertex_d_data[2]->src_point};
815
816 // remark the corners of the triangle are sorted by global ids, the same is
817 // true for the edge data
818 struct weight_vector_data c_3_data[3] = {
819 {.weight = 1.0, .point_id = src_points[0]},
820 {.weight = 1.0, .point_id = src_points[1]},
821 {.weight = 1.0, .point_id = src_points[2]}};
822 struct weight_vector c_3[3] = {{.data = &(c_3_data[0]), .n = 1},
823 {.data = &(c_3_data[1]), .n = 1},
824 {.data = &(c_3_data[2]), .n = 1}};
825 struct weight_vector * c_300 = &(c_3[0]);
826 struct weight_vector * c_030 = &(c_3[1]);
827 struct weight_vector * c_003 = &(c_3[2]);
828 struct weight_vector * c_021 = &(curr_edges[0]->c[0]);
829 struct weight_vector * c_012 = &(curr_edges[0]->c[1]);
830 struct weight_vector * c_201 = &(curr_edges[1]->c[0]);
831 struct weight_vector * c_102 = &(curr_edges[1]->c[1]);
832 struct weight_vector * c_210 = &(curr_edges[2]->c[0]);
833 struct weight_vector * c_120 = &(curr_edges[2]->c[1]);
834
835 double corner_coordinate_xyz[3][3] = {
836 {vertex_d_data[0]->coordinate_xyz[0],
837 vertex_d_data[0]->coordinate_xyz[1],
838 vertex_d_data[0]->coordinate_xyz[2]},
839 {vertex_d_data[1]->coordinate_xyz[0],
840 vertex_d_data[1]->coordinate_xyz[1],
841 vertex_d_data[1]->coordinate_xyz[2]},
842 {vertex_d_data[2]->coordinate_xyz[0],
843 vertex_d_data[2]->coordinate_xyz[1],
844 vertex_d_data[2]->coordinate_xyz[2]}};
845
846 // vector which are tangents of the sphere in the middle points of the edges
847 // and are perpendicular to the edges
848 double * g[3] = {
849 &(curr_edges[0]->g[0]), &(curr_edges[1]->g[0]), &(curr_edges[2]->g[0])};
850
851 // spherical barycentric coordinates of g
852 double b_g[3][3] = {{g[0][0], g[0][1], g[0][2]},
853 {g[1][0], g[1][1], g[1][2]},
854 {g[2][0], g[2][1], g[2][2]}};
856 &(b_g[0][0]), 3, corner_coordinate_xyz, "compute_triangle_coefficients");
857
858 // computing quadratic spherical Bernstein-Bezier polynomials for the edge
859 // middle points (e.g. B_020(w0)) using w0 as an example
860 // I. w0 is in the middle of the edge opposing corner 0
861 // II. for the barycentric coordinates if w0 we can say the following
862 // a) b_0(w0) = 0 -> because it is on the edge opposing v0
863 // b) b_1(w0) = b_2(w0) -> because it is in the middle between v1 and v2
864 // III. B_ijk(p) = d!/(i!*j!*k!) * b_0(p)^i * b_1(p)^j * b_2(p)^k
865 // -> for all (i + j + k) = d
866 // -> p = w0 and d = 2 in our case
867 //
868 // from II.a) it follows: B_200 = B_110 = B_101 = 0
869 // from II.b) it follows: B_020 = B_002 = 2 * B_011 = b_1(w0) = b_2(w0) = bw
870
871 double bw[3] = {
872 curr_edges[0]->sb_coord_middle_point *
873 curr_edges[0]->sb_coord_middle_point,
874 curr_edges[1]->sb_coord_middle_point *
875 curr_edges[1]->sb_coord_middle_point,
876 curr_edges[2]->sb_coord_middle_point *
877 curr_edges[2]->sb_coord_middle_point};
878
879#define COPY_D_DATA(edge_idx) \
880 { \
881 get_derivative_weights( \
882 curr_edges[edge_idx]->middle_d_data.gauss_nnn_patch, \
883 curr_edges[edge_idx]->middle_d_data.coordinate_xyz, g[edge_idx], \
884 weight_vector_data_buffer + n, 1.0 / 3.0); \
885 n += curr_edges[edge_idx]->middle_d_data.gauss_nnn_patch->num_src_points; \
886 }
887#define COPY_COEFF(c_ijk, edge_idx, b_idx, bw_factor) \
888 { \
889 struct weight_vector_data * curr_buffer = weight_vector_data_buffer + n; \
890 size_t curr_n = c_ijk->n; \
891 memcpy(curr_buffer, c_ijk->data, curr_n * sizeof(*curr_buffer)); \
892 n += curr_n; \
893 double factor = - bw[edge_idx] * b_g[edge_idx][b_idx] * bw_factor; \
894 for (size_t i_ = 0; i_ < curr_n; ++i_) curr_buffer[i_].weight *= factor; \
895 }
896#define MULT_COEFF(edge_idx) \
897 { \
898 double factor = 1.0 / (2.0 * bw[edge_idx] * b_g[edge_idx][edge_idx]); \
899 for (size_t i_ = 0; i_ < n; ++i_) \
900 weight_vector_data_buffer[i_].weight *= factor; \
901 }
902#define COMPACT_WEIGHTS(edge_idx) \
903 { \
904 compact_weight_vector_data( \
905 weight_vector_data_buffer, &n, weight_vector_data_pos_buffer); \
906 curr_triangle->c_111_a[edge_idx].data = \
907 xmalloc(n * sizeof(*(curr_triangle->c_111_a[edge_idx].data))); \
908 memcpy(curr_triangle->c_111_a[edge_idx].data, weight_vector_data_buffer, \
909 n * sizeof(*weight_vector_data_buffer)); \
910 curr_triangle->c_111_a[edge_idx].n = n; \
911 }
912
913 // a_0 = (D_g f(w0)/3 -
914 // B_020(w0) * (b_0(g0)*c_120 + b_1(g0)*c_030 + b_2(g0)*c_021) -
915 // B_011(w0) * ( b_1(g0)*c_021 + b_2(g0)*c_012) -
916 // B_002(w0) * (b_0(g0)*c_102 + b_1(g0)*c_012 + b_2(g0)*c_003)) /
917 // (B_011(w0) * b_0(g0))
918 size_t n = 0;
919 COPY_D_DATA(0); // D_g f(w0)/3
920 COPY_COEFF(c_120, 0, 0, 1.0); // - B_020(w0) * b_0(g0) * c_120
921 COPY_COEFF(c_030, 0, 1, 1.0); // - B_020(w0) * b_1(g0) * c_030
922 COPY_COEFF(c_021, 0, 2, 1.0); // - B_020(w0) * b_2(g0) * c_021
923 COPY_COEFF(c_021, 0, 1, 2.0); // - B_011(w0) * b_1(g0) * c_021
924 COPY_COEFF(c_012, 0, 2, 2.0); // - B_011(w0) * b_2(g0) * c_012
925 COPY_COEFF(c_102, 0, 0, 1.0); // - B_002(w0) * b_0(g0) * c_102
926 COPY_COEFF(c_012, 0, 1, 1.0); // - B_002(w0) * b_1(g0) * c_012
927 COPY_COEFF(c_003, 0, 2, 1.0); // - B_002(w0) * b_2(g0) * c_003
928 MULT_COEFF(0); // (...) / (B_011(w0) * b_0(g0))
929 COMPACT_WEIGHTS(0); // a_0 = ...
930
931 // a_1 = (D_g f(w1)/3 -
932 // B_200(w1) * (b_0(g1)*c_300 + b_1(g1)*c_210 + b_2(g1)*c_201) -
933 // B_101(w1) * (b_0(g1)*c_201 + b_2(g1)*c_102) -
934 // B_002(w1) * (b_0(g1)*c_102 + b_1(g1)*c_012 + b_2(g1)*c_003)) /
935 // (B_101(w1) * b_1(g1))
936 n = 0;
937 COPY_D_DATA(1); // D_g f(w1)/3
938 COPY_COEFF(c_300, 1, 0, 1.0); // - B_200(w1) * b_0(g1) * c_300
939 COPY_COEFF(c_210, 1, 1, 1.0); // - B_200(w1) * b_1(g1) * c_210
940 COPY_COEFF(c_201, 1, 2, 1.0); // - B_200(w1) * b_2(g1) * c_201
941 COPY_COEFF(c_201, 1, 0, 2.0); // - B_101(w1) * b_0(g1) * c_201
942 COPY_COEFF(c_102, 1, 2, 2.0); // - B_101(w1) * b_2(g1) * c_102
943 COPY_COEFF(c_102, 1, 0, 1.0); // - B_002(w1) * b_0(g1) * c_102
944 COPY_COEFF(c_012, 1, 1, 1.0); // - B_002(w1) * b_1(g1) * c_012
945 COPY_COEFF(c_003, 1, 2, 1.0); // - B_002(w1) * b_2(g1) * c_003
946 MULT_COEFF(1); // (...) / (B_101(w1) * b_1(g1))
947 COMPACT_WEIGHTS(1); // a_1 = ...
948
949 // a_2 = (D_g f(w2)/3 -
950 // B_200(w2) * (b_0(g2)*c_300 + b_1(g2)*c_210 + b_2(g2)*c_201) -
951 // B_110(w2) * (b_0(g2)*c_210 + b_1(g2)*c_120 ) -
952 // B_020(w2) * (b_0(g2)*c_120 + b_1(g2)*c_030 + b_2(g2)*c_021)) /
953 // (B_110(w2) * b_2(g2))
954 n = 0;
955 COPY_D_DATA(2); // D_g f(w2)/3
956 COPY_COEFF(c_300, 2, 0, 1.0); // - B_200(w2) * b_0(g2) * c_300
957 COPY_COEFF(c_210, 2, 1, 1.0); // - B_200(w2) * b_1(g2) * c_210
958 COPY_COEFF(c_201, 2, 2, 1.0); // - B_200(w2) * b_2(g2) * c_201
959 COPY_COEFF(c_210, 2, 0, 2.0); // - B_110(w2) * b_0(g2) * c_210
960 COPY_COEFF(c_120, 2, 1, 2.0); // - B_110(w2) * b_1(g2) * c_120
961 COPY_COEFF(c_120, 2, 0, 1.0); // - B_020(w2) * b_0(g2) * c_120
962 COPY_COEFF(c_030, 2, 1, 1.0); // - B_020(w2) * b_1(g2) * c_030
963 COPY_COEFF(c_021, 2, 2, 1.0); // - B_020(w2) * b_2(g2) * c_021
964 MULT_COEFF(2); // (...) / (B_110(w2) * b_2(g2))
965 COMPACT_WEIGHTS(2); // a_2 = ...
966
967#undef COMPACT_WEIGHTS
968#undef MULT_COEFF
969#undef COPY_COEFF
970#undef COPY_D_DATA
971 }
972 free(weight_vector_data_buffer);
973 free(weight_vector_data_pos_buffer);
974}
975
977 struct tgt_point_search_data * tgt_point_data) {
978
980 (tgt_point_data->type_flag == ON_VERTEX) ||
981 (tgt_point_data->type_flag == ON_EDGE) ||
982 (tgt_point_data->type_flag == ON_TRIANGLE), "invalid type_flag")
983 switch(tgt_point_data->type_flag) {
984
985 case (ON_VERTEX):
986 return 1;
987 case (ON_EDGE):
988 return 2 + tgt_point_data->interp_data.edge->c[0].n +
989 tgt_point_data->interp_data.edge->c[1].n;
990 default:
991 case (ON_TRIANGLE): {
992 struct triangle_interp_data * triangle_data =
993 tgt_point_data->interp_data.triangle;
994 return 3 +
995 triangle_data->edges[0]->c[0].n + triangle_data->edges[0]->c[1].n +
996 triangle_data->edges[1]->c[0].n + triangle_data->edges[1]->c[1].n +
997 triangle_data->edges[2]->c[0].n + triangle_data->edges[2]->c[1].n +
998 triangle_data->c_111_a[0].n +
999 triangle_data->c_111_a[1].n +
1000 triangle_data->c_111_a[2].n;
1001 }
1002 };
1003}
1004
1006 struct tgt_point_search_data * tgt_point_data,
1007 struct weight_vector_data * weights, size_t * n) {
1008
1009 weights[0].weight = 1.0;
1010 weights[0].point_id = tgt_point_data->src_points[0];
1011 *n = 1;
1012}
1013
1015 struct tgt_point_search_data * tgt_point_data,
1016 struct weight_vector_data * weights, size_t * n) {
1017
1018 // spherical barycentric coordinates of the target point
1019 double * sb_coords = tgt_point_data->sb_coords;
1020
1021 // compute the spherical Bernstein base polynomials for the given vertices
1022 // (since the target point is on the edge, we only need a subset of the
1023 // polynomials, because the rest are zero anyway)
1024 // B_ijk(p) = d!/(i!*j!*k!) * b_0(p)^i * b_1(p)^j * b_2(p)^k
1025 double B_300 = sb_coords[0] * sb_coords[0] * sb_coords[0];
1026 double B_030 = sb_coords[1] * sb_coords[1] * sb_coords[1];
1027 double B_210 = 3.0 * sb_coords[0] * sb_coords[0] * sb_coords[1];
1028 double B_120 = 3.0 * sb_coords[0] * sb_coords[1] * sb_coords[1];
1029
1030 // c_300 = f(v1)
1031 // c_030 = f(v2)
1032 // c_210 and c_120
1033 struct weight_vector * c = &(tgt_point_data->interp_data.edge->c[0]);
1034
1035 // f(p) = SUM(c_ijk * B_ijk) // for 300, 030, 210, and 120
1036
1037 size_t * src_points = tgt_point_data->src_points;
1038
1039 // c_300 * B_300
1040 // weights[0].weight = B_300 + B_210;
1041 weights[0].weight = B_300;
1042 weights[0].point_id = src_points[0];
1043 // c_030 * B_030
1044 // weights[1].weight = B_030 + B_120;
1045 weights[1].weight = B_030;
1046 weights[1].point_id = src_points[1];
1047 // c_210 * B_210
1048 struct weight_vector_data * curr_weights = weights + 2;
1049 memcpy(curr_weights, c[0].data, c[0].n * sizeof(*curr_weights));
1050 for (size_t i = 0; i < c[0].n; ++i) curr_weights[i].weight *= B_210;
1051 // c_120 * B_120
1052 curr_weights += c[0].n;
1053 memcpy(curr_weights, c[1].data, c[1].n * sizeof(*curr_weights));
1054 for (size_t i = 0; i < c[1].n; ++i) curr_weights[i].weight *= B_120;
1055
1056 *n = 2 + c[0].n + c[1].n;
1057}
1058
1060 double * sb_coords, double * A) {
1061
1062 double b[3] = {sb_coords[1]*sb_coords[1] * sb_coords[2]*sb_coords[2],
1063 sb_coords[0]*sb_coords[0] * sb_coords[2]*sb_coords[2],
1064 sb_coords[0]*sb_coords[0] * sb_coords[1]*sb_coords[1]};
1065 double temp = 1.0 / (b[0] + b[1] + b[2]);
1066
1067 for (size_t i = 0; i < 3; ++i) {
1068
1069 if (fabs(b[i]) < 1e-9) A[i] = 0.0;
1070 else A[i] = b[i] * temp;
1071 }
1072}
1073
1075 struct tgt_point_search_data * tgt_point_data,
1076 struct weight_vector_data * weights, size_t * n) {
1077
1078 // spherical barycentric coordinates of the target point
1079 double * sb_coords = tgt_point_data->sb_coords;
1080
1081 struct edge_interp_data * curr_edges[3] = {
1082 tgt_point_data->interp_data.triangle->edges[0],
1083 tgt_point_data->interp_data.triangle->edges[1],
1084 tgt_point_data->interp_data.triangle->edges[2]};
1085 struct vertex_interp_data * vertex_d_data[3] = {
1086 curr_edges[2]->vertex_d_data[0],
1087 curr_edges[2]->vertex_d_data[1],
1088 curr_edges[1]->vertex_d_data[1]};
1089
1090 // compute the spherical Bernstein base polynomials for the given vertices
1091 // B_ijk(p) = d!/(i!*j!*k!) * b_0(p)^i * b_1(p)^j * b_2(p)^k
1092 double B_vertex[3] =
1093 {sb_coords[0] * sb_coords[0] * sb_coords[0], // B_300
1094 sb_coords[1] * sb_coords[1] * sb_coords[1], // B_030
1095 sb_coords[2] * sb_coords[2] * sb_coords[2]}; // B_003
1096 double B_edge[3][2] =
1097 {{3.0 * sb_coords[1] * sb_coords[1] * sb_coords[2], // B_021
1098 3.0 * sb_coords[1] * sb_coords[2] * sb_coords[2]}, // B_012
1099 {3.0 * sb_coords[0] * sb_coords[0] * sb_coords[2], // B_201
1100 3.0 * sb_coords[0] * sb_coords[2] * sb_coords[2]}, // B_102
1101 {3.0 * sb_coords[0] * sb_coords[0] * sb_coords[1], // B_210
1102 3.0 * sb_coords[0] * sb_coords[1] * sb_coords[1]}}; // B_120
1103 double B_111 = 6.0 * sb_coords[0] * sb_coords[1] * sb_coords[2];
1104
1105 // f(p) = SUM(c_ijk * B_ijk) // for all (i+j+k) = 3
1106
1107 // the three vertices coefficients (300, 030, and 003)
1108 for (size_t i = 0; i < 3; ++i) {
1109 weights[i].weight = B_vertex[i];
1110 weights[i].point_id = vertex_d_data[i]->src_point;
1111 }
1112
1113 size_t n_ = 3;
1114
1115 // the six edges coefficients
1116 struct weight_vector * c_ijk[3][2] = {
1117 {&(curr_edges[0]->c[0]), // c_021
1118 &(curr_edges[0]->c[1])}, // c_012
1119 {&(curr_edges[1]->c[0]), // c_201
1120 &(curr_edges[1]->c[1])}, // c_102
1121 {&(curr_edges[2]->c[0]), // c_210
1122 &(curr_edges[2]->c[1])} // c_120
1123 };
1124 for (size_t edge_idx = 0; edge_idx < 3; ++edge_idx) {
1125 for (size_t i = 0; i < 2; ++i) {
1126 struct weight_vector_data * curr_weights = weights + n_;
1127 size_t curr_n = c_ijk[edge_idx][i]->n;
1128 n_ += curr_n;
1129 memcpy(curr_weights, c_ijk[edge_idx][i]->data,
1130 c_ijk[edge_idx][i]->n * sizeof(*curr_weights));
1131 double B = B_edge[edge_idx][i];
1132 for (size_t j = 0; j < curr_n; ++j)
1133 curr_weights[j].weight *= B;
1134 }
1135 }
1136
1137 // the middle vertex
1138 // c_111 = SUM(c_111_a[i] * A[i]) // for i = 0..2
1139 // where a is the blending function
1140 double A[3];
1141 evaluate_blending_function(sb_coords, &(A[0]));
1142
1143 struct weight_vector * c_111_a =
1144 tgt_point_data->interp_data.triangle->c_111_a;
1145 for (size_t i = 0; i < 3; ++i) {
1146 struct weight_vector_data * curr_weights = weights + n_;
1147 size_t curr_n = c_111_a[i].n;
1148 n_ += curr_n;
1149 memcpy(curr_weights, c_111_a[i].data, curr_n * sizeof(*curr_weights));
1150 double B_111_x_A_i = B_111 * A[i];
1151 for (size_t j = 0; j < curr_n; ++j)
1152 curr_weights[j].weight *= B_111_x_A_i;
1153 }
1154
1155 *n = n_;
1156}
1157
1159 struct tgt_point_search_data * tgt_point_data,
1160 struct weight_vector_data * weights, size_t * n,
1161 struct weight_vector_data_pos * compact_buffer) {
1162
1163 YAC_ASSERT(
1164 (tgt_point_data->type_flag == ON_VERTEX) ||
1165 (tgt_point_data->type_flag == ON_EDGE) ||
1166 (tgt_point_data->type_flag == ON_TRIANGLE), "invalid type_flag")
1167
1168 switch(tgt_point_data->type_flag) {
1169
1170 case (ON_VERTEX):
1171 compute_hcsbb_weights_vertex(tgt_point_data, weights, n);
1172 break;
1173 case (ON_EDGE):
1174 compute_hcsbb_weights_edge(tgt_point_data, weights, n);
1175 break;
1176 default:
1177 case (ON_TRIANGLE):
1178 compute_hcsbb_weights_triangle(tgt_point_data, weights, n);
1179 break;
1180 }
1181
1182 compact_weight_vector_data(weights, n, compact_buffer);
1183}
1184
1186 struct tgt_point_search_data * tgt_point_data, size_t num_tgt_points,
1187 struct edge_interp_data * edge_data, size_t num_edges,
1188 struct triangle_interp_data * triangle_data, size_t num_triangles,
1189 struct weight_vector_data ** weights, size_t ** num_weights_per_tgt,
1190 size_t * total_num_weights) {
1191
1192 //--------------------------------------------------------------------------
1193 // prepare patch data for the computation of the weights for each individual
1194 // target point
1195 //--------------------------------------------------------------------------
1196
1197 // compute edge coefficients
1198 compute_edge_coefficients(edge_data, num_edges);
1199
1200 // compute triangle coefficients
1201 compute_triangle_coefficients(triangle_data, num_triangles);
1202
1203 struct weight_vector_data * weight_vector_data = NULL;
1204 size_t weight_vector_data_array_size = 0;
1205 size_t total_num_weights_ = 0;
1206 size_t * num_weights_per_tgt_ =
1207 xmalloc(num_tgt_points * sizeof(*num_weights_per_tgt_));
1208 struct weight_vector_data_pos * compact_buffer =
1209 xmalloc((3 * 1 + // c_300, c_030, c_003
1210 3 * (1 + HCSBB_NUM_GAUSS_POINTS * HCSBB_GAUSS_NNN) + // c_012, c_021, c_102, ...
1212 6 * (1 + HCSBB_NUM_GAUSS_POINTS * HCSBB_GAUSS_NNN))) * // c_111_a[3]
1213 sizeof(*compact_buffer));
1214
1215 //--------------------------------------
1216 // compute weights for the target points
1217 //--------------------------------------
1218
1219 for (size_t i = 0; i < (num_tgt_points + 127) / 128; ++i) {
1220
1221 size_t curr_num_tgt_points = MIN(128, num_tgt_points - i * 128);
1222 struct tgt_point_search_data * curr_tgt_point_data =
1223 tgt_point_data + i * 128;
1224 size_t * curr_num_weights_per_tgt = num_weights_per_tgt_ + i * 128;
1225
1226 size_t curr_max_num_weights = 0;
1227 for (size_t j = 0; j < curr_num_tgt_points; ++j)
1228 curr_max_num_weights += get_max_num_weights(curr_tgt_point_data + j);
1229
1230 ENSURE_ARRAY_SIZE(weight_vector_data, weight_vector_data_array_size,
1231 total_num_weights_ + curr_max_num_weights);
1232
1233 for (size_t j = 0; j < curr_num_tgt_points; ++j) {
1235 curr_tgt_point_data + j, weight_vector_data + total_num_weights_,
1236 curr_num_weights_per_tgt + j, compact_buffer);
1237 total_num_weights_ += curr_num_weights_per_tgt[j];
1238 }
1239 }
1240
1241 free(compact_buffer);
1242
1243 *weights =
1244 xrealloc(
1245 weight_vector_data, total_num_weights_ * sizeof(*weight_vector_data));
1246 *num_weights_per_tgt = num_weights_per_tgt_;
1247 *total_num_weights = total_num_weights_;
1248}
1249
1251 const void * a, const void * b) {
1252
1253 struct tgt_point_search_data const * a_ = a;
1254 struct tgt_point_search_data const * b_ = b;
1255
1256 int ret;
1257 if ((ret = a_->is_masked - b_->is_masked)) return ret;
1258 if (a_->is_masked) return 0;
1259 if ((ret = (int)(a_->type_flag) - (int)(b_->type_flag))) return ret;
1260 for (int i = 0; i <= (int)a_->type_flag; ++i)
1261 if ((ret = (a_->src_points[i] > b_->src_points[i]) -
1262 (a_->src_points[i] < b_->src_points[i]))) return ret;
1263 return (a_->tgt_point > b_->tgt_point) - (a_->tgt_point < b_->tgt_point);
1264}
1265
1267 size_t * points, yac_const_coordinate_pointer coords,
1268 double bnd_triangle[][3]) {
1269
1270 double point_coords[HCSBB_D_NNN][3];
1271
1272 for (size_t i = 0; i < HCSBB_D_NNN; ++i)
1273 memcpy(point_coords[i], coords[points[i]], 3 * sizeof(double));
1274
1276 &(point_coords[0][0]), HCSBB_D_NNN, bnd_triangle, 16);
1277}
1278
1279static int compare_bnd_triangles(void const * a, void const * b) {
1280
1281 double const * tri_a = a, * tri_b = b;
1282 int ret = 0;
1283
1284 for (size_t i = 0; (!ret) && (i < 9); ++i) {
1285 double a_ = tri_a[i], b_ = tri_b[i];
1286 if (fabs(a_ - b_) > 1e-9) ret = (a_ > b_) - (a_ < b_);
1287 }
1288 return ret;
1289}
1290
1292 double gauss_vertices[HCSBB_NUM_GAUSS_POINTS][3],
1293 double gauss_sb_coords[HCSBB_NUM_GAUSS_POINTS][3],
1294 double bnd_triangle[3][3]) {
1295
1296#if HCSBB_GAUSS_ORDER == 3
1297 static double const abscissa[HCSBB_NUM_GAUSS_POINTS][3] = {
1298 {1.0-0.333333333333333-0.333333333333333,0.333333333333333,0.333333333333333},
1299 {1.0-0.200000000000000-0.200000000000000,0.200000000000000,0.200000000000000},
1300 {1.0-0.600000000000000-0.200000000000000,0.600000000000000,0.200000000000000},
1301 {1.0-0.200000000000000-0.600000000000000,0.200000000000000,0.600000000000000}
1302 };
1303#elif HCSBB_GAUSS_ORDER == 4
1304 static double const abscissa[HCSBB_NUM_GAUSS_POINTS][3] = {
1305 {1.0-0.091576213509771-0.091576213509771,0.091576213509771,0.091576213509771},
1306 {1.0-0.816847572980459-0.091576213509771,0.816847572980459,0.091576213509771},
1307 {1.0-0.091576213509771-0.816847572980459,0.091576213509771,0.816847572980459},
1308 {1.0-0.445948490915965-0.445948490915965,0.445948490915965,0.445948490915965},
1309 {1.0-0.108103018168070-0.445948490915965,0.108103018168070,0.445948490915965},
1310 {1.0-0.445948490915965-0.108103018168070,0.445948490915965,0.108103018168070}
1311 };
1312#elif HCSBB_GAUSS_ORDER == 5
1313 static double const abscissa[HCSBB_NUM_GAUSS_POINTS][3] = {
1314 {1.0-0.333333333333333-0.333333333333333,0.333333333333333,0.333333333333333},
1315 {1.0-0.101286507323456-0.101286507323456,0.101286507323456,0.101286507323456},
1316 {1.0-0.797426985353087-0.101286507323456,0.797426985353087,0.101286507323456},
1317 {1.0-0.101286507323456-0.797426985353087,0.101286507323456,0.797426985353087},
1318 {1.0-0.470142064105115-0.470142064105115,0.470142064105115,0.470142064105115},
1319 {1.0-0.059715871789770-0.470142064105115,0.059715871789770,0.470142064105115},
1320 {1.0-0.470142064105115-0.059715871789770,0.470142064105115,0.059715871789770}
1321 };
1322#elif HCSBB_GAUSS_ORDER == 6
1323 static double const abscissa[HCSBB_NUM_GAUSS_POINTS][3] = {
1324 {1.0-0.063089014491502-0.063089014491502,0.063089014491502,0.063089014491502},
1325 {1.0-0.873821971016996-0.063089014491502,0.873821971016996,0.063089014491502},
1326 {1.0-0.063089014491502-0.873821971016996,0.063089014491502,0.873821971016996},
1327 {1.0-0.249286745170910-0.249286745170910,0.249286745170910,0.249286745170910},
1328 {1.0-0.501426509658179-0.249286745170910,0.501426509658179,0.249286745170910},
1329 {1.0-0.249286745170910-0.501426509658179,0.249286745170910,0.501426509658179},
1330 {1.0-0.310352451033785-0.053145049844816,0.310352451033785,0.053145049844816},
1331 {1.0-0.053145049844816-0.310352451033785,0.053145049844816,0.310352451033785},
1332 {1.0-0.636502499121399-0.053145049844816,0.636502499121399,0.053145049844816},
1333 {1.0-0.053145049844816-0.636502499121399,0.053145049844816,0.636502499121399},
1334 {1.0-0.636502499121399-0.310352451033785,0.636502499121399,0.310352451033785},
1335 {1.0-0.310352451033785-0.636502499121399,0.310352451033785,0.636502499121399}
1336 };
1337#elif HCSBB_GAUSS_ORDER == 7
1338 static double const abscissa[HCSBB_NUM_GAUSS_POINTS][3] = {
1339 {1.0-0.333333333333333-0.333333333333333,0.333333333333333,0.333333333333333},
1340 {1.0-0.260345966079038-0.260345966079038,0.260345966079038,0.260345966079038},
1341 {1.0-0.479308067841923-0.260345966079038,0.479308067841923,0.260345966079038},
1342 {1.0-0.260345966079038-0.479308067841923,0.260345966079038,0.479308067841923},
1343 {1.0-0.065130102902216-0.065130102902216,0.065130102902216,0.065130102902216},
1344 {1.0-0.869739794195568-0.065130102902216,0.869739794195568,0.065130102902216},
1345 {1.0-0.065130102902216-0.869739794195568,0.065130102902216,0.869739794195568},
1346 {1.0-0.312865496004874-0.048690315425316,0.312865496004874,0.048690315425316},
1347 {1.0-0.048690315425316-0.312865496004874,0.048690315425316,0.312865496004874},
1348 {1.0-0.638444188569809-0.048690315425316,0.638444188569809,0.048690315425316},
1349 {1.0-0.048690315425316-0.638444188569809,0.048690315425316,0.638444188569809},
1350 {1.0-0.638444188569809-0.312865496004874,0.638444188569809,0.312865496004874},
1351 {1.0-0.312865496004874-0.638444188569809,0.312865496004874,0.638444188569809}
1352 };
1353#elif HCSBB_GAUSS_ORDER == 8
1354 static double const abscissa[HCSBB_NUM_GAUSS_POINTS][3] = {
1355 {1.0-0.333333333333333-0.333333333333333,0.333333333333333,0.333333333333333},
1356 {1.0-0.081414823414554-0.459292588292723,0.081414823414554,0.459292588292723},
1357 {1.0-0.459292588292723-0.081414823414554,0.459292588292723,0.081414823414554},
1358 {1.0-0.459292588292723-0.459292588292723,0.459292588292723,0.459292588292723},
1359 {1.0-0.658861384496480-0.170569307751760,0.658861384496480,0.170569307751760},
1360 {1.0-0.170569307751760-0.658861384496480,0.170569307751760,0.658861384496480},
1361 {1.0-0.170569307751760-0.170569307751760,0.170569307751760,0.170569307751760},
1362 {1.0-0.898905543365938-0.050547228317031,0.898905543365938,0.050547228317031},
1363 {1.0-0.050547228317031-0.898905543365938,0.050547228317031,0.898905543365938},
1364 {1.0-0.050547228317031-0.050547228317031,0.050547228317031,0.050547228317031},
1365 {1.0-0.008394777409958-0.263112829634638,0.008394777409958,0.263112829634638},
1366 {1.0-0.263112829634638-0.008394777409958,0.263112829634638,0.008394777409958},
1367 {1.0-0.008394777409958-0.728492392955404,0.008394777409958,0.728492392955404},
1368 {1.0-0.728492392955404-0.008394777409958,0.728492392955404,0.008394777409958},
1369 {1.0-0.263112829634638-0.728492392955404,0.263112829634638,0.728492392955404},
1370 {1.0-0.728492392955404-0.263112829634638,0.728492392955404,0.263112829634638}
1371 };
1372#else
1373 static double const abscissa[1][3];
1374#error "interpolation_method_hcsbb: the specified gauss order is currently not supported."
1375#endif
1376
1377 for (size_t i = 0; i < HCSBB_NUM_GAUSS_POINTS; ++i) {
1378
1379 gauss_vertices[i][0] = bnd_triangle[0][0] * abscissa[i][0] +
1380 bnd_triangle[1][0] * abscissa[i][1] +
1381 bnd_triangle[2][0] * abscissa[i][2];
1382 gauss_vertices[i][1] = bnd_triangle[0][1] * abscissa[i][0] +
1383 bnd_triangle[1][1] * abscissa[i][1] +
1384 bnd_triangle[2][1] * abscissa[i][2];
1385 gauss_vertices[i][2] = bnd_triangle[0][2] * abscissa[i][0] +
1386 bnd_triangle[1][2] * abscissa[i][1] +
1387 bnd_triangle[2][2] * abscissa[i][2];
1388 double scale = 1.0 / sqrt(gauss_vertices[i][0] * gauss_vertices[i][0] +
1389 gauss_vertices[i][1] * gauss_vertices[i][1] +
1390 gauss_vertices[i][2] * gauss_vertices[i][2]);
1391 gauss_vertices[i][0] *= scale;
1392 gauss_vertices[i][1] *= scale;
1393 gauss_vertices[i][2] *= scale;
1394 gauss_sb_coords[i][0] = abscissa[i][0] * scale;
1395 gauss_sb_coords[i][1] = abscissa[i][1] * scale;
1396 gauss_sb_coords[i][2] = abscissa[i][2] * scale;
1397 }
1398}
1399
1400// computes the spherical Bernstein basis polynomials
1401// for degree = 3 the polynomials B_ijk are ordered in the following order:
1402// B_003, B_012, B_021, B_030, B_102, B_111, B_120, B_201, B_210, B_300
1405 double sbb_polynomials[HCSBB_NUM_SBB_COEFFS][HCSBB_NUM_GAUSS_POINTS]) {
1406
1407#define POW_0(x) (1.0)
1408#define POW_1(x) ((x))
1409#define POW_2(x) ((x)*(x))
1410#define POW_3(x) ((x)*(x)*(x))
1411#define FAC_0 (1.0)
1412#define FAC_1 (1.0)
1413#define FAC_2 (2.0)
1414#define FAC_3 (6.0)
1415
1416 for (size_t vertex_idx = 0; vertex_idx < HCSBB_NUM_GAUSS_POINTS; ++vertex_idx)
1417 sbb_polynomials[0][vertex_idx] =
1418 (FAC_3 / (FAC_0 * FAC_0 * FAC_3)) * (POW_0(sb_coords[vertex_idx][0]) *
1419 POW_0(sb_coords[vertex_idx][1]) *
1420 POW_3(sb_coords[vertex_idx][2]));
1421 for (size_t vertex_idx = 0; vertex_idx < HCSBB_NUM_GAUSS_POINTS; ++vertex_idx)
1422 sbb_polynomials[1][vertex_idx] =
1423 (FAC_3 / (FAC_0 * FAC_1 * FAC_2)) * (POW_0(sb_coords[vertex_idx][0]) *
1424 POW_1(sb_coords[vertex_idx][1]) *
1425 POW_2(sb_coords[vertex_idx][2]));
1426 for (size_t vertex_idx = 0; vertex_idx < HCSBB_NUM_GAUSS_POINTS; ++vertex_idx)
1427 sbb_polynomials[2][vertex_idx] =
1428 (FAC_3 / (FAC_0 * FAC_2 * FAC_1)) * (POW_0(sb_coords[vertex_idx][0]) *
1429 POW_2(sb_coords[vertex_idx][1]) *
1430 POW_1(sb_coords[vertex_idx][2]));
1431 for (size_t vertex_idx = 0; vertex_idx < HCSBB_NUM_GAUSS_POINTS; ++vertex_idx)
1432 sbb_polynomials[3][vertex_idx] =
1433 (FAC_3 / (FAC_0 * FAC_3 * FAC_0)) * (POW_0(sb_coords[vertex_idx][0]) *
1434 POW_3(sb_coords[vertex_idx][1]) *
1435 POW_0(sb_coords[vertex_idx][2]));
1436 for (size_t vertex_idx = 0; vertex_idx < HCSBB_NUM_GAUSS_POINTS; ++vertex_idx)
1437 sbb_polynomials[4][vertex_idx] =
1438 (FAC_3 / (FAC_1 * FAC_0 * FAC_2)) * (POW_1(sb_coords[vertex_idx][0]) *
1439 POW_0(sb_coords[vertex_idx][1]) *
1440 POW_2(sb_coords[vertex_idx][2]));
1441 for (size_t vertex_idx = 0; vertex_idx < HCSBB_NUM_GAUSS_POINTS; ++vertex_idx)
1442 sbb_polynomials[5][vertex_idx] =
1443 (FAC_3 / (FAC_1 * FAC_1 * FAC_1)) * (POW_1(sb_coords[vertex_idx][0]) *
1444 POW_1(sb_coords[vertex_idx][1]) *
1445 POW_1(sb_coords[vertex_idx][2]));
1446 for (size_t vertex_idx = 0; vertex_idx < HCSBB_NUM_GAUSS_POINTS; ++vertex_idx)
1447 sbb_polynomials[6][vertex_idx] =
1448 (FAC_3 / (FAC_1 * FAC_2 * FAC_0)) * (POW_1(sb_coords[vertex_idx][0]) *
1449 POW_2(sb_coords[vertex_idx][1]) *
1450 POW_0(sb_coords[vertex_idx][2]));
1451 for (size_t vertex_idx = 0; vertex_idx < HCSBB_NUM_GAUSS_POINTS; ++vertex_idx)
1452 sbb_polynomials[7][vertex_idx] =
1453 (FAC_3 / (FAC_2 * FAC_0 * FAC_1)) * (POW_2(sb_coords[vertex_idx][0]) *
1454 POW_0(sb_coords[vertex_idx][1]) *
1455 POW_1(sb_coords[vertex_idx][2]));
1456 for (size_t vertex_idx = 0; vertex_idx < HCSBB_NUM_GAUSS_POINTS; ++vertex_idx)
1457 sbb_polynomials[8][vertex_idx] =
1458 (FAC_3 / (FAC_2 * FAC_1 * FAC_0)) * (POW_2(sb_coords[vertex_idx][0]) *
1459 POW_1(sb_coords[vertex_idx][1]) *
1460 POW_0(sb_coords[vertex_idx][2]));
1461 for (size_t vertex_idx = 0; vertex_idx < HCSBB_NUM_GAUSS_POINTS; ++vertex_idx)
1462 sbb_polynomials[9][vertex_idx] =
1463 (FAC_3 / (FAC_3 * FAC_0 * FAC_0)) * (POW_3(sb_coords[vertex_idx][0]) *
1464 POW_0(sb_coords[vertex_idx][1]) *
1465 POW_0(sb_coords[vertex_idx][2]));
1466
1467#undef POW_0
1468#undef POW_1
1469#undef POW_2
1470#undef POW_3
1471#undef FAC_0
1472#undef FAC_1
1473#undef FAC_2
1474#undef FAC_3
1475}
1476
1478
1479// LAPACKE_dsytrf_work and LAPACKE_dsytri might not be available (see yac_lapack_interface.h).
1480#ifdef YAC_LAPACK_NO_DSYTR
1481 lapack_int ipiv[HCSBB_NUM_SBB_COEFFS + 1] = {0};
1482 double work[HCSBB_NUM_SBB_COEFFS*HCSBB_NUM_SBB_COEFFS] = {0};
1483
1484 YAC_ASSERT(
1485 !LAPACKE_dgetrf(
1486 LAPACK_COL_MAJOR, (lapack_int) HCSBB_NUM_SBB_COEFFS,
1487 (lapack_int) HCSBB_NUM_SBB_COEFFS, &A[0][0],
1488 (lapack_int) HCSBB_NUM_SBB_COEFFS, ipiv), "internal ERROR: dgetrf")
1489
1490 YAC_ASSERT(
1491 !LAPACKE_dgetri_work(
1492 LAPACK_COL_MAJOR, (lapack_int) HCSBB_NUM_SBB_COEFFS, &A[0][0],
1493 (lapack_int) HCSBB_NUM_SBB_COEFFS, ipiv, work,
1495 "internal ERROR: dgetri")
1496#else
1497 lapack_int ipiv[HCSBB_NUM_SBB_COEFFS] = {0};
1498 double work[HCSBB_NUM_SBB_COEFFS] = {0};
1499
1500 YAC_ASSERT(
1501 !LAPACKE_dsytrf_work(
1502 LAPACK_COL_MAJOR, 'L', (lapack_int) HCSBB_NUM_SBB_COEFFS , &A[0][0],
1503 (lapack_int) HCSBB_NUM_SBB_COEFFS, ipiv, work,
1504 (lapack_int) HCSBB_NUM_SBB_COEFFS), "internal ERROR: dsytrf")
1505
1506 YAC_ASSERT(
1507 !LAPACKE_dsytri_work(
1508 LAPACK_COL_MAJOR, 'L', (lapack_int) HCSBB_NUM_SBB_COEFFS , &A[0][0],
1509 (lapack_int) HCSBB_NUM_SBB_COEFFS, ipiv, work),
1510 "internal ERROR: dsytri")
1511
1512 for (size_t i = 0; i < HCSBB_NUM_SBB_COEFFS; ++i)
1513 for (size_t j = i + 1; j < HCSBB_NUM_SBB_COEFFS; ++j)
1514 A[j][i] = A[i][j];
1515#endif
1516}
1517
1519 struct gauss_nnn_patch * gauss_nnn_patch, double (*bnd_triangle)[3],
1520 double (*gauss_vertices)[3],
1521 double gauss_sbb_polynomials[HCSBB_NUM_SBB_COEFFS][HCSBB_NUM_GAUSS_POINTS],
1523
1524 // compute bounding triangle
1525 memcpy(&(gauss_nnn_patch->bnd_triangle[0][0]), bnd_triangle,
1526 3 * sizeof(*bnd_triangle));
1527
1528 double gauss_sb_coords[HCSBB_NUM_GAUSS_POINTS][3];
1529
1530 // compute gauss points
1531 generate_gauss_legendre_points(gauss_vertices, gauss_sb_coords, bnd_triangle);
1532
1533 double (*w_g)[HCSBB_NUM_GAUSS_POINTS] =
1534 xmalloc(HCSBB_NUM_SBB_COEFFS * sizeof(w_g[0]));
1535 gauss_nnn_patch->weights = (double*)w_g;
1536
1537 // compute w_g
1538 {
1539 // compute the spherical Bernstein basis polynomials for the
1540 // gauss points (P_g)
1541 compute_sbb_polynomials_gauss_3d(gauss_sb_coords, gauss_sbb_polynomials);
1542
1543 // P_g^T * P_g
1544 // (actually this is a triangular matrix -> computing halve would be enough)
1545 for (size_t i = 0; i < HCSBB_NUM_SBB_COEFFS; ++i) {
1546 for (size_t j = 0; j < HCSBB_NUM_SBB_COEFFS; ++j) {
1547 double accu = 0;
1548 for (size_t k = 0; k < HCSBB_NUM_GAUSS_POINTS; ++k) {
1549 accu += gauss_sbb_polynomials[i][k] * gauss_sbb_polynomials[j][k];
1550 }
1551 C[i][j] = accu;
1552 }
1553 }
1554
1555 // (P_p^T * P_p)^-1
1556 inverse(C);
1557
1558 // (P_p^T * P_p)^-1 * P_p^T
1559 for (size_t i = 0; i < HCSBB_NUM_SBB_COEFFS; ++i) {
1560 for (size_t j = 0; j < HCSBB_NUM_GAUSS_POINTS; ++j) {
1561 double accu = 0;
1562 for (size_t k = 0; k < HCSBB_NUM_SBB_COEFFS; ++k) {
1563 accu += C[i][k] * gauss_sbb_polynomials[k][j];
1564 }
1565 w_g[i][j] = accu;
1566 }
1567 }
1568 }
1569}
1570
1572 struct gauss_nnn_patch * gauss_nnn_patches, size_t num_gauss_nnn_patches) {
1573
1574 for (size_t i = 0; i < num_gauss_nnn_patches; ++i) {
1575
1576 free(gauss_nnn_patches[i].src_points);
1577 free(gauss_nnn_patches[i].weights);
1578 }
1579
1580 free(gauss_nnn_patches);
1581}
1582
1583// This routine generates a triangle around each coordinate. The generated
1584// triangle contains at around HCSBB_D_NNN source points, this ensures that the
1585// size of the triangle scales with the resolution of the source grid in the
1586// area around the coordinate.
1588 size_t count, yac_coordinate_pointer coords,
1589 struct yac_interp_grid * interp_grid, size_t * num_unique_triangles_,
1590 double (**unique_bnd_triangles_)[3][3], size_t ** coord_to_triangle) {
1591
1592 // for all points at which we need to estimate the derivative, do a nearest
1593 // neighbour search
1594 size_t * nnn_search_results =
1595 xmalloc((HCSBB_D_NNN + 1) * count * sizeof(*nnn_search_results));
1597 interp_grid, coords, count, HCSBB_D_NNN, nnn_search_results, M_PI);
1598
1599 // sort the results for each search coordinate by the global ids of the
1600 // result ids (we do not actually care about the distance to the search
1601 // point (we also add a reorder index)
1602 const_yac_int_pointer src_global_ids =
1604 for (size_t i = 0, j = count - 1; i < count; ++i, --j) {
1605 // get global_ids for the current search results
1606 size_t * curr_nnn_search_results =
1607 nnn_search_results + j * HCSBB_D_NNN;
1608 yac_int nnn_search_result_global_ids[HCSBB_D_NNN];
1609 for (int k = 0; k < HCSBB_D_NNN; ++k)
1610 nnn_search_result_global_ids[k] =
1611 src_global_ids[curr_nnn_search_results[k]];
1612 // sort results of current point
1614 nnn_search_result_global_ids, HCSBB_D_NNN, curr_nnn_search_results);
1615 // make space for reorder index
1616 memmove(nnn_search_results + j * (HCSBB_D_NNN + 1),
1617 curr_nnn_search_results,
1618 HCSBB_D_NNN * sizeof(*nnn_search_results));
1619 // set reorder index
1620 nnn_search_results[j * (HCSBB_D_NNN + 1) + HCSBB_D_NNN] = j;
1621 }
1622
1623 // sort all results in order to be able to finde duplicated results
1624 qsort(nnn_search_results, count,
1625 (HCSBB_D_NNN + 1) * sizeof(*nnn_search_results),
1627
1628 size_t * coord_to_search_results =
1629 xmalloc(count * sizeof(*coord_to_search_results));
1630 size_t num_unique_search_results = 0;
1631 size_t dummy_search_results[HCSBB_D_NNN + 1];
1632 for (size_t i = 0; i < HCSBB_D_NNN + 1; ++i)
1633 dummy_search_results[i] = SIZE_MAX;
1634 for (size_t i = 0, * prev_search_result = dummy_search_results;
1635 i < count; ++i) {
1636
1637 size_t * curr_search_result = nnn_search_results + i * (HCSBB_D_NNN + 1);
1638 size_t coord_idx = curr_search_result[HCSBB_D_NNN];
1639 if (compare_HCSBB_D_NNN_size_t(prev_search_result, curr_search_result)) {
1640 prev_search_result = curr_search_result;
1641 ++num_unique_search_results;
1642 }
1643 coord_to_search_results[coord_idx] = num_unique_search_results - 1;
1644 }
1645
1646 // Remark: we have to call yac_interp_grid_get_src_field_coords after the call
1647 // to yac_interp_grid_do_nnn_search_src, because the source grid might have been
1648 // changed by the search
1649 yac_const_coordinate_pointer src_point_coords =
1651
1652 // generate bnd_triangles for all unique search results
1653 struct bnd_triangle_reorder * bnd_triangles_reorder =
1654 xmalloc(num_unique_search_results * sizeof(*bnd_triangles_reorder));
1655 for (size_t i = 0, j = 0, * prev_search_result = dummy_search_results;
1656 i < count; ++i) {
1657
1658 size_t * curr_search_result = nnn_search_results + i * (HCSBB_D_NNN + 1);
1659 if (compare_HCSBB_D_NNN_size_t(prev_search_result, curr_search_result)) {
1661 curr_search_result, src_point_coords, bnd_triangles_reorder[j].coords);
1662 bnd_triangles_reorder[j].reorder_idx = j;
1663 prev_search_result = curr_search_result;
1664 ++j;
1665 }
1666 }
1667 free(nnn_search_results);
1668
1669 // sort generated bounding triangles
1670 qsort(bnd_triangles_reorder, num_unique_search_results,
1671 sizeof(*bnd_triangles_reorder), compare_bnd_triangles);
1672
1673 // determine number of unique bnd_triangles
1674 size_t * search_result_to_bnd_triangle =
1675 xmalloc(num_unique_search_results * sizeof(*search_result_to_bnd_triangle));
1676 double (*unique_bnd_triangles)[3][3] = (double(*)[3][3])bnd_triangles_reorder;
1677 size_t num_unique_triangles = 0;
1678 double dummy_bnd_triangle[3][3] = {{-1,-1,-1},{-1,-1,-1},{-1,-1,-1}};
1679 double (*prev_bnd_triangle)[3] = dummy_bnd_triangle;
1680 for (size_t i = 0; i < num_unique_search_results; ++i) {
1681 double (*curr_bnd_triangle)[3] = bnd_triangles_reorder[i].coords;
1682 size_t reorder_idx = bnd_triangles_reorder[i].reorder_idx;
1683 if (compare_bnd_triangles(prev_bnd_triangle, curr_bnd_triangle)) {
1684 memmove(unique_bnd_triangles[num_unique_triangles], curr_bnd_triangle,
1685 sizeof(*unique_bnd_triangles));
1686 ++num_unique_triangles;
1687 prev_bnd_triangle = curr_bnd_triangle;
1688 }
1689 search_result_to_bnd_triangle[reorder_idx] = num_unique_triangles - 1;
1690 }
1691
1692 // convert coord_to_search_results to coord_to_triangle
1693 for (size_t i = 0; i < count; ++i)
1694 coord_to_search_results[i] =
1695 search_result_to_bnd_triangle[coord_to_search_results[i]];
1696 free(search_result_to_bnd_triangle);
1697
1698 *num_unique_triangles_ = num_unique_triangles;
1699 *unique_bnd_triangles_ =
1700 xrealloc(unique_bnd_triangles,
1701 num_unique_triangles * sizeof(*unique_bnd_triangles));
1702 *coord_to_triangle =
1703 xrealloc(coord_to_search_results, count * sizeof(*coord_to_search_results));
1704}
1705
1706// To estimate the derivate at a given point we first build triangle around the
1707// point. The size of this triangle scales with the source grid resolution.
1708// For each triangle we generate a number of supporting points, which are
1709// interpolated using a simple nearest neighbour approach. Using these
1710// supporting points we can interpolate the source field based on
1711// Bernstein basis polynomials. Based on these polynomials, we can generate the
1712// weights to compute derivatives of points.
1714 size_t num_vertices, struct vertex_interp_data * vertex_data,
1715 size_t num_edges, struct edge_interp_data * edge_data,
1716 struct yac_interp_grid * interp_grid, size_t * num_gauss_nnn_patches_,
1717 struct gauss_nnn_patch ** gauss_nnn_patches_) {
1718
1719 // coordinates at which we will need to estimate a derivative
1721 xmalloc((num_vertices + num_edges) * sizeof(*coords));
1722
1723 // get coordinates of all vertices and all edge middle points
1724 for (size_t i = 0; i < num_vertices; ++i)
1725 memcpy(coords[i], vertex_data[i].coordinate_xyz, sizeof(*coords));
1726 for (size_t i = 0; i < num_edges; ++i)
1727 memcpy(
1728 coords[i + num_vertices], edge_data[i].middle_d_data.coordinate_xyz,
1729 sizeof(*coords));
1730
1731 size_t num_gauss_nnn_patches;
1732 double (*bnd_triangles)[3][3];
1733 size_t * coord_to_gauss_nnn_patch;
1735 num_vertices + num_edges, coords, interp_grid,
1736 &num_gauss_nnn_patches, &bnd_triangles, &coord_to_gauss_nnn_patch);
1737 free(coords);
1738
1739 struct gauss_nnn_patch * gauss_nnn_patches =
1740 xmalloc(num_gauss_nnn_patches * sizeof(*gauss_nnn_patches));
1741 double (*gauss_points)[HCSBB_NUM_GAUSS_POINTS][3] =
1742 xmalloc(num_gauss_nnn_patches * sizeof(*gauss_points));
1743 double (*gauss_sbb_polynomials_buffer)[HCSBB_NUM_GAUSS_POINTS] =
1744 xmalloc(HCSBB_NUM_SBB_COEFFS * sizeof(*gauss_sbb_polynomials_buffer));
1745 double (*work_buffer)[HCSBB_NUM_SBB_COEFFS] =
1746 xmalloc(HCSBB_NUM_SBB_COEFFS * sizeof(*work_buffer));
1747
1748 *num_gauss_nnn_patches_ = num_gauss_nnn_patches;
1749 *gauss_nnn_patches_ = gauss_nnn_patches;
1750
1751 // initialise all gauss patches
1752 for (size_t i = 0; i < num_gauss_nnn_patches; ++i)
1754 gauss_nnn_patches + i, bnd_triangles[i],
1755 gauss_points[i], gauss_sbb_polynomials_buffer, work_buffer);
1756 free(work_buffer);
1757 free(gauss_sbb_polynomials_buffer);
1758 free(bnd_triangles);
1759
1760 for (size_t i = 0; i < num_vertices; ++i)
1761 vertex_data[i].gauss_nnn_patch =
1762 gauss_nnn_patches + coord_to_gauss_nnn_patch[i];
1763 for (size_t i = 0; i < num_edges; ++i)
1764 edge_data[i].middle_d_data.gauss_nnn_patch =
1765 gauss_nnn_patches + coord_to_gauss_nnn_patch[i + num_vertices];
1766 free(coord_to_gauss_nnn_patch);
1767
1768 // do an NNN search for all gauss integration point
1769 size_t * nnn_search_results =
1770 xmalloc(HCSBB_GAUSS_NNN * HCSBB_NUM_GAUSS_POINTS * num_gauss_nnn_patches *
1771 sizeof(*nnn_search_results));
1773 interp_grid, (yac_coordinate_pointer)&(gauss_points[0][0][0]),
1774 HCSBB_NUM_GAUSS_POINTS * num_gauss_nnn_patches,
1775 HCSBB_GAUSS_NNN, nnn_search_results, M_PI);
1776
1777 // generate the nnn weights for the interpolation of the gauss integration
1778 // points which are required for the derivative estimates
1779 double (*w_nnn_buffer)[HCSBB_NUM_GAUSS_POINTS] =
1780 xmalloc(HCSBB_GAUSS_NNN * HCSBB_NUM_GAUSS_POINTS * sizeof(*w_nnn_buffer));
1781 size_t * src_point_buffer =
1782 xmalloc(
1783 HCSBB_GAUSS_NNN * HCSBB_NUM_GAUSS_POINTS * sizeof(*src_point_buffer));
1784 yac_int * global_id_buffer =
1785 xmalloc(
1786 HCSBB_GAUSS_NNN * HCSBB_NUM_GAUSS_POINTS * sizeof(*global_id_buffer));
1787 {
1788 yac_const_coordinate_pointer src_point_coords =
1790 const_yac_int_pointer src_point_global_ids =
1792 for (size_t i = 0; i < num_gauss_nnn_patches; ++i)
1794 gauss_nnn_patches + i, gauss_points[i],
1795 nnn_search_results + i * HCSBB_NUM_GAUSS_POINTS * HCSBB_GAUSS_NNN,
1796 w_nnn_buffer, src_point_buffer, global_id_buffer, src_point_coords,
1797 src_point_global_ids);
1798 }
1799 free(nnn_search_results);
1800 free(global_id_buffer);
1801 free(src_point_buffer);
1802 free(w_nnn_buffer);
1803 free(gauss_points);
1804}
1805
1806static int check_polygon(
1807 double * check_coord, int num_vertices, size_t const * vertices,
1808 size_t vertex_start_idx, const_yac_int_pointer global_ids,
1809 yac_const_coordinate_pointer point_coords,
1810 size_t * triangle, double * sb_coords) {
1811
1812 // number of triangle the current source cell can be split into
1813 size_t num_triangles = (size_t)(num_vertices - 2);
1814 size_t triangle_indices[num_triangles][3];
1816 vertices, num_vertices, vertex_start_idx, &(triangle_indices[0]));
1817
1818 int ret = 0;
1819 for (size_t i = 0; (!ret) && (i < num_triangles); ++i) {
1820
1821 triangle[0] = triangle_indices[i][0];
1822 triangle[1] = triangle_indices[i][1];
1823 triangle[2] = triangle_indices[i][2];
1824 yac_int triangle_ids[3] =
1825 {global_ids[triangle[0]],
1826 global_ids[triangle[1]],
1827 global_ids[triangle[2]]};
1828
1829 // this is done to ensure bit-reproducibility
1830 yac_quicksort_index_yac_int_size_t(triangle_ids, 3, triangle);
1831
1832 double triangle_coords[3][3];
1833 for (int j = 0; j < 3; ++j)
1834 memcpy(
1835 triangle_coords[j], point_coords[triangle[j]], 3 * sizeof(double));
1836
1837 // check whether this is actually a triangle
1838 if ((
1839 ret =
1840 !points_are_identically(triangle_coords[0], triangle_coords[1]) &&
1841 !points_are_identically(triangle_coords[0], triangle_coords[2]) &&
1842 !points_are_identically(triangle_coords[1], triangle_coords[2]))) {
1843
1844 sb_coords[0] = check_coord[0];
1845 sb_coords[1] = check_coord[1];
1846 sb_coords[2] = check_coord[2];
1847 compute_sb_coords(sb_coords, 1, triangle_coords, "check_polygon");
1848
1849 // if the point is in the current triangle
1850 ret = (sb_coords[0] > -SB_COORD_TOL) &&
1851 (sb_coords[1] > -SB_COORD_TOL) &&
1852 (sb_coords[2] > -SB_COORD_TOL);
1853 }
1854 }
1855
1856 return ret;
1857}
1858
1860 double * tgt_coord, size_t src_cell,
1861 struct yac_const_basic_grid_data * src_grid_data,
1862 yac_const_coordinate_pointer src_point_coords,
1863 size_t * src_triangle_vertices, double * sb_coords) {
1864
1865 size_t const * src_vertices =
1866 src_grid_data->cell_to_vertex +
1867 src_grid_data->cell_to_vertex_offsets[src_cell];
1868 int num_src_vertices = src_grid_data->num_vertices_per_cell[src_cell];
1869 yac_int const * vertex_ids = src_grid_data->ids[YAC_LOC_CORNER];
1870
1871 // Find start point for triangulation of current source cell. This ensures
1872 // that the result is decomposition independent.
1873 size_t lowest_vertex_id_idx = 0;
1874 {
1875 yac_int lowest_vertex_id = vertex_ids[src_vertices[0]];
1876 for (int i = 1; i < num_src_vertices; ++i) {
1877 if (vertex_ids[src_vertices[i]] < lowest_vertex_id) {
1878 lowest_vertex_id = vertex_ids[src_vertices[i]];
1879 lowest_vertex_id_idx = i;
1880 }
1881 }
1882 }
1883
1884 return
1886 tgt_coord, num_src_vertices, src_vertices, lowest_vertex_id_idx,
1887 vertex_ids, src_point_coords, src_triangle_vertices, sb_coords);
1888}
1889
1891 double * tgt_coord, size_t src_cell,
1892 struct yac_const_basic_grid_data * src_grid_data,
1893 yac_const_coordinate_pointer src_point_coords,
1894 size_t * vertex_to_cell, size_t * vertex_to_cell_offsets,
1895 int * num_cells_per_vertex, size_t * src_triangle, double * sb_coords) {
1896
1897 size_t num_vertices = src_grid_data->num_vertices_per_cell[src_cell];
1898 size_t const * curr_vertices =
1899 src_grid_data->cell_to_vertex +
1900 src_grid_data->cell_to_vertex_offsets[src_cell];
1901 yac_int const * cell_ids = src_grid_data->ids[YAC_LOC_CELL];
1902
1903 int ret = 0;
1904
1905 // for all auxiliary grid cells
1906 for (size_t i = 0; (!ret) && (i < num_vertices); ++i) {
1907
1908 size_t curr_vertex = curr_vertices[i];
1909
1910 int curr_num_src_cells = num_cells_per_vertex[curr_vertex];
1911 if (curr_num_src_cells == 0) continue;
1912
1913 size_t * curr_src_cells =
1914 vertex_to_cell + vertex_to_cell_offsets[curr_vertex];
1915
1916 // the auxiliary grid cells are already constructed in a way that ensures
1917 // that they are decomposition independent => start index == 0
1918 ret =
1920 tgt_coord, curr_num_src_cells, curr_src_cells, 0, cell_ids,
1921 src_point_coords, src_triangle, sb_coords);
1922 }
1923
1924 return ret;
1925}
1926
1928 size_t num_tgt_points, size_t * selected_tgt, size_t * tgt_points,
1929 yac_coordinate_pointer tgt_coords, size_t * src_cells,
1930 struct yac_interp_grid * interp_grid) {
1931
1932 enum yac_location src_location =
1934
1935 struct tgt_point_search_data * tgt_point_data =
1936 xmalloc(num_tgt_points * sizeof(*tgt_point_data));
1937
1938 // if the source data is located at cells, we need to have information on the
1939 // auxiliary grid (cell points are the vertices of this grid)
1940 size_t * vertex_to_cell = NULL;
1941 size_t * vertex_to_cell_offsets = NULL;
1942 int * num_cells_per_vertex = NULL;
1943 if (src_location == YAC_LOC_CELL)
1945 interp_grid, src_cells, num_tgt_points,
1946 &vertex_to_cell, &vertex_to_cell_offsets, &num_cells_per_vertex);
1947
1948 // Remark: you have to get the pointers after the call to
1949 // yac_dist_grid_get_aux_grid_cells, because the routine might change
1950 // the underlying memory
1951 struct yac_const_basic_grid_data * src_grid_data =
1953 yac_const_coordinate_pointer src_point_coords =
1955 const_int_pointer src_mask =
1956 yac_interp_grid_get_src_field_mask(interp_grid, 0);
1957
1958 for (size_t i = 0; i < num_tgt_points; ++i, ++tgt_point_data) {
1959
1960 size_t tgt_idx = selected_tgt[i];
1961
1962 double * tgt_coord = tgt_coords[tgt_idx];
1963 tgt_point_data->tgt_point = tgt_points[tgt_idx];
1964 memcpy(
1965 tgt_point_data->coordinate_xyz, tgt_coord, 3 * sizeof(*tgt_coord));
1966
1967 // For the target point we need to find a triangle of source points connected
1968 // by great circles. The triangulation of the source cells needs to be
1969 // identical for all source cells on all processes
1970 size_t src_triangle_vertices[3];
1971 double sb_coords[3];
1972 int successfull;
1973 YAC_ASSERT(
1974 (src_location == YAC_LOC_CORNER) || (src_location == YAC_LOC_CELL),
1975 "invalid source location")
1976 if (src_location == YAC_LOC_CORNER) {
1977 successfull =
1979 tgt_coord, src_cells[i], src_grid_data, src_point_coords,
1980 src_triangle_vertices, sb_coords);
1981 } else {
1982 successfull =
1984 tgt_coord, src_cells[i], src_grid_data, src_point_coords,
1985 vertex_to_cell, vertex_to_cell_offsets, num_cells_per_vertex,
1986 src_triangle_vertices, sb_coords);
1987 }
1988
1989 if (successfull) {
1990
1991 int tmp_type_flag = -1;
1992 int is_masked = 0;
1993 for (size_t k = 0; k < 3; ++k) {
1994 if (fabs(sb_coords[k]) > SB_COORD_TOL) {
1995 tmp_type_flag++;
1996 tgt_point_data->src_points[tmp_type_flag] = src_triangle_vertices[k];
1997 tgt_point_data->sb_coords[tmp_type_flag] = sb_coords[k];
1998 // check the mask for the source vertices
1999 if (src_mask != NULL) is_masked |= !src_mask[src_triangle_vertices[k]];
2000 }
2001 }
2002 tgt_point_data->type_flag = (enum interp_type_flag)tmp_type_flag;
2003 tgt_point_data->is_masked = is_masked;
2004 } else {
2005 tgt_point_data->is_masked = 1;
2006 }
2007 }
2008 free(num_cells_per_vertex);
2009 free(vertex_to_cell_offsets);
2010 free(vertex_to_cell);
2011
2012 return tgt_point_data - num_tgt_points;
2013}
2014
2016 size_t num_vertices, size_t * vertices,
2017 struct yac_interp_grid * interp_grid) {
2018
2019 yac_const_coordinate_pointer src_point_coords =
2021
2022 struct vertex_interp_data * vertex_data =
2023 xmalloc(num_vertices * sizeof(*vertex_data));
2024
2025 for (size_t i = 0; i < num_vertices; ++i) {
2026 size_t vertex_idx = vertices[i];
2027 memcpy(vertex_data[i].coordinate_xyz,
2028 src_point_coords[vertex_idx], sizeof(*src_point_coords));
2029 vertex_data[i].src_point = vertex_idx;
2030 }
2031
2032 return vertex_data;
2033}
2034
2036 size_t num_edges, size_t (*edge_to_vertex_d_data)[2],
2037 struct vertex_interp_data * vertex_data) {
2038
2039 struct edge_interp_data * edge_data =
2040 xmalloc(num_edges * sizeof(*edge_data));
2041
2042 for (size_t i = 0; i < num_edges; ++i) {
2043
2044 // link edge to derivative data of its two vertices
2045 edge_data[i].vertex_d_data[0] = vertex_data + edge_to_vertex_d_data[i][0];
2046 edge_data[i].vertex_d_data[1] = vertex_data + edge_to_vertex_d_data[i][1];
2047
2048 double * vertex_coordinates_xyz[2] = {
2049 edge_data[i].vertex_d_data[0]->coordinate_xyz,
2050 edge_data[i].vertex_d_data[1]->coordinate_xyz};
2051
2052 // compute middle point of edge
2053 double * middle_point = edge_data[i].middle_d_data.coordinate_xyz;
2054 middle_point[0] = vertex_coordinates_xyz[0][0] +
2055 vertex_coordinates_xyz[1][0];
2056 middle_point[1] = vertex_coordinates_xyz[0][1] +
2057 vertex_coordinates_xyz[1][1];
2058 middle_point[2] = vertex_coordinates_xyz[0][2] +
2059 vertex_coordinates_xyz[1][2];
2060 double sb_coord =
2061 1.0 / sqrt(middle_point[0] * middle_point[0] +
2062 middle_point[1] * middle_point[1] +
2063 middle_point[2] * middle_point[2]);
2064 middle_point[0] *= sb_coord;
2065 middle_point[1] *= sb_coord;
2066 middle_point[2] *= sb_coord;
2067 edge_data[i].sb_coord_middle_point = sb_coord;
2068
2069 // compute vector that is orthogonal to the edge and a tangent on the
2070 // sphere in the middle point
2071 crossproduct_d(vertex_coordinates_xyz[0], vertex_coordinates_xyz[1],
2072 &(edge_data[i].g[0]));
2073 }
2074
2075 return edge_data;
2076}
2077
2079 size_t num_triangles, size_t (*triangle_to_edge_data)[3],
2080 struct edge_interp_data * edge_data) {
2081
2082 struct triangle_interp_data * triangle_data =
2083 xmalloc(num_triangles * sizeof(*triangle_data));
2084
2085 for (size_t i = 0; i < num_triangles; ++i) {
2086
2087 // link triangle to the data of its edges
2088 triangle_data[i].edges[0] = edge_data + triangle_to_edge_data[i][0];
2089 triangle_data[i].edges[1] = edge_data + triangle_to_edge_data[i][1];
2090 triangle_data[i].edges[2] = edge_data + triangle_to_edge_data[i][2];
2091 }
2092
2093 return triangle_data;
2094}
2095
2096static size_t do_search_hcsbb (struct interp_method * method,
2097 struct yac_interp_grid * interp_grid,
2098 size_t * tgt_points, size_t count,
2099 struct yac_interp_weights * weights,
2100 int * interpolation_complete) {
2101
2102 if (*interpolation_complete) return 0;
2103
2104 YAC_INSTRUMENT_START(YAC_INSTR_INTERP_SEARCH_HCSBB);
2105
2106 UNUSED(method);
2107
2108 CHECK_SRC_FIELD_COUNT_SINGLE(interp_grid)
2109
2111
2112 // get coordinates of target points
2113 yac_coordinate_pointer tgt_coords = xmalloc(count * sizeof(*tgt_coords));
2115 interp_grid, tgt_points, count, tgt_coords);
2116
2117 size_t * size_t_buffer = xmalloc(2 * count * sizeof(*size_t_buffer));
2118 size_t * src_cells = size_t_buffer;
2119 size_t * reorder_idx = size_t_buffer + count;
2120
2121 // get matching source cells for all target points
2122 // (this search assumes that all edges of the grid are great circles)
2124 interp_grid, tgt_coords, count, src_cells);
2125
2126 // sort target points, for which we found a source cell, to the beginning of
2127 // the array
2128 for (size_t i = 0; i < count; ++i) reorder_idx[i] = i;
2129 yac_quicksort_index_size_t_size_t(src_cells, count, reorder_idx);
2130
2131 // count the number of target for which a valid source cell was found
2132 size_t temp_result_count = 0;
2133 for (temp_result_count = 0; temp_result_count < count; ++temp_result_count)
2134 if (src_cells[temp_result_count] == SIZE_MAX) break;
2135
2136 // initialise search data for all target point, for which a matching source
2137 // cell was found
2138 struct tgt_point_search_data * tgt_point_data =
2140 temp_result_count, reorder_idx, tgt_points, tgt_coords, src_cells,
2141 interp_grid);
2142 free(tgt_coords);
2143
2144 // sort target point data (first by whether they are marked or not, second
2145 // by interp_type, and third by vertex indices)
2146 qsort(tgt_point_data, temp_result_count, sizeof(*tgt_point_data),
2148
2149 // move target points which cannot be interpolated to the end of the list
2150 for (size_t i = temp_result_count; i < count; ++i)
2151 reorder_idx[i] = tgt_points[reorder_idx[i]];
2152 memcpy(tgt_points + temp_result_count, reorder_idx + temp_result_count,
2153 (count - temp_result_count) * sizeof(*tgt_points));
2154 // put remaining target point to the front of the list (can also contain
2155 // failed target points)
2156 for (size_t i = 0; i < temp_result_count; ++i)
2157 tgt_points[i] = tgt_point_data[i].tgt_point;
2158 free(size_t_buffer);
2159
2160 // count the number of target points that can be interpolated
2161 size_t result_count = 0;
2162 size_t result_counts[3] = {0,0,0};
2163 for (result_count = 0; result_count < temp_result_count; ++result_count) {
2164 if (tgt_point_data[result_count].is_masked) break;
2165 else result_counts[(int)(tgt_point_data[result_count].type_flag)]++;
2166 }
2167
2168 // get all edges and triangles required for the interpolation
2169 // (each triangle requires three edges, usually each triangle edges is shared
2170 // between two triangles)
2171 size_t * unique_vertices;
2172 size_t (*unique_edge_to_unique_vertex)[2];
2173 size_t (*unique_triangle_to_unique_edge)[3];
2174 size_t num_unique_vertices, num_unique_edges, num_unique_triangles;
2176 tgt_point_data + result_counts[0], result_counts[1], result_counts[2],
2177 &unique_vertices, &num_unique_vertices,
2178 &unique_edge_to_unique_vertex, &num_unique_edges,
2179 &unique_triangle_to_unique_edge, &num_unique_triangles);
2180
2181 // initialise data for all unique vertices, edges and triangles
2182 struct vertex_interp_data * vertex_data =
2184 num_unique_vertices, unique_vertices, interp_grid);
2185 struct edge_interp_data * edge_data =
2187 num_unique_edges, unique_edge_to_unique_vertex, vertex_data);
2188 struct triangle_interp_data * triangle_data =
2190 num_unique_triangles, unique_triangle_to_unique_edge, edge_data);
2191 free(unique_vertices);
2192 free(unique_edge_to_unique_vertex);
2193 free(unique_triangle_to_unique_edge);
2194
2195 // link tgt_point_data to the edge_data and triangle_data
2196 for (size_t i = result_counts[0];
2197 i < result_counts[0] + result_counts[1]; ++i)
2198 tgt_point_data[i].interp_data.edge =
2199 edge_data + tgt_point_data[i].interp_data.idx;
2200 for (size_t i = result_counts[0] + result_counts[1];
2201 i < result_counts[0] + result_counts[1] + result_counts[2]; ++i)
2202 tgt_point_data[i].interp_data.triangle =
2203 triangle_data + tgt_point_data[i].interp_data.idx;
2204
2205 // for the interpolation we will need to estimate derivatives at all required
2206 // vertices and the middle points of all edges
2207 size_t num_gauss_nnn_patches;
2208 struct gauss_nnn_patch * gauss_nnn_patches; // have to free this later
2210 num_unique_vertices, vertex_data, num_unique_edges, edge_data, interp_grid,
2211 &num_gauss_nnn_patches, &gauss_nnn_patches);
2212
2213 // compute the actual weights
2215 size_t * num_weights_per_tgt, total_num_weights;
2216 compute_weights(tgt_point_data, result_count,
2217 edge_data, num_unique_edges,
2218 triangle_data, num_unique_triangles,
2219 &weight_vector, &num_weights_per_tgt, &total_num_weights);
2220 free(vertex_data);
2221 if (num_unique_edges > 0) free(edge_data->c[0].data);
2222 free(edge_data);
2223 for (size_t i = 0; i < num_unique_triangles; ++i)
2224 for (size_t j = 0; j < 3; ++j) free(triangle_data[i].c_111_a[j].data);
2225 free(triangle_data);
2226 free(tgt_point_data);
2227
2228 // free memory associated with the gauss_nnn_patches
2229 free_gauss_nnn_patches(gauss_nnn_patches, num_gauss_nnn_patches);
2230
2231 size_t * src_points = xmalloc(total_num_weights * sizeof(*src_points));
2232 double * weight_data = xmalloc(total_num_weights * sizeof(*weight_data));
2233 for (size_t i = 0; i < total_num_weights; ++i) {
2234 weight_data[i] = weight_vector[i].weight;
2235 src_points[i] = weight_vector[i].point_id;
2236 }
2237 free(weight_vector);
2238
2239 struct remote_point * srcs =
2241 interp_grid, 0, src_points, total_num_weights);
2242
2243 struct remote_points tgts = {
2244 .data =
2246 interp_grid, tgt_points, result_count),
2247 .count = result_count};
2248
2249 // store weights
2251 weights, &tgts, num_weights_per_tgt, srcs, weight_data);
2252
2253 free(tgts.data);
2254 free(srcs);
2255 free(weight_data);
2256 free(src_points);
2257 free(num_weights_per_tgt);
2258
2259 YAC_INSTRUMENT_STOP(YAC_INSTR_INTERP_SEARCH_HCSBB);
2260
2261 return result_count;
2262}
2263
2265
2266 struct interp_method_hcsbb * method = xmalloc(1 * sizeof(*method));
2267
2269
2270 return (struct interp_method*)method;
2271}
2272
2273static void delete_hcsbb(struct interp_method * method) {
2274 free(method);
2275}
2276
2277// --- Modular config struct and vtable for HCSBB method ---
2278
2293
2296 free(config);
2297}
2298
2300 struct yac_interp_method_config const *config) {
2302 struct yac_interp_method_config_hcsbb *copy = xmalloc(1 * sizeof(*copy));
2303 copy->base.vtable = config_hcsbb->base.vtable;
2304 copy->base.root_param_cache = NULL;
2305 return (struct yac_interp_method_config *)copy;
2306}
2307
2309 void const *a_, void const *b_) {
2310 // No parameters to compare for this method
2311 UNUSED(a_);
2312 UNUSED(b_);
2313 // No parameters to compare for this method
2314 return 0;
2315}
2316
2317// Gets interpolation method typed_config_hcsbb_get_type
2321
2323 struct yac_interp_method_config const *config) {
2324 UNUSED(config);
2326}
2327
2329 struct yac_interp_method_config const *config) {
2330 UNUSED(config);
2331 return yac_param_struct_new("bernstein_bezier", NULL, 0);
2332}
2333
2342
2344 struct yac_interp_method_config_hcsbb *config_hcsbb =
2345 xmalloc(sizeof(*config_hcsbb));
2347 config_hcsbb->base.root_param_cache = NULL;
2348 config_hcsbb->config = (struct yac_interp_method_hcsbb_config){._dummy = 0};
2349 return (struct yac_interp_method_config *)config_hcsbb;
2350}
#define YAC_ASSERT(exp, msg)
void yac_compute_bnd_triangle(double *vertices, size_t num_vertices, double triangle[][3], size_t num_tests)
#define UNUSED(x)
Definition core.h:72
int const * const_int_pointer
yac_int const * const_yac_int_pointer
#define ENSURE_ARRAY_SIZE(arrayp, curr_array_size, req_size)
void yac_triangulate_cell_indices(size_t const *corner_indices, size_t num_corners, size_t start_corner, size_t(*triangle_indices)[3])
Definition grid_cell.c:144
static int points_are_identically(double const *a, double const *b)
Definition geometry.h:727
static void crossproduct_d(const double a[], const double b[], double cross[])
Definition geometry.h:429
#define yac_angle_tol
Definition geometry.h:26
static double get_vector_angle(double const a[3], double const b[3])
Definition geometry.h:472
#define YAC_INSTRUMENT_START(ID)
Enter an instrumented region.
#define YAC_INSTRUMENT_STOP(ID)
Exit an instrumented region entered with YAC_INSTRUMENT_START(ID).
const_int_pointer yac_interp_grid_get_src_field_mask(struct yac_interp_grid *interp_grid, size_t src_field_idx)
void yac_interp_grid_get_aux_grid_src(struct yac_interp_grid *interp_grid, size_t *cells, size_t count, size_t **vertex_to_cell, size_t **vertex_to_cell_offsets, int **num_cells_per_vertex)
const_yac_int_pointer yac_interp_grid_get_src_field_global_ids(struct yac_interp_grid *interp_grid, size_t src_field_idx)
struct remote_point * yac_interp_grid_get_tgt_remote_points(struct yac_interp_grid *interp_grid, size_t *tgt_points, size_t count)
enum yac_location yac_interp_grid_get_src_field_location(struct yac_interp_grid *interp_grid, size_t src_field_idx)
struct remote_point * yac_interp_grid_get_src_remote_points(struct yac_interp_grid *interp_grid, size_t src_field_idx, size_t *src_points, size_t count)
void yac_interp_grid_do_nnn_search_src(struct yac_interp_grid *interp_grid, yac_coordinate_pointer search_coords, size_t count, size_t n, size_t *src_points, double max_search_distance)
yac_const_coordinate_pointer yac_interp_grid_get_src_field_coords(struct yac_interp_grid *interp_grid, size_t src_field_idx)
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)
void yac_interp_grid_do_points_search_gc(struct yac_interp_grid *interp_grid, yac_coordinate_pointer search_coords, size_t count, size_t *src_cells)
struct yac_const_basic_grid_data * yac_interp_grid_get_basic_grid_data_src(struct yac_interp_grid *interp_grid)
yac_interpolation_list
@ YAC_BERNSTEIN_BEZIER
Bernstein-Bezier interpolation.
#define DEF_INTERP_METHOD_CONFIG_TYPE(TYPE)
static struct triangle_interp_data * init_triangle_interp_data(size_t num_triangles, size_t(*triangle_to_edge_data)[3], struct edge_interp_data *edge_data)
static struct yac_param * config_hcsbb_get_param(struct yac_interp_method_config const *config)
static struct edge_interp_data * init_edge_interp_data(size_t num_edges, size_t(*edge_to_vertex_d_data)[2], struct vertex_interp_data *vertex_data)
static int compare_tgt_point_search_data(const void *a, const void *b)
static void compute_weights(struct tgt_point_search_data *tgt_point_data, size_t num_tgt_points, struct edge_interp_data *edge_data, size_t num_edges, struct triangle_interp_data *triangle_data, size_t num_triangles, struct weight_vector_data **weights, size_t **num_weights_per_tgt, size_t *total_num_weights)
#define FAC_0
static void compute_gauss_nnn_patch(struct gauss_nnn_patch *gauss_nnn_patch, double(*gauss_points)[3], size_t *nnn_search_results, double w_nnn[][HCSBB_NUM_GAUSS_POINTS], size_t *src_point_buffer, yac_int *global_id_buffer, yac_const_coordinate_pointer src_point_coords, const_yac_int_pointer src_point_global_ids)
static struct vertex_interp_data * init_vertex_interp_data(size_t num_vertices, size_t *vertices, struct yac_interp_grid *interp_grid)
static enum yac_interpolation_list config_hcsbb_get_type()
static int compare_HCSBB_D_NNN_size_t(const void *a, const void *b)
static int compare_size_t(const void *a, const void *b)
static int config_hcsbb_compare(void const *a_, void const *b_)
static struct yac_interp_method_config * config_hcsbb_copy(struct yac_interp_method_config const *config)
static void generate_d_data_triangle(size_t count, yac_coordinate_pointer coords, struct yac_interp_grid *interp_grid, size_t *num_unique_triangles_, double(**unique_bnd_triangles_)[3][3], size_t **coord_to_triangle)
#define HCSBB_D_NNN
static struct interp_method_vtable interp_method_hcsbb_vtable
#define HCSBB_GAUSS_NNN
static struct yac_interp_method_config_vtable yac_interp_method_config_vtable_hcsbb
#define HCSBB_NUM_SBB_COEFFS
#define HCSBB_NUM_GAUSS_POINTS
@ ON_EDGE
the target point is on an edge of the source point grid
@ ON_TRIANGLE
static void config_hcsbb_delete(struct yac_interp_method_config *config)
static void compute_triangle_coefficients(struct triangle_interp_data *triangle_data, size_t num_triangles)
#define COMPACT_WEIGHTS(edge_idx)
#define COPY_D_DATA(edge_idx)
static void compute_sb_coords(double *sb_coords, size_t num_vertices, double triangle[3][3], char const *caller)
static void generate_derivative_data(size_t num_vertices, struct vertex_interp_data *vertex_data, size_t num_edges, struct edge_interp_data *edge_data, struct yac_interp_grid *interp_grid, size_t *num_gauss_nnn_patches_, struct gauss_nnn_patch **gauss_nnn_patches_)
static void compute_hcsbb_weights_vertex(struct tgt_point_search_data *tgt_point_data, struct weight_vector_data *weights, size_t *n)
#define MULT_COEFF(edge_idx)
static void generate_bnd_triangle(size_t *points, yac_const_coordinate_pointer coords, double bnd_triangle[][3])
static size_t do_search_hcsbb(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)
static void compute_hcsbb_weights_edge(struct tgt_point_search_data *tgt_point_data, struct weight_vector_data *weights, size_t *n)
static void inverse(double A[HCSBB_NUM_SBB_COEFFS][HCSBB_NUM_SBB_COEFFS])
static void compute_hcsbb_weights(struct tgt_point_search_data *tgt_point_data, struct weight_vector_data *weights, size_t *n, struct weight_vector_data_pos *compact_buffer)
static void compact_weight_vector_data(struct weight_vector_data *weights, size_t *n, struct weight_vector_data_pos *buffer)
static void get_unique_interp_data(struct tgt_point_search_data *tgt_point_data, size_t num_edges, size_t num_triangles, size_t **unique_vertices, size_t *num_unique_vertices, size_t(**unique_edge_to_unique_vertex)[2], size_t *num_unique_edges, size_t(**unique_triangle_to_unique_edge)[3], size_t *num_unique_triangles)
#define SB_COORD_D
static void delete_hcsbb(struct interp_method *method)
static void compute_edge_coefficients(struct edge_interp_data *edge_data, size_t num_edges)
static int compare_bnd_triangles(void const *a, void const *b)
static void compute_sbb_polynomials_gauss_3d(double sb_coords[HCSBB_NUM_GAUSS_POINTS][3], double sbb_polynomials[HCSBB_NUM_SBB_COEFFS][HCSBB_NUM_GAUSS_POINTS])
#define COPY_COEFF(c_ijk, edge_idx, b_idx, bw_factor)
#define FAC_2
static int compare_2_size_t(const void *a, const void *b)
static void init_gauss_nnn_patch(struct gauss_nnn_patch *gauss_nnn_patch, double(*bnd_triangle)[3], double(*gauss_vertices)[3], double gauss_sbb_polynomials[HCSBB_NUM_SBB_COEFFS][HCSBB_NUM_GAUSS_POINTS], double C[HCSBB_NUM_SBB_COEFFS][HCSBB_NUM_SBB_COEFFS])
static int check_polygon(double *check_coord, int num_vertices, size_t const *vertices, size_t vertex_start_idx, const_yac_int_pointer global_ids, yac_const_coordinate_pointer point_coords, size_t *triangle, double *sb_coords)
static int compare_3_size_t(const void *a, const void *b)
struct interp_method * yac_interp_method_hcsbb_new()
struct yac_interp_method_config * yac_interp_method_config_default_hcsbb_new(void)
Creates an HCSBB interpolation method configuration with default parameters.
static int compare_weight_vector_data_point(void const *a, void const *b)
static void compute_hcsbb_weights_triangle(struct tgt_point_search_data *tgt_point_data, struct weight_vector_data *weights, size_t *n)
static void generate_gauss_legendre_points(double gauss_vertices[HCSBB_NUM_GAUSS_POINTS][3], double gauss_sb_coords[HCSBB_NUM_GAUSS_POINTS][3], double bnd_triangle[3][3])
#define FAC_3
static int compare_weight_vector_data_pos_pos(void const *a, void const *b)
#define POW_2(x)
#define SB_COORD_P
#define POW_1(x)
static struct interp_method * config_hcsbb_generate(struct yac_interp_method_config const *config)
static size_t get_max_num_weights(struct tgt_point_search_data *tgt_point_data)
static void evaluate_blending_function(double *sb_coords, double *A)
static int compare_weight_vector_data_pos_weight(void const *a, void const *b)
static int get_matching_aux_cell_triangle(double *tgt_coord, size_t src_cell, struct yac_const_basic_grid_data *src_grid_data, yac_const_coordinate_pointer src_point_coords, size_t *vertex_to_cell, size_t *vertex_to_cell_offsets, int *num_cells_per_vertex, size_t *src_triangle, double *sb_coords)
#define FAC_1
#define POW_0(x)
static void free_gauss_nnn_patches(struct gauss_nnn_patch *gauss_nnn_patches, size_t num_gauss_nnn_patches)
#define SB_COORD_TOL
static int get_matching_vertex_triangle(double *tgt_coord, size_t src_cell, struct yac_const_basic_grid_data *src_grid_data, yac_const_coordinate_pointer src_point_coords, size_t *src_triangle_vertices, double *sb_coords)
#define POW_3(x)
static struct tgt_point_search_data * init_tgt_point_data(size_t num_tgt_points, size_t *selected_tgt, size_t *tgt_points, yac_coordinate_pointer tgt_coords, size_t *src_cells, struct yac_interp_grid *interp_grid)
static void get_derivative_weights(struct gauss_nnn_patch *gauss_nnn_patch, double coordinate_xyz[3], double direction[3], struct weight_vector_data *weights, double mult_factor)
static void compute_d_sbb_polynomials_3d(double bnd_triangle[3][3], double direction[3], double coordinate_xyz[3], double d_sbb_polynomials[HCSBB_NUM_SBB_COEFFS])
#define CHECK_SRC_FIELD_COUNT_SINGLE(INTERP_GRID)
#define CHECK_SRC_FIELD_LOCATION_CORNER_OR_CELL(INTERP_GRID)
void yac_interp_weights_add_wsum(struct yac_interp_weights *weights, struct remote_points *tgts, size_t *num_src_per_tgt, struct remote_point *srcs, double *w)
yac_location
Definition location.h:12
@ YAC_LOC_CORNER
Definition location.h:15
@ YAC_LOC_CELL
Definition location.h:14
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 xrealloc(ptr, size)
Definition ppm_xfuncs.h:67
#define xmalloc(size)
Definition ppm_xfuncs.h:66
double coordinate_xyz[3]
point at which a derivative is to be estimated
struct edge_interp_data::@37 middle_d_data
derivative data of edge middle point
struct weight_vector c[2]
struct vertex_interp_data * vertex_d_data[2]
derivative data of both vertices
struct gauss_nnn_patch * gauss_nnn_patch
gauss integration point patch used to estimate the derivative
double bnd_triangle[3][3]
bounding triangle
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)
information (global id and location) about a point that
structure containing the information (global id and location)
struct remote_point * data
union tgt_point_search_data::@38 interp_data
enum interp_type_flag type_flag
depending on type flag interp_data contains a point to the required data
struct triangle_interp_data * triangle
struct edge_interp_data * edge
struct weight_vector c_111_a[3]
weights for alpha values used to compute c_111
struct edge_interp_data * edges[3]
edges of the triangle (edge[0] is the on opposing corner src_points[0])
size_t src_point
index of the associacted source point
double coordinate_xyz[3]
coordinate of the source point
struct gauss_nnn_patch * gauss_nnn_patch
struct weight_vector_data * weight
struct weight_vector_data * data
const_size_t_pointer cell_to_vertex_offsets
const_size_t_pointer cell_to_vertex
const const_int_pointer num_vertices_per_cell
const const_yac_int_pointer ids[3]
Concrete implementation of yac_interp_method_config for the HCSBB method.
struct yac_interp_method_config base
‍base config object, must be first entry
struct yac_interp_method_hcsbb_config config
‍method-specific configuration
void(* delete)(struct yac_interp_method_config *config)
struct yac_interp_method_config_vtable const * vtable
double * data
static struct yac_interp_method_config * config
#define MIN(a, b)
Definition toy_common.h:29
double * buffer
void yac_quicksort_index_yac_int_size_t(yac_int *a, size_t n, size_t *idx)
static void yac_remove_duplicates_size_t_3(size_t(*array)[3], size_t *n)
Definition utils_core.h:161
static void yac_remove_duplicates_size_t(size_t *array, size_t *n)
Definition utils_core.h:100
void yac_quicksort_index_size_t_size_t(size_t *a, size_t n, size_t *idx)
static void yac_remove_duplicates_size_t_2(size_t(*array)[2], size_t *n)
Definition utils_core.h:127
#define YAC_ASSERT_F(exp, format,...)
Definition yac_assert.h:39
double const (* yac_const_coordinate_pointer)[3]
Definition yac_types.h:22
YAC_INT yac_int
Definition yac_types.h:15
double(* yac_coordinate_pointer)[3]
Definition yac_types.h:21