forked from dengwirda/jigsaw
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhfn_init.hpp
266 lines (228 loc) · 7.87 KB
/
hfn_init.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/*
--------------------------------------------------------
* HFN-INIT: init HFUN data via GEOM/CFG., etc.
--------------------------------------------------------
*
* This program may be freely redistributed under the
* condition that the copyright notices (including this
* entire header) are not removed, and no compensation
* is received through use of the software. Private,
* research, and institutional use is free. You may
* distribute modified versions of this code UNDER THE
* CONDITION THAT THIS CODE AND ANY MODIFICATIONS MADE
* TO IT IN THE SAME FILE REMAIN UNDER COPYRIGHT OF THE
* ORIGINAL AUTHOR, BOTH SOURCE AND OBJECT CODE ARE
* MADE FREELY AVAILABLE WITHOUT CHARGE, AND CLEAR
* NOTICE IS GIVEN OF THE MODIFICATIONS. Distribution
* of this code as part of a commercial system is
* permissible ONLY BY DIRECT ARRANGEMENT WITH THE
* AUTHOR. (If you are not directly supplying this
* code to a customer, and you are instead telling them
* how they can obtain it for free, then you are not
* required to make any arrangement with me.)
*
* Disclaimer: Neither I nor: Columbia University, The
* Massachusetts Institute of Technology, The
* University of Sydney, nor The National Aeronautics
* and Space Administration warrant this code in any
* way whatsoever. This code is provided "as-is" to be
* used at your own risk.
*
--------------------------------------------------------
*
* Last updated: 14 September, 2017
*
* Copyright 2013-2017
* Darren Engwirda
* https://github.com/dengwirda/
*
--------------------------------------------------------
*/
# pragma once
# ifndef __HFN_INIT__
# define __HFN_INIT__
/*
--------------------------------------------------------
* INIT-HFUN: default HFUN data via BBOX.
--------------------------------------------------------
*/
template <
typename jlog_data
>
__normal_call iptr_type init_hfun (
jcfg_data &_jcfg,
jlog_data &_jlog,
geom_data &_geom,
hfun_data &_hfun
)
{
iptr_type _errv = __no_error ;
__unreferenced(_jlog) ;
/*--------------------------------- find GEOM scaling */
real_type _scal = (real_type) +1. ;
if (_jcfg._hfun_scal ==
jcfg_data::hfun_scal::relative)
{
if (_geom._ndim == +2 &&
_geom._kind ==
jmsh_kind::euclidean_mesh)
{
/*--------------------------------- euclidean-mesh-2d */
_scal = (real_type) +0. ;
_scal +=
_geom._euclidean_mesh_2d._bmax[0] -
_geom._euclidean_mesh_2d._bmin[0] ;
_scal +=
_geom._euclidean_mesh_2d._bmax[1] -
_geom._euclidean_mesh_2d._bmin[1] ;
_scal /= (real_type) +2. ;
}
else
if (_geom._ndim == +3 &&
_geom._kind ==
jmsh_kind::euclidean_mesh)
{
/*--------------------------------- euclidean-mesh-3d */
_scal = (real_type) +0. ;
_scal +=
_geom._euclidean_mesh_3d._bmax[0] -
_geom._euclidean_mesh_3d._bmin[0] ;
_scal +=
_geom._euclidean_mesh_3d._bmax[1] -
_geom._euclidean_mesh_3d._bmin[1] ;
_scal +=
_geom._euclidean_mesh_3d._bmax[2] -
_geom._euclidean_mesh_3d._bmin[2] ;
_scal /= (real_type) +3. ;
}
else
if (_geom._kind ==
jmsh_kind::ellipsoid_mesh)
{
/*--------------------------------- euclidean-mesh-3d */
_scal = (real_type) +0. ;
_scal +=
_geom._ellipsoid_mesh_3d._bmax[0] -
_geom._ellipsoid_mesh_3d._bmin[0] ;
_scal +=
_geom._ellipsoid_mesh_3d._bmax[1] -
_geom._ellipsoid_mesh_3d._bmin[1] ;
_scal +=
_geom._ellipsoid_mesh_3d._bmax[2] -
_geom._ellipsoid_mesh_3d._bmin[2] ;
_scal /= (real_type) +3. ;
}
}
/*--------------------------------- push GEOM scaling */
if (_hfun._ndim == +0)
{
/*--------------------------------- constant-value-kd */
_hfun._constant_value_kd.
_hval = _scal*_jcfg._hfun_hmax ;
}
else
if (_hfun._ndim == +2)
{
if (_hfun._kind ==
jmsh_kind::euclidean_mesh)
{
/*--------------------------------- euclidean-mesh-2d */
for (auto _node = _hfun.
_euclidean_mesh_2d._mesh._set1.head();
_node != _hfun.
_euclidean_mesh_2d._mesh._set1.tend();
++_node )
{
if (_node->mark() < 0) continue;
_node->hval() =
_scal * _node->hval();
_node->hval() =
std::min(_node->hval(),
_scal *_jcfg._hfun_hmax) ;
_node->hval() =
std::max(_node->hval(),
_scal *_jcfg._hfun_hmin) ;
}
}
if (_hfun._kind ==
jmsh_kind::euclidean_grid)
{
/*--------------------------------- euclidean-grid-2d */
for (auto _iter = _hfun.
_euclidean_grid_2d._hmat.head();
_iter != _hfun.
_euclidean_grid_2d._hmat.tend();
++_iter )
{
*_iter = _scal * *_iter;
*_iter = std::min(*_iter,
_scal *_jcfg._hfun_hmax) ;
*_iter = std::max(*_iter,
_scal *_jcfg._hfun_hmin) ;
}
}
}
else
if (_hfun._ndim == +3)
{
if (_hfun._kind ==
jmsh_kind::euclidean_mesh)
{
/*--------------------------------- euclidean-mesh-3d */
for (auto _node = _hfun.
_euclidean_mesh_3d._mesh._set1.head();
_node != _hfun.
_euclidean_mesh_3d._mesh._set1.tend();
++_node )
{
if (_node->mark() < 0) continue;
_node->hval() =
_scal * _node->hval();
_node->hval() =
std::min(_node->hval(),
_scal *_jcfg._hfun_hmax) ;
_node->hval() =
std::max(_node->hval(),
_scal *_jcfg._hfun_hmin) ;
}
}
if (_hfun._kind ==
jmsh_kind::euclidean_grid)
{
/*--------------------------------- euclidean-grid-3d */
for (auto _iter = _hfun.
_euclidean_grid_3d._hmat.head();
_iter != _hfun.
_euclidean_grid_3d._hmat.tend();
++_iter )
{
*_iter = _scal * *_iter;
*_iter = std::min(*_iter,
_scal *_jcfg._hfun_hmax) ;
*_iter = std::max(*_iter,
_scal *_jcfg._hfun_hmin) ;
}
}
}
else
if (_hfun._kind ==
jmsh_kind::ellipsoid_grid)
{
/*--------------------------------- ellipsoid-grid-3d */
for (auto _iter = _hfun.
_ellipsoid_grid_3d._hmat.head();
_iter != _hfun.
_ellipsoid_grid_3d._hmat.tend();
++_iter )
{
*_iter = _scal * *_iter;
*_iter = std::min(*_iter,
_scal *_jcfg._hfun_hmax) ;
*_iter = std::max(*_iter,
_scal *_jcfg._hfun_hmin) ;
}
}
return ( _errv ) ;
}
# endif //__HFN_INIT__