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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338 | // *****************************************************************************
/*!
\file src/Transfer/NodeSearch.cpp
\copyright 2020-2021 Charmworks, Inc.,
2022-2025 J. Bakosi
All rights reserved. See the LICENSE file for details.
\brief Definitions pertaining to node search between 3d meshes
*/
// *****************************************************************************
#include <cmath>
#include "NodeSearch.hpp"
#include "Transfer.hpp"
#include "DerivedData.hpp"
#include "InciterConfig.hpp"
#include "NoWarning/collidecharm.h"
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wold-style-cast"
#endif
PUPbytes( Collision );
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
#include "NoWarning/transfer.decl.h"
namespace transfer {
extern CollideHandle g_collideHandle;
extern CProxy_Transfer g_transferProxy;
}
namespace inciter {
extern ctr::Config g_cfg;
}
using transfer::NodeSearch;
NodeSearch::NodeSearch( CkArrayID p, MeshData mesh, CkCallback cb )<--- Member variable 'NodeSearch::m_inpoel' is not initialized in the constructor.<--- Member variable 'NodeSearch::m_coord' is not initialized in the constructor.<--- Member variable 'NodeSearch::m_u' is not initialized in the constructor.<--- Member variable 'NodeSearch::m_flag' is not initialized in the constructor.<--- Member variable 'NodeSearch::m_trflag' is not initialized in the constructor.<--- Member variable 'NodeSearch::m_dir' is not initialized in the constructor.<--- Member variable 'NodeSearch::m_numsent' is not initialized in the constructor.<--- Member variable 'NodeSearch::m_numreceived' is not initialized in the constructor.
: m_firstchunk( mesh.firstchunk )
// *****************************************************************************
// Constructor
//! \param[in] firstchunk Chunk ID used for the collision detection library
//! \param[in] cb Callback to inform application that the library is ready
// *****************************************************************************
{
//std::cout << "NodeSearch: " << mesh.nchare << '\n';
mesh.proxy = thisProxy;
CollideRegister( g_collideHandle, /*ignored*/0 );
g_transferProxy.ckLocalBranch()->setMesh( p, mesh );
contribute( cb );
}
void
NodeSearch::setSourceTets( const std::vector< std::size_t >& inpoel,
const std::array< std::vector< double >, 3 >& coord,
const tk::Fields& u,
const std::vector< double >& flag,
bool dir,
CkCallback cb )
// *****************************************************************************
// Set the data for the source tetrahedrons to be collided
//! \param[in] inpoel Pointer to the connectivity data for the source mesh
//! \param[in] coord Pointer to the coordinate data for the source mesh
//! \param[in] u Pointer to the solution data for the source mesh
//! \param[in] flag Transfer flags
//! \param[in] dir Transfer direction: 0: bg to overset, 1: overset to bg
//! \param[in] cb Callback to call when src side of transfer is done
// *****************************************************************************
{
m_inpoel = const_cast< std::vector< std::size_t >* >( &inpoel );
m_coord = const_cast< std::array< std::vector< double >, 3 >* >( &coord );
m_u = const_cast< tk::Fields* >( &u );
m_flag = const_cast< std::vector< double >* >( &flag );
m_dir = dir;
m_done = cb;
m_srcnotified = 0;
// Send tetrahedron data to the collision detection library
collideTets();
}
void
NodeSearch::setDestPoints( const std::array< std::vector< double >, 3 >& coord,
tk::Fields& u,
std::vector< double >& flag,
bool trflag,
bool dir,
CkCallback cb )
// *****************************************************************************
// Set the data for the destination points to be collided
//! \param[in] coord Pointer to the coordinate data for the destination mesh
//! \param[in,out] u Pointer to the solution data for the destination mesh
//! \param[in,out] flag Transfer flags
//! \param[in] trflag Transfer flags if true
//! \param[in] dir Transfer direction: 0: bg to overset, 1: overset to bg
//! \param[in] cb Callback to call when dst side of transfer is done
// *****************************************************************************
{
m_coord = const_cast< std::array< std::vector< double >, 3 >* >( &coord );
m_u = static_cast< tk::Fields* >( &u );
m_flag = const_cast< std::vector< double >* >( &flag );
m_trflag = trflag;
m_dir = dir;
m_done = cb;
// Initialize msg counters, callback, and background solution data
m_numsent = 0;
m_numreceived = 0;
//background();
// Send vertex data to the collision detection library
collideVertices();
}
void
NodeSearch::background()<--- The function 'background' is never used.
// *****************************************************************************
// Initialize dest mesh solution with background data
//! \details This is useful to see what points did not receive solution.
// *****************************************************************************
{
tk::Fields& u = *m_u;
for (std::size_t i = 0; i < u.nunk(); ++i) u(i,0) = -1.0;
}
void
NodeSearch::collideVertices()
// *****************************************************************************
// Pass vertex information to the collision detection library
// *****************************************************************************
{
const std::array< std::vector< double >, 3 >& coord = *m_coord;
auto nVertices = coord[0].size();
std::size_t nBoxes = 0;
std::vector< bbox3d > boxes( nVertices );
std::vector< int > prio( nVertices );
auto firstchunk = static_cast< int >( m_firstchunk );
for (std::size_t i=0; i<nVertices; ++i) {
boxes[nBoxes].empty();
boxes[nBoxes].add(CkVector3d(coord[0][i], coord[1][i], coord[2][i]));
prio[nBoxes] = firstchunk;
++nBoxes;
}
CollideBoxesPrio( g_collideHandle, firstchunk + thisIndex,
static_cast<int>(nBoxes), boxes.data(), prio.data() );
}
void
NodeSearch::collideTets() const
// *****************************************************************************
// Pass tet information to the collision detection library
// *****************************************************************************
{
const std::vector< std::size_t >& inpoel = *m_inpoel;
const std::array< std::vector< double >, 3 >& coord = *m_coord;
auto nBoxes = inpoel.size() / 4;
std::vector< bbox3d > boxes( nBoxes );
std::vector< int > prio( nBoxes );
auto firstchunk = static_cast< int >( m_firstchunk );
for (std::size_t i=0; i<nBoxes; ++i) {
boxes[i].empty();
prio[i] = firstchunk;
for (std::size_t j=0; j<4; ++j) {
// Get index of the jth point of the ith tet
auto p = inpoel[i*4+j];
// Add that point to the tets bounding box
boxes[i].add( CkVector3d( coord[0][p], coord[1][p], coord[2][p] ) );
}
}
CollideBoxesPrio( g_collideHandle, firstchunk + thisIndex,
static_cast<int>(nBoxes), boxes.data(), prio.data() );
}
void
NodeSearch::processCollisions( const MeshData& src,
int nColl,
Collision* colls )
// *****************************************************************************
// Process potential collisions by sending my points to the source mesh chares
// that they potentially collide with.
//! \param[in] src Source mesh config data
//! \param[in] nColl Number of potential collisions to process
//! \param[in] colls List of potential collisions
// *****************************************************************************
{
const std::array< std::vector< double >, 3 >& coord = *m_coord;
int mychunk = m_firstchunk + thisIndex;
std::vector< std::vector< PotentialCollision > >
pColls( static_cast<std::size_t>(src.nchare) );
// Separate potential collisions into lists based on the source mesh chare
// that is involved in the potential collision
for (int i=0; i<nColl; ++i) {
int chareindex;
PotentialCollision pColl;
if (colls[i].A.chunk == mychunk) {
chareindex = colls[i].B.chunk - src.firstchunk;
pColl.dst = static_cast<std::size_t>(colls[i].A.number);
pColl.src = static_cast<std::size_t>(colls[i].B.number);
} else {
chareindex = colls[i].A.chunk - src.firstchunk;
pColl.dst = static_cast<std::size_t>(colls[i].B.number);
pColl.src = static_cast<std::size_t>(colls[i].A.number);
}
#if defined(STRICT_GNUC)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-copy"
#endif
auto dst = pColl.dst;
pColl.point = { coord[0][dst], coord[1][dst], coord[2][dst] };
#if defined(STRICT_GNUC)
#pragma GCC diagnostic pop
#endif
pColls[ static_cast<std::size_t>(chareindex) ].push_back( pColl );
}
// Send out the lists of potential collisions to the source mesh chares
for (int i=0; i<src.nchare; ++i) {
auto I = static_cast< std::size_t >( i );
m_numsent++;
src.proxy[i].determineActualCollisions( thisProxy, thisIndex,
static_cast<int>(pColls[I].size()), pColls[I].data() );
}
}
void
NodeSearch::determineActualCollisions( CProxy_NodeSearch proxy,
int index,
int nColls,
PotentialCollision* colls )
// *****************************************************************************
// Identify actual collisions by calling intet on all possible collisions, and
// interpolate solution values to send back to the destination mesh.
//! \param[in] proxy The proxy of the destination mesh chare array
//! \param[in] index The index in proxy to return the solution data to
//! \param[in] nColls Number of collisions to be checked
//! \param[in] colls List of potential collisions
// *****************************************************************************
{
const std::vector< std::size_t >& inpoel = *m_inpoel;
const tk::Fields& u = *m_u;
const std::vector< double >& f = *m_flag;
//CkPrintf( "Source chare %i received data for %i potential collisions\n",
// thisIndex, nColls);
// Slightly shift dest mesh if symmetry is specified
auto eps = std::numeric_limits< tk::real >::epsilon();
const auto& sym = inciter::g_cfg.get< tag::overset, tag::sym_ >()[ 1 ];
std::array< double, 3 > shift{ 0.0, 0.0, sym=="z" ? eps : 0.0 };
// Iterate over my potential collisions and call intet() to determine
// if an actual collision occurred, and if so interpolate solution to dest
int numInTet = 0;
std::vector< SolutionData > exp;
for (int i=0; i<nColls; ++i) {
const auto& p = colls[i].point;
std::vector< double > point{ p.x, p.y, p.z };
std::array< double, 4 > N;
if (tk::intet( *m_coord, *m_inpoel, point, colls[i].src, N, shift )) {
++numInTet;
SolutionData data;
data.dst = colls[i].dst;
auto e = colls[i].src;
const auto A = inpoel[e*4+0];
const auto B = inpoel[e*4+1];
const auto C = inpoel[e*4+2];
const auto D = inpoel[e*4+3];
data.sol.resize( u.nprop() + 1 );
for (std::size_t c=0; c<u.nprop(); ++c) {
data.sol[c] = N[0]*u(A,c) + N[1]*u(B,c) + N[2]*u(C,c) + N[3]*u(D,c);
}
data.sol.back() = N[0]*f[A] + N[1]*f[B] + N[2]*f[C] + N[3]*f[D];
exp.push_back( data );
}
}
//if (numInTet) {
// CkPrintf( "Source chare %i found %i/%i actual collisions\n",
// thisIndex, numInTet, nColls );
//}
// Send the solution data for the actual collisions back to the dest mesh
proxy[index].transferSolution( exp );
if (not m_srcnotified) {
m_done.send();
m_srcnotified = 1;
}
}
void
NodeSearch::transferSolution( const std::vector< SolutionData >& data )
// *****************************************************************************
// Transfer the interpolated solution data to destination mesh
//! \param[in] data List of solutions at nodes (multiple scalars transferred)
// *****************************************************************************
{
tk::Fields& u = *m_u;
std::vector< double >& f = *m_flag;
//auto eps = std::numeric_limits< tk::real >::epsilon();
for (std::size_t i=0; i<data.size(); ++i) {
const auto& d = data[i];
if (m_trflag) { // transfer flags only
if (m_dir) f[d.dst] = d.sol.back(); // overset to background only
}
else { // transfer solution only
if (m_dir) { // overset to background
if (f[d.dst] > 0.5) {
for (std::size_t c=0; c<u.nprop(); ++c) u(d.dst,c) = d.sol[c];
}
}
else { // background to overset
if (f[d.dst] > -0.5 and f[d.dst] < 0.5) {
for (std::size_t c=0; c<u.nprop(); ++c) u(d.dst,c) = d.sol[c];
}
}
}
}
// Inform the caller if we've received all solution data
m_numreceived++;
if (m_numreceived == m_numsent) {
m_done.send();
}
}
#include "NoWarning/nodesearch.def.h"
|