core 1.5.0
Shared MPI block decomposition, asynchronous ghost-layer exchange, SDF geometry, load balancing (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:
15// Eulerian 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, Centering c = Centering::Cell) {
52 recs_[name] = FieldRec{View<double>(name, n), ghost, c, true};
53 return recs_.at(name);
54 }
55
57 FieldRec& adopt(const std::string& name, View<double> v, int ghost,
59 recs_[name] = FieldRec{std::move(v), ghost, c, false};
60 return recs_.at(name);
61 }
62
63 bool has(const std::string& name) const { return recs_.find(name) != recs_.end(); }
64
65 FieldRec& at(const std::string& name) {
66 auto it = recs_.find(name);
67 if (it == recs_.end())
68 throw std::out_of_range("FieldSet: no field named '" + name + "'");
69 return it->second;
70 }
71 const FieldRec& at(const std::string& name) const {
72 auto it = recs_.find(name);
73 if (it == recs_.end())
74 throw std::out_of_range("FieldSet: no field named '" + name + "'");
75 return it->second;
76 }
77
78 std::size_t size() const { return recs_.size(); }
79
81 std::vector<std::string> names() const {
82 std::vector<std::string> out;
83 out.reserve(recs_.size());
84 for (const auto& kv : recs_)
85 out.push_back(kv.first);
86 std::sort(out.begin(), out.end());
87 return out;
88 }
89
90 private:
91 std::unordered_map<std::string, FieldRec> recs_;
92};
93
94} // namespace peclet::core
95
96#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:81
bool has(const std::string &name) const
Definition field_set.hpp:63
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:71
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:57
FieldRec & at(const std::string &name)
Definition field_set.hpp:65
std::size_t size() const
Definition field_set.hpp:78
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