62 FlagUID const Domain_flag{
"domain"};
64 FlagUID const Boundary_flag{
"boundary"};
67 class DynamicValueCallback {
69 DynamicValueCallback() {
71 std::make_shared<typename decltype(m_value_boundary)::element_type>();
76 std::shared_ptr<blockforest::StructuredBlockForest>
const &
blocks,
77 IBlock &
block)
const {
87 void unset_node_boundary_value(
Cell const &
global) {
89 m_value_boundary->erase(
global);
96 bool node_is_boundary(
Cell const &
global)
const {
97 return m_value_boundary->contains(
global);
100#if defined(__CUDACC__)
109 std::vector<FloatType>
values;
111 for (
auto const &[cell, value] : *m_value_boundary) {
113 for (
auto i : {0, 1, 2}) {
116 if constexpr (std::is_arithmetic_v<ValueType>) {
117 values.emplace_back(
static_cast<FloatType
>(value));
119 for (
auto i : {0, 1, 2}) {
120 values.emplace_back(
static_cast<FloatType
>(value[i]));
135#if defined(__CUDACC__)
139 std::shared_ptr<std::unordered_map<Cell, ValueType>> m_value_boundary;
140 static constexpr ValueType default_value{};
142 [[
nodiscard]]
auto const &get_value(
Cell const &cell)
const {
143 if (m_value_boundary->contains(cell)) {
144 return m_value_boundary->at(cell);
146 return default_value;
150 [[
nodiscard]]
inline auto get_flag_field_and_flag(IBlock *
block)
const {
165 m_callback(DynamicValueCallback()), m_local_domain(
local_domain),
166 m_pending_changes(
false) {
168 for (
auto &
block : *m_blocks) {
172 std::function
callback = m_callback;
181 return m_callback.node_is_boundary(
to_cell(node));
186 return m_callback.get_node_boundary_value(
to_cell(node));
192 m_callback.set_node_boundary_value(
to_cell(node), v);
194 m_pending_changes =
true;
199 m_callback.set_node_boundary_value(
to_cell(node), v);
205 m_callback.unset_node_boundary_value(
to_cell(node));
207 m_pending_changes =
true;
212 if (m_pending_changes) {
214 m_blocks, m_flag_field_id, Boundary_flag, Domain_flag);
215#if defined(__CUDACC__)
216 m_callback.rebuild_flat_map_device(m_local_domain);
218 m_pending_changes =
false;
224 return {
static_cast<int>(field->xSize()),
static_cast<int>(field->ySize()),
225 static_cast<int>(field->zSize())};
228#if defined(__CUDACC__)
230 return m_callback.get_flattened_map_device();
235 return m_boundary->getForce(
block);
239 using ForceVector = BoundaryClass::ForceVector;
242 forceVector->syncCPU();
243 return m_boundary->getForceVector(
block);
246 return m_boundary->getIndexVector(
block);
250 std::shared_ptr<StructuredBlockForest> m_blocks;
252 DynamicValueCallback m_callback;
253 std::shared_ptr<BoundaryClass> m_boundary;
254 CellInterval m_local_domain;
255 bool m_pending_changes;