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 | // *****************************************************************************
/*!
\file src/Transfer/Transfer.cpp
\copyright 2020-2021 Charmworks, Inc.,
2022-2025 J. Bakosi
All rights reserved. See the LICENSE file for details.
\brief Definitions pertaining to transfer between 3D meshes
*/
// *****************************************************************************
#include <cassert><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <iostream> // NOT NEEDED<--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include "Transfer.hpp"
#include "NodeSearch.hpp"
#include "ContainerUtil.hpp"
namespace transfer {
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-variable-declarations"
#endif
CProxy_Transfer g_transferProxy;
CollideHandle g_collideHandle;
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
static void
collisionHandler( [[maybe_unused]] void *param, int nColl, Collision *colls )
// *****************************************************************************
//! ...
// *****************************************************************************
{
g_transferProxy.ckLocalBranch()->distributeCollisions( nColl, colls );
}
LibTransfer::LibTransfer( CkArgMsg* msg )
// *****************************************************************************
// Constructor: initialize mesh-to-mesh transfer
// *****************************************************************************
{
delete msg;
g_transferProxy = CProxy_Transfer::ckNew();
// Need to make sure this is actually correct
CollideGrid3d gridMap( CkVector3d(0, 0, 0), CkVector3d(2, 100, 2) );
g_collideHandle = CollideCreate( gridMap,
CollideSerialClient( collisionHandler, nullptr ) );
}
void
addMesh( CkArrayID p, int nchare, CkCallback cb )
// *****************************************************************************
// API for registering a mesh to be part of mesh-to-mesh transfer
//! \param[in] p Charm++ host proxy participating in mesh-to-mesh transfer
//! \param[in] nchare Number of mesh partitions
//! \param[in] cb Callback to continue with once finished
// *****************************************************************************
{
g_transferProxy[0].addMesh( p, nchare, cb );
}
void
setSourceTets( CkArrayID p,
int chare,
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 )
// *****************************************************************************
// API for configuring source mesh
//! \param[in] inpoel Source mesh connectivity
//! \param[in] coord Source mesh node coordinates
//! \param[in] u Source solution data
//! \param[in] flag Transfer flags
//! \param[in] dir Transfer direction: 0: bg to overset, 1: overset to bg
//! \param[in] cb Callback to continue with once finished
// *****************************************************************************
{
g_transferProxy.ckLocalBranch()->
setSourceTets( p, chare, inpoel, coord, u, flag, dir, cb );
}
void setDestPoints( CkArrayID p,
int chare,
const std::array< std::vector< double >, 3 >& coord,
tk::Fields& u,
std::vector< double >& flag,
bool trflag,
bool dir,
CkCallback cb )
// *****************************************************************************
// API for configuring destination mesh
//! \param[in] coord Destination mesh node coordinates
//! \param[in,out] u Destination mesh solution data
//! \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 continue with once finished
// *****************************************************************************
{
g_transferProxy.ckLocalBranch()->
setDestPoints( p, chare, coord, u, flag, trflag, dir, cb );
}
void
Transfer::addMesh( CkArrayID p, int nchare, CkCallback cb )
// *****************************************************************************
// Register a mesh to be part of mesh-to-mesh transfer
//! \param[in] p Charm++ host proxy participating in mesh-to-mesh transfer
//! \param[in] nchare Number of mesh partitions
//! \param[in] cb Callback to continue with once finished
// *****************************************************************************
{
auto id = static_cast<std::size_t>(CkGroupID(p).idx);
//std::cout << "addMesh: " << nchare << ", id:" << id << '\n';
assert( m_proxyMap.count(id) == 0 );
CkArrayOptions opts;
opts.bindTo( p );
opts.setNumInitial( nchare );
MeshData mesh;
mesh.nchare = nchare;
mesh.firstchunk = m_current_chunk;
mesh.proxy = CProxy_NodeSearch::ckNew( p, mesh, cb, opts );
m_proxyMap[ id ] = mesh;
m_current_chunk += nchare;
}
void
Transfer::setMesh( CkArrayID p, const MeshData& mesh )
// *****************************************************************************
//! \param[in] p Charm++ host proxy participating in mesh-to-mesh transfer
// *****************************************************************************
{
m_proxyMap[static_cast<std::size_t>(CkGroupID(p).idx)] = mesh;
//std::cout << "setMesh: pe:" << CkMyPe() << ": "; for (const auto& [i,m] : m_proxyMap) std::cout << " groupid:" << i << " firstchunk:" << m.firstchunk << " nchare:" << m.nchare << ' '; std::cout << '\n';
}
void
Transfer::setSourceTets( CkArrayID p,
int chare,
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 )
// *****************************************************************************
// Configure source mesh
//! \param[in] inpoel Source mesh connectivity
//! \param[in] coord Source mesh node coordinates
//! \param[in] u Source solution data
//! \param[in] flag Transfer flags
//! \param[in] dir Transfer direction: 0: bg to overset, 1: overset to bg
//! \param[in] cb Callback to continue with once finished
// *****************************************************************************
{
m_src = static_cast< std::size_t >( CkGroupID(p).idx );
assert( m_proxyMap.count(m_src) );
NodeSearch* w = tk::cref_find( m_proxyMap, m_src ).proxy[ chare ].ckLocal();
assert( w );
w->setSourceTets( inpoel, coord, u, flag, dir, cb );
}
void
Transfer::setDestPoints( CkArrayID p,
int chare,
const std::array< std::vector< double >, 3 >& coord,
tk::Fields& u,
std::vector< double >& flag,
bool trflag,
bool dir,
CkCallback cb )
// *****************************************************************************
// Configure destination mesh
//! \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 continue with once finished
// *****************************************************************************
{
m_dst = static_cast< std::size_t >( CkGroupID(p).idx );
assert( m_proxyMap.count(m_dst) );
NodeSearch* w = tk::cref_find( m_proxyMap, m_dst ).proxy[ chare ].ckLocal();
assert( w );
w->setDestPoints( coord, u, flag, trflag, dir, cb );
}
void
Transfer::distributeCollisions( int nColl, Collision* colls )
// *****************************************************************************
// Called when all potential collisions have been found, and now need to be
// distributed to the chares in the destination mesh to determine actual
// collisions.
//! \param[in] nColl Number of potential collisions found
//! \param[in] colls The list of potential collisions
// *****************************************************************************
{
//CkPrintf("Collisions found: %i\n", nColl);
const auto& dst = tk::cref_find( m_proxyMap, m_dst );
auto first = static_cast< std::size_t >( dst.firstchunk );
auto nchare = static_cast< std::size_t >( dst.nchare );
std::vector< std::vector< Collision > > separated( nchare );
// Separate collisions based on the destination mesh chare they belong to
for (std::size_t i=0; i<static_cast<std::size_t>(nColl); ++i) {
auto achunk = static_cast< std::size_t >( colls[i].A.chunk );
auto bchunk = static_cast< std::size_t >( colls[i].B.chunk );
if (achunk >= first && achunk < first + nchare) {
separated[ achunk - first ].push_back(colls[i]);
} else {
separated[ bchunk - first ].push_back(colls[i]);
}
}
// Send out each list to the destination chares for further processing
for (std::size_t i=0; i<nchare; ++i) {
//CkPrintf("Dest mesh chunk %i has %lu\n", i, separated[i].size());
const auto& src = tk::cref_find( m_proxyMap, m_src );
dst.proxy[ static_cast<int>(i) ].processCollisions( src,
static_cast< int >( separated[ i ].size() ),
separated[ i ].data() );
}
}
} // transfer::
#include "NoWarning/transfer.def.h"<--- Include file: "NoWarning/transfer.def.h" not found.
|