Line data Source code
1 : /**
2 : * Sub-range of a domain edge - shared by every BC that applies to part of an edge
3 : *
4 : * A position along an x/y edge is node index based: node i of `count` sits at
5 : * t = i / (count - 1), so 0 is the low-coordinate end and 1 the high one. On the
6 : * uniform grids these BCs run on, that is also the normalized coordinate.
7 : *
8 : * Used by the velocity inlet range (bc_inlet_set_range) and by the turbulence
9 : * BC segments (turbulence_bc_add_segment), so the two agree on which nodes a
10 : * range such as [7/64, 1] covers. The CUDA inlet kernels mirror this in
11 : * inlet_node_position_gpu().
12 : *
13 : * This header is internal.
14 : */
15 :
16 : #ifndef CFD_BC_EDGE_RANGE_H
17 : #define CFD_BC_EDGE_RANGE_H
18 :
19 : #include <math.h>
20 : #include <stdbool.h>
21 : #include <stddef.h>
22 :
23 : /* Slack on the range test, so a bound placed exactly on a node (0.5 on an odd
24 : * node count) keeps that node despite the rounding in i/(n-1). */
25 : #define BC_EDGE_RANGE_EPS 1e-9
26 :
27 : /** Normalized position of node i of `count` along an edge. */
28 2097 : static inline double bc_edge_node_t(size_t i, size_t count) {
29 2097 : return (count > 1) ? (double)i / (double)(count - 1) : 0.5;
30 : }
31 :
32 : /**
33 : * Whether normalized edge position t lies in [start, end], and if so its
34 : * position rescaled to span that range, so a profile covers the range rather
35 : * than the whole edge.
36 : */
37 388 : static inline bool bc_edge_range_position(double t, double start, double end,
38 : double* position) {
39 388 : if (t < start - BC_EDGE_RANGE_EPS || t > end + BC_EDGE_RANGE_EPS) {
40 : return false;
41 : }
42 310 : double s = (t - start) / (end - start);
43 310 : *position = fmin(1.0, fmax(0.0, s));
44 310 : return true;
45 : }
46 :
47 : #endif /* CFD_BC_EDGE_RANGE_H */
|