core
Shared MPI block decomposition + asynchronous ghost-layer exchange (header-only C++20)
Loading...
Searching...
No Matches
field_set.hpp
Go to the documentation of this file.
1// core — named registry of structured cell/face fields (the multiphysics field container).
2//
3// A method code (flow, and later coupling) accumulates an open-ended set of per-cell fields:
4// velocity components, pressure, the SDF, transported scalars (temperature, concentration, phase
5// fractions), and material-property fields (density, viscosity). Rather than hard-code each as a
6// named member and hand-list them wherever the full set matters (halo exchange, load-balance
7// redistribution), the FieldSet keeps them in one place keyed by name.
8//
9// It is a *directory*, not an owner of policy: it holds the device buffer, its ghost width and
10// centering, and whether the FieldSet allocated it (add) or merely aliases a member the solver
11// already owns (adopt). It carries NO halo objects — exchange stays per-call on the caller's
12// topology (docs/INTERFACES.md: the Field concept is duck-typed on the exchanger side).
13//
14// Header-only, Kokkos-required (pulls in common/view.hpp). Payload type is fixed to double: Eulerian
15// field state is double per docs/CONVENTIONS.md (§ precision policy).
16#ifndef PECLET_CORE_FIELD_FIELD_SET_HPP
17#define PECLET_CORE_FIELD_FIELD_SET_HPP
18
19#include <algorithm>
20#include <stdexcept>
21#include <string>
22#include <unordered_map>
23#include <vector>
24
26
27namespace peclet::core {
28
32enum class Centering { Cell, FaceX, FaceY, FaceZ };
33
43
48class FieldSet {
49 public:
51 FieldRec& add(const std::string& name, std::size_t n, int ghost,
53 recs_[name] = FieldRec{View<double>(name, n), ghost, c, true};
54 return recs_.at(name);
55 }
56
58 FieldRec& adopt(const std::string& name, View<double> v, int ghost,
60 recs_[name] = FieldRec{std::move(v), ghost, c, false};
61 return recs_.at(name);
62 }
63
64 bool has(const std::string& name) const { return recs_.find(name) != recs_.end(); }
65
66 FieldRec& at(const std::string& name) {
67 auto it = recs_.find(name);
68 if (it == recs_.end())
69 throw std::out_of_range("FieldSet: no field named '" + name + "'");
70 return it->second;
71 }
72 const FieldRec& at(const std::string& name) const {
73 auto it = recs_.find(name);
74 if (it == recs_.end())
75 throw std::out_of_range("FieldSet: no field named '" + name + "'");
76 return it->second;
77 }
78
79 std::size_t size() const { return recs_.size(); }
80
82 std::vector<std::string> names() const {
83 std::vector<std::string> out;
84 out.reserve(recs_.size());
85 for (const auto& kv : recs_)
86 out.push_back(kv.first);
87 std::sort(out.begin(), out.end());
88 return out;
89 }
90
91 private:
92 std::unordered_map<std::string, FieldRec> recs_;
93};
94
95} // namespace peclet::core
96
97#endif // PECLET_CORE_FIELD_FIELD_SET_HPP
Name → FieldRec directory.
Definition field_set.hpp:48
std::vector< std::string > names() const
Field names in a deterministic (sorted) order — the collective-safe enumeration.
Definition field_set.hpp:82
bool has(const std::string &name) const
Definition field_set.hpp:64
FieldRec & add(const std::string &name, std::size_t n, int ghost, Centering c=Centering::Cell)
Allocate a fresh zero-initialised device buffer of n elements and register it.
Definition field_set.hpp:51
const FieldRec & at(const std::string &name) const
Definition field_set.hpp:72
FieldRec & adopt(const std::string &name, View< double > v, int ghost, Centering c=Centering::Cell)
Register an existing buffer under name without taking ownership of its allocation.
Definition field_set.hpp:58
FieldRec & at(const std::string &name)
Definition field_set.hpp:66
std::size_t size() const
Definition field_set.hpp:79
Centering
Where a field's samples sit relative to a cell.
Definition field_set.hpp:32
Kokkos::View< T *, MemSpace > View
1D device array.
Definition view.hpp:26
One registered field: its flat x-fastest device buffer plus the metadata a consumer needs to exchange...
Definition field_set.hpp:37
View< double > data
Definition field_set.hpp:38