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