/home/runner/work/amr-wind/amr-wind/amr-wind/core/CollMgr.H Source File

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/core/CollMgr.H Source File
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
CollMgr.H
Go to the documentation of this file.
1#ifndef COLLMGR_H
2#define COLLMGR_H
3
4#include <string>
5#include <memory>
6#include <unordered_map>
7#include "AMReX_Vector.H"
8
9namespace amr_wind {
10
20template <typename Collection, typename Type, bool allow_duplicates = false>
22{
23public:
24 using TypePtr = std::unique_ptr<Type>;
25 using TypeVector = amrex::Vector<TypePtr>;
26
27private:
28 CollMgr() = default;
29
30public:
31 ~CollMgr() = default;
32
33 CollMgr(const CollMgr&) = delete;
34 CollMgr& operator=(const CollMgr&) = delete;
35
39 template <class... Args>
40 Type& create(const std::string& key, Args&&... args)
41 {
42 if (!allow_duplicates && contains(key)) {
43 return operator()(key);
44 }
45
46 m_obj_vec.emplace_back(Type::create(key, std::forward<Args>(args)...));
47 m_obj_map[key] = m_obj_vec.size() - 1;
48
49 return *m_obj_vec.back();
50 }
51
54 [[nodiscard]] const TypeVector& objects() const { return m_obj_vec; }
55
57 [[nodiscard]] bool contains(const std::string& key) const
58 {
59 auto it = m_obj_map.find(key);
60 return (it != m_obj_map.end());
61 }
62
64 Type& operator()(const std::string& key)
65 {
66 return *m_obj_vec[m_obj_map.at(key)];
67 }
68
69 const Type& operator()(const std::string& key) const
70 {
71 return *m_obj_vec[m_obj_map.at(key)];
72 }
73
75 template <typename T>
76 T& operator()(const std::string& key)
77 {
78 return dynamic_cast<T&>(operator()(key));
79 }
80
81protected:
84
86 std::unordered_map<std::string, int> m_obj_map;
87 friend Collection;
88};
89
90} // namespace amr_wind
91
92#endif /* COLLMGR_H */
~CollMgr()=default
TypeVector & objects()
Return a vector of the registered objects.
Definition CollMgr.H:53
Type & operator()(const std::string &key)
Return the object corresponding to a lookup key.
Definition CollMgr.H:64
amrex::Vector< TypePtr > TypeVector
Definition CollMgr.H:25
bool contains(const std::string &key) const
Query if an object exists using the lookup key.
Definition CollMgr.H:57
std::unique_ptr< Type > TypePtr
Definition CollMgr.H:24
friend Collection
Definition CollMgr.H:87
CollMgr & operator=(const CollMgr &)=delete
T & operator()(const std::string &key)
Return object for a lookup key cast into its exact class definition.
Definition CollMgr.H:76
CollMgr(const CollMgr &)=delete
TypeVector m_obj_vec
Collection of objects registered so far.
Definition CollMgr.H:83
const TypeVector & objects() const
Definition CollMgr.H:54
Type & create(const std::string &key, Args &&... args)
Definition CollMgr.H:40
const Type & operator()(const std::string &key) const
Definition CollMgr.H:69
std::unordered_map< std::string, int > m_obj_map
Key word based lookup.
Definition CollMgr.H:86
This test case is intended as an evaluation of the momentum advection scheme.
Definition BCInterface.cpp:10