Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
SetWhenMask.cpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
17
19#include "shambase/string.hpp"
24
26
27 template<class T>
30
31 auto edges = get_edges();
32
33 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
34
35 edges.mask.check_sizes(edges.part_counts.indexes);
36 edges.field_to_set.ensure_sizes(edges.part_counts.indexes);
37
38 auto var_counts = edges.part_counts.indexes.template map<u32>([&](u64, u32 count) {
39 return count * nvar;
40 });
41
43 dev_sched,
44 sham::DDMultiRef{edges.mask.get_spans()},
45 sham::DDMultiRef{edges.field_to_set.get_spans()},
46 var_counts,
47 [val_to_set = this->val_to_set,
48 nvar = this->nvar](u32 id_var, const u32 *mask, T *field_to_set) {
49 if (mask[id_var / nvar] != 0) {
50 field_to_set[id_var] = val_to_set;
51 }
52 });
53 }
54
55 template<class T>
56 std::string SetWhenMask<T>::_impl_get_tex() const {
57 auto mask = get_ro_edge_base(1).get_tex_symbol();
58 auto field_to_set = get_rw_edge_base(0).get_tex_symbol();
59
60 std::string tex = R"tex(
61 Set the field to a constant value \‍(c\) where the mask is non-zero
62 \begin{align}
63 {field}_{i,k} &= c \quad \text{if } {mask}_i \neq 0, \quad k = 0, \dots, {nvar} - 1
64 \end{align}
65 )tex";
66
67 shambase::replace_all(tex, "{field}", field_to_set);
68 shambase::replace_all(tex, "{mask}", mask);
69 shambase::replace_all(tex, "{nvar}", std::to_string(nvar));
70
71 return tex;
72 }
73
74} // namespace shammodels::sph::modules
75
Header file describing a Node Instance.
Solver graph node overwriting a field with a constant value where a mask is set.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
Overwrite every variable of a field with a constant where the per-object mask is non-zero.
void _impl_evaluate_internal()
evaluate the node
virtual std::string _impl_get_tex() const
get the tex of the node
IEdge & get_rw_edge_base(int slot)
Get a reference to a read write edge and cast it to the type IEdge.
Definition INode.hpp:147
const IEdge & get_ro_edge_base(int slot)
Get a reference to a read only edge.
Definition INode.hpp:138
void distributed_data_kernel_call(sham::DeviceScheduler_ptr dev_sched, RefIn in, RefOut in_out, const shambase::DistributedData< index_t > &thread_counts, Functor &&func)
A variant of sham::kernel_call for distributed data.
void replace_all(std::string &inout, std::string_view what, std::string_view with)
replace all occurence of a search string with another
Definition string.hpp:106
namespace for the sph model modules
This file contains the definition for the stacktrace related functionality.
#define __shamrock_stack_entry()
Macro to create a stack entry.
A variant of sham::MultiRef for distributed data.