7#ifndef LBMBCOLLECTOR_H_
8#define LBMBCOLLECTOR_H_
27#ifdef MAIA_EXTRA_DEBUG
28#define LBCOLLECTOR_SANITY_CHECKS_ACCESSORS
32#if defined(LBCOLLECTOR_SANITY_CHECKS_ACCESSORS) || defined(MAIA_ASSERT_ACCESSORS)
33#define ENSURE_VALID_ID_ACCESSOR(id) \
35 MAIA_CONTAINER_ENSURE_VALID_ID(id); \
37#define ENSURE_VALID_VARIABLE_ID_ACCESSOR(id) \
39 MAIA_CONTAINER_ENSURE( \
40 id >= 0 && id < noVariables(), \
41 "variable id = " + std::to_string(id) + " is out-of-bounds [0, " + std::to_string(noVariables()) + ")", AT_); \
43#define ENSURE_VALID_DISTANCE_ID_ACCESSOR(id) \
45 MAIA_CONTAINER_ENSURE( \
46 id >= 0 && id < noDistances(), \
47 "distance id = " + std::to_string(id) + " is out-of-bounds [0, " + std::to_string(noDistances()), AT_); \
49#define ENSURE_VALID_DIM_ID_ACCESSOR(dim) \
51 MAIA_CONTAINER_ENSURE(dim >= 0 && dim < nDim, \
52 "dim = " + std::to_string(dim) + " is out-of-bounds [0, " + std::to_string(nDim) + ")", \
55#define ENSURE_VALID_PROPERTY_ACCESSOR(p) \
57 MAIA_CONTAINER_ENSURE(p != LbCell::NumProperties, "Invalid property", AT_); \
61#define ENSURE_VALID_ID_ACCESSOR(id) \
64#define ENSURE_VALID_VARIABLE_ID_ACCESSOR(id) \
67#define ENSURE_VALID_DISTANCE_ID_ACCESSOR(id) \
70#define ENSURE_VALID_DIM_ID_ACCESSOR(id) \
73#define ENSURE_VALID_PROPERTY_ACCESSOR(dir) \
153 template <
class Functor,
class T>
173 resetStorage(1, m_cellId);
174 resetStorage(noDistances(), m_distances);
175 resetStorage(nDim, m_velocities);
176 resetStorage(nDim * noDistances(), m_forces);
177 resetStorage(nDim * noDistances(), m_surfaceCenters);
178 resetStorage(nDim, m_cellCenters);
179 resetStorage(nDim, m_normal);
180 resetStorage(1, m_density);
189#ifdef LBMBCOLLECTOR_SOA_MEMORY_LAYOUT
190#error Missing implementation for structure-of-arrays memory layout.
192 ENSURE_VALID_ID_ACCESSOR(
id);
199#ifdef LBMBCOLLECTOR_SOA_MEMORY_LAYOUT
200#error Missing implementation for structure-of-arrays memory layout.
202 ENSURE_VALID_ID_ACCESSOR(
id);
210#ifdef LBMBCOLLECTOR_SOA_MEMORY_LAYOUT
211#error Missing implementation for structure-of-arrays memory layout.
213 ENSURE_VALID_ID_ACCESSOR(
id);
214 ENSURE_VALID_DISTANCE_ID_ACCESSOR(did);
215 return m_distances[
id * noDistances() + did];
221#ifdef LBMBCOLLECTOR_SOA_MEMORY_LAYOUT
222#error Missing implementation for structure-of-arrays memory layout.
224 ENSURE_VALID_ID_ACCESSOR(
id);
225 ENSURE_VALID_DISTANCE_ID_ACCESSOR(did);
226 return m_distances[
id * noDistances() + did];
233#ifdef LBMBCOLLECTOR_SOA_MEMORY_LAYOUT
234#error Missing implementation for structure-of-arrays memory layout.
236 ENSURE_VALID_ID_ACCESSOR(
id);
237 ENSURE_VALID_DIM_ID_ACCESSOR(dim);
238 return m_velocities[
id * nDim + dim];
244#ifdef LBMBCOLLECTOR_SOA_MEMORY_LAYOUT
245#error Missing implementation for structure-of-arrays memory layout.
247 ENSURE_VALID_ID_ACCESSOR(
id);
248 ENSURE_VALID_DIM_ID_ACCESSOR(dim);
249 return m_velocities[
id * nDim + dim];
255#ifdef LBMBCOLLECTOR_SOA_MEMORY_LAYOUT
256#error Missing implementation for structure-of-arrays memory layout.
258 ENSURE_VALID_ID_ACCESSOR(
id);
259 for(
MInt n = 0; n < nDim; n++) {
260 m_velocities[
id * nDim + n] = velocity[n];
267#ifdef LBMBCOLLECTOR_SOA_MEMORY_LAYOUT
268#error Missing implementation for structure-of-arrays memory layout.
270 ENSURE_VALID_ID_ACCESSOR(
id);
271 for(
MInt n = 0; n < nDim; n++) {
272 m_velocities[
id * nDim + n] += velocity[n];
280#ifdef LBMBCOLLECTOR_SOA_MEMORY_LAYOUT
281#error Missing implementation for structure-of-arrays memory layout.
283 ENSURE_VALID_ID_ACCESSOR(
id);
284 ENSURE_VALID_DIM_ID_ACCESSOR(dim);
285 ENSURE_VALID_DISTANCE_ID_ACCESSOR(did);
286 return m_forces[
id * nDim * noDistances() + nDim * did + dim];
292#ifdef LBMBCOLLECTOR_SOA_MEMORY_LAYOUT
293#error Missing implementation for structure-of-arrays memory layout.
295 ENSURE_VALID_ID_ACCESSOR(
id);
296 ENSURE_VALID_DIM_ID_ACCESSOR(dim);
297 ENSURE_VALID_DISTANCE_ID_ACCESSOR(did);
298 return m_forces[
id * nDim * noDistances() + nDim * did + dim];
305#ifdef LBMBCOLLECTOR_SOA_MEMORY_LAYOUT
306#error Missing implementation for structure-of-arrays memory layout.
308 ENSURE_VALID_ID_ACCESSOR(
id);
309 ENSURE_VALID_DIM_ID_ACCESSOR(dim);
310 ENSURE_VALID_DISTANCE_ID_ACCESSOR(did);
311 return m_surfaceCenters[
id * nDim * noDistances() + nDim * did + dim];
317#ifdef LBMBCOLLECTOR_SOA_MEMORY_LAYOUT
318#error Missing implementation for structure-of-arrays memory layout.
320 ENSURE_VALID_ID_ACCESSOR(
id);
321 ENSURE_VALID_DIM_ID_ACCESSOR(dim);
322 ENSURE_VALID_DISTANCE_ID_ACCESSOR(did);
323 return m_surfaceCenters[
id * nDim * noDistances() + nDim * did + dim];
330#ifdef LBMBCOLLECTOR_SOA_MEMORY_LAYOUT
331#error Missing implementation for structure-of-arrays memory layout.
333 ENSURE_VALID_ID_ACCESSOR(
id);
334 ENSURE_VALID_DIM_ID_ACCESSOR(dim);
335 return m_cellCenters[
id * nDim + dim];
341#ifdef LBMBCOLLECTOR_SOA_MEMORY_LAYOUT
342#error Missing implementation for structure-of-arrays memory layout.
344 ENSURE_VALID_ID_ACCESSOR(
id);
345 ENSURE_VALID_DIM_ID_ACCESSOR(dim);
346 return m_cellCenters[
id * nDim + dim];
353#ifdef LBMBCOLLECTOR_SOA_MEMORY_LAYOUT
354#error Missing implementation for structure-of-arrays memory layout.
356 ENSURE_VALID_ID_ACCESSOR(
id);
357 ENSURE_VALID_DIM_ID_ACCESSOR(dim);
358 return m_normal[
id * nDim + dim];
364#ifdef LBMBCOLLECTOR_SOA_MEMORY_LAYOUT
365#error Missing implementation for structure-of-arrays memory layout.
367 ENSURE_VALID_ID_ACCESSOR(
id);
368 ENSURE_VALID_DIM_ID_ACCESSOR(dim);
369 return m_normal[
id * nDim + dim];
376#ifdef LBMBCOLLECTOR_SOA_MEMORY_LAYOUT
377#error Missing implementation for structure-of-arrays memory layout.
379 ENSURE_VALID_ID_ACCESSOR(
id);
380 return m_density[
id];
386#ifdef LBMBCOLLECTOR_SOA_MEMORY_LAYOUT
387#error Missing implementation for structure-of-arrays memory layout.
389 ENSURE_VALID_ID_ACCESSOR(
id);
390 return m_density[
id];
400#ifdef LBMBCOLLECTOR_SOA_MEMORY_LAYOUT
401#error Missing implementation for structure-of-arrays memory layout.
403 fill_invalid(m_cellId, begin, end);
404 fill_invalid(m_distances, begin, end, noDistances());
405 fill_invalid(m_velocities, begin, end, nDim);
406 fill_invalid(m_forces, begin, end, nDim * noDistances(), 0.0);
407 fill_invalid(m_surfaceCenters, begin, end, nDim * noDistances());
408 fill_invalid(m_cellCenters, begin, end, nDim);
409 fill_invalid(m_normal, begin, end, nDim);
410 fill_invalid(m_density, begin, end);
415template <
class Functor,
class T>
417 const MInt destination) {
419#ifdef LBMBCOLLECTOR_SOA_MEMORY_LAYOUT
420#error Missing implementation for structure-of-arrays memory layout.
422 copyData(source.m_cellId, m_cellId, c, begin, end, destination, 1);
423 copyData(source.m_distances, m_distances, c, begin, end, destination, noDistances());
424 coptData(source.m_velocities, m_velocities, c, begin, end, destination, nDim);
425 copyData(source.m_forces, m_forces, c, begin, end, destination, nDim * noDistances());
426 copyData(source.m_surfaceCenters, m_surfaceCenters, c, begin, end, destination, nDim * noDistances());
427 copyData(source.m_cellCenters, m_cellCenters, c, begin, end, destination, nDim);
428 copyData(source.m_normal, m_normal, c, begin, end, destination, nDim);
429 copyData(source.m_density, m_density, c, begin, end, destination, 1);
436#undef LBCOLLECTOR_SANITY_CHECKS_ACCESSORS
437#undef ENSURE_VALID_ID_ACCESSOR
438#undef ENSURE_VALID_VARIABLE_ID_ACCESSOR
439#undef ENSURE_VALID_DISTANCES_ID_ACCESSOR
440#undef ENSURE_VALID_PROPERTY_ACCESSOR
void copyData(const Container_ &source, Container_ &target, Functor &&f, const MInt begin, const MInt end, const MInt dest, const MInt solverSize=1)
Copy [begin, end) range with given solver size from source to dest position of target.
void fill_invalid(Container_ &c, const MInt begin, const MInt end, const MInt solverSize=1, const T value=Invalid< T >::value())
void resetStorage(const MInt n, Storage< T > &c)
Create new container with given size and replace original one.
void reset(const MInt capacity)
Reset tree, re-create data structures with given capacity, and set size to zero.
Class that represents LB cell collector.
MFloat & surfaceCenter(const MInt id, const MInt did, const MInt dim)
Accessor for surfaceCenter.
void rawCopyGeneric(Functor &&c, const T &source, const MInt begin, const MInt end, const MInt destination)
Helper function for rawCopy(). Destination may refer to beginning or end of target range.
void noDistances(const MInt noDistances)
void reset()
Reset tree, re-create data structures with given capacity, and set size to zero.
MFloat & distance(const MInt id, const MInt did)
Accessor for distances.
void addVelocity(const MInt id, const std::array< MFloat, nDim > &velocity)
constexpr MInt noDimensions() const
Number of dimensions.
Storage< MFloat > m_velocities
constexpr LbMbCellCollector()=default
Default c'tor does nothing.
Storage< MFloat > m_forces
typename Base::template Storage< T > Storage
MFloat & velocity(const MInt id, const MInt dim)
Accessor for velocities.
Storage< MFloat > m_surfaceCenters
void invalidate(const MInt begin, const MInt end)
Erase range of nodes such that they contain no sensible values anymore.
Storage< MFloat > m_density
MFloat & normal(const MInt id, const MInt dim)
Accessor for surface normal.
void noForces(const MInt noDistances)
MFloat & cellCenter(const MInt id, const MInt dim)
Accessor for cellCenter.
MFloat & density(const MInt id)
Accessor for density.
Storage< MFloat > m_distances
Storage< MFloat > m_normal
void setVelocity(const MInt id, const std::array< MFloat, nDim > &velocity)
MFloat & force(const MInt id, const MInt did, const MInt dim)
Accessor for forces.
constexpr MInt noForces() const
Number of forces.
constexpr MInt noDistances() const
Number of distances.
MInt & cellId(const MInt id)
Accessor for cellId.
Storage< MFloat > m_cellCenters