32 inline static const std::string name =
"std::vector<" + get_type_name<T>() +
">";
40 using Tscal = shambase::VecComponent<Tvec>;
42 std::vector<Tvec> &pos;
43 std::vector<Tvec> &vel;
44 std::vector<Tvec> &acc_sph;
45 std::vector<Tvec> &acc_ext;
46 std::vector<Tscal> &mass;
47 std::vector<Tvec> &angular_momentum;
48 std::vector<Tscal> &accretion_radius;
50 inline bool has_sinks()
const {
return !pos.empty(); }
51 inline size_t size()
const {
return pos.size(); }
57 inline T &get_sync_data(
59 return sync.template get_edge_ref<shamrock::solvergraph::IDataEdgeSerializable<T>>(name)
71 return details::get_sync_data<std::vector<Tvec>>(sync,
"sink_pos");
76 return details::get_sync_data<std::vector<Tvec>>(sync,
"sink_vel");
80 inline std::vector<Tvec> &get_sink_acc_sph(
82 return details::get_sync_data<std::vector<Tvec>>(sync,
"sink_acc_sph");
86 inline std::vector<Tvec> &get_sink_acc_ext(
87 shamrock::solvergraph::SolverGraphSerializable &sync) {
88 return details::get_sync_data<std::vector<Tvec>>(sync,
"sink_acc_ext");
92 inline std::vector<shambase::VecComponent<Tvec>> &get_sink_mass(
93 shamrock::solvergraph::SolverGraphSerializable &sync) {
94 return details::get_sync_data<std::vector<shambase::VecComponent<Tvec>>>(sync,
"sink_mass");
98 inline std::vector<Tvec> &get_sink_angular_momentum(
99 shamrock::solvergraph::SolverGraphSerializable &sync) {
100 return details::get_sync_data<std::vector<Tvec>>(sync,
"sink_angular_momentum");
104 inline std::vector<shambase::VecComponent<Tvec>> &get_sink_accretion_radius(
105 shamrock::solvergraph::SolverGraphSerializable &sync) {
106 return details::get_sync_data<std::vector<shambase::VecComponent<Tvec>>>(
107 sync,
"sink_accretion_radius");
116 return sync.
has_edge(
"sink_accreted_dust_mass");
120 inline std::vector<shambase::VecComponent<Tvec>> &get_sink_accreted_dust_mass(
122 return details::get_sync_data<std::vector<shambase::VecComponent<Tvec>>>(
123 sync,
"sink_accreted_dust_mass");
133 template<
class Tscal>
135 std::vector<Tscal> &accreted_dust_mass,
size_t sink_count,
u32 ndust) {
136 size_t target_size = sink_count * ndust;
137 if (accreted_dust_mass.size() == target_size) {
140 if (ndust == 0 || accreted_dust_mass.size() > target_size
141 || accreted_dust_mass.size() % ndust != 0) {
143 "sink accreted dust mass layout mismatch: size={}, sink_count={}, ndust={}",
144 accreted_dust_mass.size(),
148 accreted_dust_mass.resize(target_size, Tscal{0});
172 get_sink_vel<Tvec>(sync),
173 get_sink_acc_sph<Tvec>(sync),
174 get_sink_acc_ext<Tvec>(sync),
175 get_sink_mass<Tvec>(sync),
176 get_sink_angular_momentum<Tvec>(sync),
177 get_sink_accretion_radius<Tvec>(sync),
186 std::vector<SinkParticle<Tvec>> out;
187 out.reserve(e.size());
188 for (
size_t i = 0; i < e.size(); i++) {
196 e.angular_momentum[i],
197 e.accretion_radius[i],
214 e.angular_momentum.clear();
215 e.accretion_radius.clear();
217 e.pos.reserve(sinks.size());
218 e.vel.reserve(sinks.size());
219 e.acc_sph.reserve(sinks.size());
220 e.acc_ext.reserve(sinks.size());
221 e.mass.reserve(sinks.size());
222 e.angular_momentum.reserve(sinks.size());
223 e.accretion_radius.reserve(sinks.size());
225 for (
const auto &s : sinks) {
226 e.pos.push_back(s.pos);
227 e.vel.push_back(s.velocity);
228 e.acc_sph.push_back(s.sph_acceleration);
229 e.acc_ext.push_back(s.ext_acceleration);
230 e.mass.push_back(s.mass);
231 e.angular_momentum.push_back(s.angular_momentum);
232 e.accretion_radius.push_back(s.accretion_radius);
242 typename SinkEdges<Tvec>::Tscal mass,
245 typename SinkEdges<Tvec>::Tscal accretion_radius) {
247 e.pos.push_back(pos);
248 e.vel.push_back(velocity);
249 e.acc_sph.push_back({});
250 e.acc_ext.push_back({});
251 e.mass.push_back(mass);
252 e.angular_momentum.push_back({});
253 e.accretion_radius.push_back(accretion_radius);
Declare a class to register and retrieve nodes and edges from a unique container.
std::uint32_t u32
32 bit unsigned integer
bool has_edge(const std::string &name) const
Check whether an edge with the given name exists.
This header file contains utility functions related to exception handling in the code.
Namespace for internal details of the logs module.
namespace for basic c++ utilities
ExcptTypes make_except_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Create an exception with a message and a location.
namespace for the sph model
bool has_sinks(shamrock::solvergraph::SolverGraphSerializable &sync)
Check whether any sinks are present by inspecting sink_pos only.
std::vector< SinkParticle< Tvec > > to_sink_particles(const SinkEdges< Tvec > &e)
Build an AoS sink list from the current SoA edges (Python API / dump helpers).
std::vector< Tvec > & get_sink_pos(shamrock::solvergraph::SolverGraphSerializable &sync)
Named SoA getters (edges must already exist; registered by Solver::init_solver_graph)....
SinkEdges< Tvec > get_sink_edges(shamrock::solvergraph::SolverGraphSerializable &sync)
Fetch mutable references to the sink SoA synchronized edges.
void resize_sink_accreted_dust_mass(std::vector< Tscal > &accreted_dust_mass, size_t sink_count, u32 ndust)
Resize the flattened per species accreted dust mass to sink_count * ndust.
void add_sink(SinkEdges< Tvec > &e, typename SinkEdges< Tvec >::Tscal mass, Tvec pos, Tvec velocity, typename SinkEdges< Tvec >::Tscal accretion_radius)
Append one sink to the SoA edges.
bool has_sink_accreted_dust_mass(shamrock::solvergraph::SolverGraphSerializable &sync)
Whether the per species accreted dust mass sink edge is registered.
void set_sink_particles(SinkEdges< Tvec > &e, const std::vector< SinkParticle< Tvec > > &sinks)
Replace SoA sink edge contents from an AoS sink list (legacy dump migration).
Contains traits and utilities for backend related types.