7#ifndef MAIAFVSURFACECOLLECTOR_H_
8#define MAIAFVSURFACECOLLECTOR_H_
31#if defined(FVSURFACECOLLECTOR_SANITY_CHECKS_ACCESSORS) || defined(MAIA_ASSERT_ACCESSORS)
32#define ENSURE_VALID_ID_ACCESSOR(id) \
34 MAIA_CONTAINER_ENSURE_VALID_ID(id); \
36#define ENSURE_VALID_VARIABLE_ID_ACCESSOR(id) \
38 MAIA_CONTAINER_ENSURE( \
39 id >= 0 && id < noVariables(), \
40 "variable id = " + std::to_string(id) + " out-of-bounds [0, " + std::to_string(noVariables()) + ")", AT_); \
42#define ENSURE_VALID_FLUX_VARIABLE_ID_ACCESSOR(id) \
44 MAIA_CONTAINER_ENSURE(id >= 0 && id < noFVariables(), \
45 "flux variable id = " + std::to_string(id) + " out-of-bounds [0, " \
46 + std::to_string(noFVariables()) + ")", \
49#define ENSURE_VALID_DIR_ACCESSOR(id) \
51 MAIA_CONTAINER_ENSURE(id >= 0 && id < 2, "dir = " + std::to_string(id) + " out-of-bounds [0, 2)", AT_); \
53#define ENSURE_VALID_COORDINATE_DIR_ACCESSOR(dir) \
55 MAIA_CONTAINER_ENSURE( \
56 dir >= 0 && dir < nDim, \
57 "direction dir = " + std::to_string(dir) + " out-of-bounds [0, " + std::to_string(nDim) + ")", AT_); \
59#define ENSURE_VALID_SURFACE_COEFFICIENT_ID_ACCESSOR(id) \
61 MAIA_CONTAINER_ENSURE(id >= 0 && id < noSurfaceCoefficients(), \
62 "surface coefficient id = " + std::to_string(id) + " out-of-bounds [0, " \
63 + std::to_string(noSurfaceCoefficients()) + ")", \
67#define ENSURE_VALID_ID_ACCESSOR(id) \
70#define ENSURE_VALID_VARIABLE_ID_ACCESSOR(id) \
73#define ENSURE_VALID_FLUX_VARIABLE_ID_ACCESSOR(id) \
76#define ENSURE_VALID_DIR_ACCESSOR(id) \
79#define ENSURE_VALID_COORDINATE_DIR_ACCESSOR(dir) \
82#define ENSURE_VALID_SURFACE_COEFFICIENT_ID_ACCESSOR(id) \
98 static constexpr MInt value() {
return std::numeric_limits<MInt>::min(); }
104 static constexpr MLong value() {
return std::numeric_limits<MLong>::min(); }
111#ifdef MAIA_PGI_COMPILER
112 return std::numeric_limits<MFloat>::quiet_NaN();
114 return std::numeric_limits<MFloat>::signaling_NaN();
215 template <
class Functor,
class T>
255 std::cerr <<
"@FvSurfaceCollector: noVariables() = " << noVariables() <<
", noFVariables() = " << noFVariables()
256 <<
", noSurfaceCoefficients() = " << noSurfaceCoefficients() <<
", m_noMaxSrfcs = " << noMaxSrfcs()
264 resetStorage(1, m_bndryCndId);
265 resetStorage(1, m_orientation);
266 resetStorage(2, m_factor);
267 resetStorage(1, m_area);
268 resetStorage(nDim, m_coordinates);
269 resetStorage(2 * nDim, m_deltaX);
270 resetStorage(2, m_nghbrCellIds);
271 resetStorage(2 * noVariables(), m_variables);
272 resetStorage(1, m_upwindCoefficent);
273 resetStorage(noSurfaceCoefficients(), m_surfaceCoefficients);
274 resetStorage(noFVariables(), m_flux);
281 resizeStorage(1, m_bndryCndId);
282 resizeStorage(1, m_orientation);
283 resizeStorage(2, m_factor);
284 resizeStorage(1, m_area);
285 resizeStorage(nDim, m_coordinates);
286 resizeStorage(2 * nDim, m_deltaX);
287 resizeStorage(2, m_nghbrCellIds);
288 resizeStorage(2 * noVariables(), m_variables);
289 resizeStorage(1, m_upwindCoefficent);
290 resizeStorage(noSurfaceCoefficients(), m_surfaceCoefficients);
291 resizeStorage(noFVariables(), m_flux);
304#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
305#error Missing implementation for structure-of-arrays memory layout.
307 ENSURE_VALID_ID_ACCESSOR(
id);
308 return m_bndryCndId[
id];
314#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
315#error Missing implementation for structure-of-arrays memory layout.
317 ENSURE_VALID_ID_ACCESSOR(
id);
318 return m_bndryCndId[
id];
325#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
326#error Missing implementation for structure-of-arrays memory layout.
328 ENSURE_VALID_ID_ACCESSOR(
id);
329 return m_orientation[
id];
335#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
336#error Missing implementation for structure-of-arrays memory layout.
338 ENSURE_VALID_ID_ACCESSOR(
id);
339 return m_orientation[
id];
346#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
347#error Missing implementation for structure-of-arrays memory layout.
349 ENSURE_VALID_ID_ACCESSOR(
id);
350 ENSURE_VALID_VARIABLE_ID_ACCESSOR(varId);
351 return m_factor[
id * 2 + varId];
357#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
358#error Missing implementation for structure-of-arrays memory layout.
360 ENSURE_VALID_ID_ACCESSOR(
id);
361 ENSURE_VALID_VARIABLE_ID_ACCESSOR(varId);
362 return m_factor[
id * 2 + varId];
369#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
370#error Missing implementation for structure-of-arrays memory layout.
372 ENSURE_VALID_ID_ACCESSOR(
id);
379#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
380#error Missing implementation for structure-of-arrays memory layout.
382 ENSURE_VALID_ID_ACCESSOR(
id);
390#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
391#error Missing implementation for structure-of-arrays memory layout.
393 ENSURE_VALID_ID_ACCESSOR(
id);
394 ENSURE_VALID_COORDINATE_DIR_ACCESSOR(dir);
395 return m_coordinates[
id * nDim + dir];
401#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
402#error Missing implementation for structure-of-arrays memory layout.
404 ENSURE_VALID_ID_ACCESSOR(
id);
405 ENSURE_VALID_COORDINATE_DIR_ACCESSOR(dir);
406 return m_coordinates[
id * nDim + dir];
413#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
414#error Missing implementation for structure-of-arrays memory layout.
416 ENSURE_VALID_ID_ACCESSOR(
id);
417 ENSURE_VALID_VARIABLE_ID_ACCESSOR(varId);
418 return m_deltaX[
id * 2 * nDim + varId];
424#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
425#error Missing implementation for structure-of-arrays memory layout.
427 ENSURE_VALID_ID_ACCESSOR(
id);
428 ENSURE_VALID_VARIABLE_ID_ACCESSOR(varId);
429 return m_deltaX[
id * 2 * nDim + varId];
436#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
437#error Missing implementation for structure-of-arrays memory layout.
439 ENSURE_VALID_ID_ACCESSOR(
id);
440 ENSURE_VALID_COORDINATE_DIR_ACCESSOR(dir);
441 return m_nghbrCellIds[
id * 2 + dir];
447#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
448#error Missing implementation for structure-of-arrays memory layout.
450 ENSURE_VALID_ID_ACCESSOR(
id);
451 ENSURE_VALID_COORDINATE_DIR_ACCESSOR(dir);
452 return m_nghbrCellIds[
id * 2 + dir];
459#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
460#error Missing implementation for structure-of-arrays memory layout.
462 ENSURE_VALID_ID_ACCESSOR(
id);
463 ENSURE_VALID_DIR_ACCESSOR(dir);
464 ENSURE_VALID_VARIABLE_ID_ACCESSOR(varId);
465 return m_variables[(
id * 2 + dir) * noVariables() + varId];
471#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
472#error Missing implementation for structure-of-arrays memory layout.
474 ENSURE_VALID_ID_ACCESSOR(
id);
475 ENSURE_VALID_DIR_ACCESSOR(dir);
476 ENSURE_VALID_VARIABLE_ID_ACCESSOR(varId);
477 return m_variables[(
id * 2 + dir) * noVariables() + varId];
484#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
485#error Missing implementation for structure-of-arrays memory layout.
487 ENSURE_VALID_ID_ACCESSOR(
id);
488 return m_upwindCoefficent[
id];
494#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
495#error Missing implementation for structure-of-arrays memory layout.
497 ENSURE_VALID_ID_ACCESSOR(
id);
498 return m_upwindCoefficent[
id];
505#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
506#error Missing implementation for structure-of-arrays memory layout.
508 ENSURE_VALID_ID_ACCESSOR(
id);
509 ENSURE_VALID_SURFACE_COEFFICIENT_ID_ACCESSOR(dimCoefficient);
510 return m_surfaceCoefficients[
id * noSurfaceCoefficients() + dimCoefficient];
516#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
517#error Missing implementation for structure-of-arrays memory layout.
519 ENSURE_VALID_ID_ACCESSOR(
id);
520 ENSURE_VALID_SURFACE_COEFFICIENT_ID_ACCESSOR(dimCoefficient);
521 return m_surfaceCoefficients[
id * noSurfaceCoefficients() + dimCoefficient];
528#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
529#error Missing implementation for structure-of-arrays memory layout.
531 ENSURE_VALID_ID_ACCESSOR(
id);
532 ENSURE_VALID_FLUX_VARIABLE_ID_ACCESSOR(varId);
533 return m_flux[
id * noFVariables() + fVarId];
539#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
540#error Missing implementation for structure-of-arrays memory layout.
542 ENSURE_VALID_ID_ACCESSOR(
id);
543 ENSURE_VALID_FLUX_VARIABLE_ID_ACCESSOR(varId);
544 return m_flux[
id * noFVariables() + fVarId];
549 m_noSpecies = noSpecies_;
555 m_noMaxSrfcs = noMaxSrfcs_;
561 m_noVariables = noVariables_;
567 m_noFVariables = noFVariables_;
573 m_noSurfaceCoefficients = noSurfaceCoefficients_;
579 m_solverType = solverType;
586#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
587#error Missing implementation for structure-of-arrays memory layout.
591 fill_invalid(m_bndryCndId, begin, end, 1, -1);
593 fill_invalid(m_orientation, begin, end, 1, -1);
595 fill_invalid(m_factor, begin, end, 2);
597 fill_invalid(m_area, begin, end);
599 fill_invalid(m_coordinates, begin, end, nDim);
601 fill_invalid(m_deltaX, begin, end, 2 * nDim);
603 fill_invalid(m_nghbrCellIds, begin, end, 2, -1);
605 fill_invalid(m_variables, begin, end, 2 * noVariables());
607 fill_invalid(m_upwindCoefficent, begin, end);
609 fill_invalid(m_surfaceCoefficients, begin, end, noSurfaceCoefficients());
611 fill_invalid(m_flux, begin, end, noFVariables());
616template <
class Functor,
class T>
618 const MInt destination) {
620#ifdef FVSURFACECOLLECTOR_SOA_MEMORY_LAYOUT
621#error Missing implementation for structure-of-arrays memory layout.
625 copyData(source.m_bndryCndId, m_bndryCndId, c, begin, end, destination);
627 copyData(source.m_orientation, m_orientation, c, begin, end, destination);
629 copyData(source.m_factor, m_factor, c, begin, end, destination, 2);
631 copyData(source.m_area, m_area, c, begin, end, destination);
633 copyData(source.m_coordinates, m_coordinates, c, begin, end, destination, nDim);
635 copyData(source.m_deltaX, m_deltaX, c, begin, end, destination, 2 * nDim);
637 copyData(source.m_nghbrCellIds, m_nghbrCellIds, c, begin, end, destination, 2);
639 copyData(source.m_variables, m_variables, c, begin, end, destination, 2 * noVariables());
641 copyData(source.m_upwindCoefficent, m_upwindCoefficent, c, begin, end, destination);
643 copyData(source.m_surfaceCoefficients, m_surfaceCoefficients, c, begin, end, destination, noSurfaceCoefficients());
645 copyData(source.m_flux, m_flux, c, begin, end, destination, noFVariables());
651#undef FVSURFACECOLLECTOR_SANITY_CHECKS_ACCESSORS
652#undef ENSURE_VALID_ID_ACCESSOR
653#undef ENSURE_VALID_VARIABLE_ID_ACCESSOR
654#undef ENSURE_VALID_FLUX_VARIABLE_ID_ACCESSOR
655#undef ENSURE_VALID_DIR_ACCESSOR
656#undef ENSURE_VALID_COORDINATE_DIR_ACCESSOR
657#undef ENSURE_VALID_SURFACE_COEFFICIENT_ID_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 resizeStorage(const MInt n, Storage< T > &c)
Resize container with given size.
void reset(const MInt capacity)
Reset tree, re-create data structures with given capacity, and set size to zero.
Class that represents FV surface collector.
MFloat & area(const MInt id)
Accessor for area.
constexpr MInt noVariables() const
Return number of variables.
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.
constexpr MInt noMaxSrfcs() const
Return number of maximum surfaces.
Storage< MFloat > m_deltaX
Storage< MFloat > m_variables
Storage< MInt > m_orientation
Storage< MFloat > m_factor
MFloat & coordinate(const MInt id, const MInt dir)
Accessor for coordinate.
void checkVariables()
Print data size variables.
MFloat & upwindCoefficient(const MInt id)
Accessor for upwind coefficient.
constexpr FvSurfaceCollector()=default
Default c'tor does nothing.
MInt m_noSurfaceCoefficients
MFloat & factor(const MInt id, const MInt varId)
Accessor for factor.
void setNoSurfaceCoefficients(const MInt noSurfaceCoefficients_)
Set number of surface coefficients and update number of surface coefficients.
void setNoVariables(const MInt noVariables_)
Set number of variables and update number of variables.
Storage< MFloat > m_coordinates
MFloat & flux(const MInt id, const MInt fVarId)
Accessor for flux.
constexpr MInt noSpecies() const
Return number of species.
MFloat & deltaX(const MInt id, const MInt varId)
Accessor for deltaX.
constexpr SolverType solverType() const
Return solver type.
void resize() override
Reset tree, re-create data structures with given capacity, and set size to zero.
MFloat & variable(const MInt id, const MInt dir, const MInt varId)
Accessor for variable.
MInt & nghbrCellId(const MInt id, const MInt dir)
Accessor for nghbrCellId.
Storage< MInt > m_bndryCndId
void reset()
Reset tree, re-create data structures with given capacity, and set size to zero.
void invalidate(const MInt begin, const MInt end)
Erase range of nodes such that they contain no sensible values anymore.
Storage< MFloat > m_surfaceCoefficients
MInt & bndryCndId(const MInt id)
Accessor for bndryCndId.
Storage< MInt > m_nghbrCellIds
MInt m_noSpecies
Number of species (not being used)
void setNoSpecies(const MInt noSpecies_)
Set number of species and update number of variables.
MInt & orientation(const MInt id)
Accessor for orientation.
typename maia::fv::surface_collector::Invalid< T > Invalid
void setSolverType(const MInt solverType)
Set solver type.
constexpr MInt noSurfaceCoefficients() const
Return number of surface coefficients.
constexpr MInt noFVariables() const
Return number of flux variables.
void setNoFVariables(const MInt noFVariables_)
Set number of flux variables.
Storage< MFloat > m_upwindCoefficent
typename Base::template Storage< T > Storage
MFloat & surfaceCoefficient(const MInt id, const MInt dimCoefficient)
Accessor for surfaceCoefficient.
void setNoMaxSrfcs(const MInt noMaxSrfcs_)
Set number of maximum surfaces and update number of variables.
Namespace for auxiliary functions/classes.
static constexpr MInt value()
static constexpr MLong value()