Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_FabFactory.H
Go to the documentation of this file.
1
2#ifndef BL_FABFACTORY_H_
3#define BL_FABFACTORY_H_
4#include <AMReX_Config.H>
5
11#include <AMReX_Box.H>
12#include <AMReX_Print.H>
13#include <AMReX_MakeType.H>
14#include <AMReX_Vector.H>
15#include <AMReX_Arena.H>
16#include <AMReX_TypeTraits.H>
17
18namespace amrex
19{
20
21class FArrayBox;
22
27enum class FabType : int {
28 covered = -1,
29 regular = 0,
30 singlevalued = 1,
31 multivalued = 2,
32 undefined = 100
33};
34
40struct FabInfo
41{
42 bool alloc = true;
43 bool shared = false;
44 Arena* arena = nullptr;
45
47 FabInfo& SetAlloc (bool a) noexcept {
48 alloc = a;
49 return *this;
50 }
51
53 FabInfo& SetShared (bool s) noexcept {
54 shared = s;
55 return *this;
56 }
57
59 FabInfo& SetArena (Arena* ar) noexcept {
60 arena = ar;
61 return *this;
62 }
63};
64
71template <class FAB>
73{
74public:
75 FabFactory () noexcept = default;
76 FabFactory (FabFactory const&) noexcept = default;
77 FabFactory (FabFactory &&) noexcept = default;
78 FabFactory& operator= (FabFactory const&) noexcept = default;
79 FabFactory& operator= (FabFactory &&) noexcept = default;
80 virtual ~FabFactory () noexcept = default;
92 [[nodiscard]]
93 virtual FAB* create (const Box& box, int ncomps, const FabInfo& info, int box_index) const = 0;
99 [[nodiscard]]
100 virtual FAB* create_alias (FAB const& /*rhs*/, int /*scomp*/, int /*ncomp*/) const { return nullptr; }
102 virtual void destroy (FAB* fab) const = 0;
104 [[nodiscard]] virtual FabFactory<FAB>* clone () const = 0;
106 [[nodiscard]] virtual Long nBytes (const Box& box, int ncomps, int /*box_index*/) const {
107 if constexpr (IsBaseFab_v<FAB>) {
108 return box.numPts() * ncomps * Long(sizeof(typename FAB::value_type));
109 } else {
110 return -1;
111 }
112 }
113};
114
121template <class FAB>
123 : public FabFactory<FAB>
124{
125public:
126 [[nodiscard]]
127 FAB* create (const Box& box, int ncomps, const FabInfo& info, int /*box_index*/) const override
128 {
129 return new FAB(box, ncomps, info.alloc, info.shared, info.arena);
130 }
131
132 [[nodiscard]]
133 FAB* create_alias (FAB const& rhs, int scomp, int ncomp) const override
134 {
135 return new FAB(rhs, amrex::make_alias, scomp, ncomp);
136 }
137
138 void destroy (FAB* fab) const override
139 {
140 delete fab;
141 }
142
143 [[nodiscard]]
144 DefaultFabFactory<FAB>* clone () const override {
145 return new DefaultFabFactory<FAB>();
146 }
147};
148
149}
150
151#endif
Memory arena base class and global arena accessors.
Integer-lattice boxes and helpers for defining index-space regions.
Abstract base class for memory arenas.
Definition AMReX_Arena.H:153
__host__ __device__ Long numPts() const noexcept
Return the number of points contained in the BoxND.
Definition AMReX_Box.H:385
Default FabFactory that calls new / delete on the FAB type directly.
Definition AMReX_FabFactory.H:124
FAB * create(const Box &box, int ncomps, const FabInfo &info, int) const override
Create a FAB covering box with ncomps components.
Definition AMReX_FabFactory.H:127
void destroy(FAB *fab) const override
Destroy a FAB previously created by this factory.
Definition AMReX_FabFactory.H:138
FAB * create_alias(FAB const &rhs, int scomp, int ncomp) const override
Create an alias FAB that views components [scomp, scomp+ncomp) of rhs.
Definition AMReX_FabFactory.H:133
DefaultFabFactory< FAB > * clone() const override
Return a heap-allocated copy of this factory.
Definition AMReX_FabFactory.H:144
Abstract factory interface for creating, aliasing, and destroying FAB objects.
Definition AMReX_FabFactory.H:73
virtual void destroy(FAB *fab) const =0
Destroy a FAB previously created by this factory.
virtual Long nBytes(const Box &box, int ncomps, int) const
Return the storage size for ncomps components in box, or -1 if unavailable.
Definition AMReX_FabFactory.H:106
virtual FabFactory< FAB > * clone() const =0
Return a heap-allocated copy of this factory.
FabFactory() noexcept=default
virtual FAB * create_alias(FAB const &, int, int) const
Create an alias FAB that views components [scomp, scomp+ncomp) of rhs.
Definition AMReX_FabFactory.H:100
virtual FAB * create(const Box &box, int ncomps, const FabInfo &info, int box_index) const =0
Create a FAB covering box with ncomps components.
amrex_long Long
Definition AMReX_INT.H:30
FabType
Aggregate classification of a FAB or subregion used by embedded-boundary data.
Definition AMReX_FabFactory.H:27
@ undefined
The classification has not been determined.
@ singlevalued
No multivalued cells; not entirely regular or covered.
@ covered
Every cell in the region is covered.
@ regular
Every cell in the region is regular.
@ multivalued
The region contains at least one multivalued cell.
Definition AMReX_Amr.cpp:50
@ make_alias
Definition AMReX_MakeType.H:7
Construction hints passed to FabFactory::create.
Definition AMReX_FabFactory.H:41
FabInfo & SetShared(bool s) noexcept
Set the shared flag; returns *this for chaining.
Definition AMReX_FabFactory.H:53
bool alloc
Whether the factory should allocate FAB storage.
Definition AMReX_FabFactory.H:42
bool shared
Whether storage is managed as team-shared memory.
Definition AMReX_FabFactory.H:43
FabInfo & SetAlloc(bool a) noexcept
Set the alloc flag; returns *this for chaining.
Definition AMReX_FabFactory.H:47
FabInfo & SetArena(Arena *ar) noexcept
Set the arena pointer; returns *this for chaining.
Definition AMReX_FabFactory.H:59
Arena * arena
Arena for storage allocation; null selects the default.
Definition AMReX_FabFactory.H:44