Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
Solver.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
18
20#include "shambase/memory.hpp"
23#include "shamcomm/logs.hpp"
87#include <memory>
88
89template<class Tvec, class TgridVec>
90class PatchDataLayerToVtk : public shamrock::solvergraph::INode {
91 bool write_id_patch;
92 bool write_world_rank;
93 using Tscal = shambase::VecComponent<Tvec>;
94 u32 block_size;
95
96 public:
97 PatchDataLayerToVtk(bool write_id_patch, bool write_world_rank, u32 block_size)
98 : write_id_patch(write_id_patch), write_world_rank(write_world_rank),
99 block_size(block_size) {}
100
101 struct Edges {
102 // inputs
104 const shamrock::solvergraph::IPatchDataLayerRefs &patch_data_layers;
105 };
106
107 inline void set_edges(
108 std::shared_ptr<shamrock::solvergraph::IDataEdge<std::string>> filename,
109 std::shared_ptr<shamrock::solvergraph::IPatchDataLayerRefs> patch_data_layers) {
110 __internal_set_ro_edges({filename, patch_data_layers});
112 }
113
114 inline Edges get_edges() {
115 return Edges{
118 };
119 }
120
123
124 auto edges = get_edges();
125
126 auto &filename = edges.filename;
127 auto &patch_data_layers = edges.patch_data_layers;
128
129 // Compute the number of fields to generate
130 auto get_field_count = [&]() {
131 u32 field_count = 0;
132
133 {
134 u64 id_patch = patch_data_layers.get_const_refs().get_ids().front();
135 auto &pdat = patch_data_layers.get(id_patch);
136
137 pdat.for_each_field_any([&](auto &field) {
138 field_count++;
139 });
140 }
141
142 if (write_id_patch) {
143 field_count++;
144 }
145 if (write_world_rank) {
146 field_count++;
147 }
148
149 return field_count - 2; // to remove the block infos
150 };
151
152 auto get_layout = [&]() -> const shamrock::patch::PatchDataLayerLayout & {
153 u64 id_patch = patch_data_layers.get_const_refs().get_ids().front();
154 const shamrock::patch::PatchDataLayer &pdat = patch_data_layers.get(id_patch);
155 return pdat.pdl();
156 };
157
158 shamrock::LegacyVtkWriter writer(filename.data, true, shamrock::UnstructuredGrid);
159
160 u32 field_count = get_field_count();
161
162 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
163 auto &q = shambase::get_check_ref(dev_sched).get_queue();
164
165 sham::DeviceBuffer<TgridVec> pos_min_block(0, dev_sched);
166 sham::DeviceBuffer<TgridVec> pos_max_block(0, dev_sched);
167
168 patch_data_layers.get_const_refs().for_each_ordered(
169 [&](u64 id_patch, const std::reference_wrapper<shamrock::patch::PatchDataLayer> &pdat) {
170 auto &pdat_ref = pdat.get();
171 auto &buf_pos_min = pdat_ref.get_field_buf_ref<TgridVec>(0);
172 auto &buf_pos_max = pdat_ref.get_field_buf_ref<TgridVec>(1);
173 pos_min_block.append(buf_pos_min);
174 pos_max_block.append(buf_pos_max);
175 });
176
177 u64 num_obj = pos_min_block.get_size();
178
179 sham::DeviceBuffer<Tvec> pos_max_cell(num_obj * block_size, dev_sched);
180 sham::DeviceBuffer<Tvec> pos_min_cell(num_obj * block_size, dev_sched);
181
182 if (num_obj > 0) {
183
185
186 if (Block::block_size != block_size) {
188 "block_size mismatch, got {} expected {}", Block::block_size, block_size));
189 }
190
192 q,
193 sham::MultiRef{pos_min_block, pos_max_block},
194 sham::MultiRef{pos_min_cell, pos_max_cell},
195 num_obj,
196 [](u32 id_a,
197 const TgridVec *__restrict ptr_block_min,
198 const TgridVec *__restrict ptr_block_max,
199 Tvec *cell_min,
200 Tvec *cell_max) {
201 Tvec block_min = ptr_block_min[id_a].template convert<Tscal>();
202 Tvec block_max = ptr_block_max[id_a].template convert<Tscal>();
203
204 Tvec delta_cell = (block_max - block_min) / Block::side_size;
205 for (u32 ix = 0; ix < Block::side_size; ix++) {
206 for (u32 iy = 0; iy < Block::side_size; iy++) {
207 for (u32 iz = 0; iz < Block::side_size; iz++) {
208 u32 i = Block::get_index({ix, iy, iz});
209 Tvec delta_val = delta_cell * Tvec{ix, iy, iz};
210 cell_min[id_a * Block::block_size + i] = block_min + delta_val;
211 cell_max[id_a * Block::block_size + i]
212 = block_min + (delta_cell) + delta_val;
213 }
214 }
215 }
216 });
217 }
218
219 auto pos_min_cell_buf = pos_min_cell.copy_to_sycl_buffer();
220 auto pos_max_cell_buf = pos_max_cell.copy_to_sycl_buffer();
221 writer.write_voxel_cells(pos_min_cell_buf, pos_max_cell_buf, num_obj * block_size);
222
223 writer.add_cell_data_section();
224 writer.add_field_data_section(field_count);
225
226 const shamrock::patch::PatchDataLayerLayout &layout = get_layout();
227
228 layout.for_each_field_any([&](auto &field_desc) {
229 using f_t = typename std::remove_reference<decltype(field_desc)>::type::field_T;
230 u32 nvar = field_desc.nvar;
231 std::string field_name = field_desc.name;
232
233 u32 idx = layout.get_field_idx<f_t>(field_name);
234
235 if (nvar == 1) {
236 // this the block info and i'll skip it for now
237 } else if (nvar != block_size) {
239 } else {
240 sham::DeviceBuffer<f_t> data(0, dev_sched);
241
242 patch_data_layers.get_const_refs().for_each_ordered(
243 [&](u64 id_patch,
244 const std::reference_wrapper<shamrock::patch::PatchDataLayer> &pdat) {
245 auto &pdat_ref = pdat.get();
246 auto &buf_field = pdat_ref.get_field_buf_ref<f_t>(idx);
247 data.append(buf_field);
248 });
249
250 auto tmp_buf = data.copy_to_sycl_buffer();
251 writer.write_field(field_name, tmp_buf, num_obj * block_size);
252 }
253 });
254
255 if (write_id_patch) {
256 using f_t = u32;
257 sham::DeviceBuffer<f_t> data(0, dev_sched);
258
259 patch_data_layers.get_const_refs().for_each_ordered(
260 [&](u64 id_patch,
261 const std::reference_wrapper<shamrock::patch::PatchDataLayer> &pdat) {
262 auto buf_field
263 = sham::DeviceBuffer<f_t>(pdat.get().get_obj_cnt() * block_size, dev_sched);
264 buf_field.fill(id_patch);
265 data.append(buf_field);
266 });
267
268 auto tmp_buf = data.copy_to_sycl_buffer();
269 writer.write_field("id_patch", tmp_buf, num_obj * block_size);
270 }
271 if (write_world_rank) {
272 using f_t = u32;
273 sham::DeviceBuffer<f_t> data(0, dev_sched);
274
275 patch_data_layers.get_const_refs().for_each_ordered(
276 [&](u64 id_patch,
277 const std::reference_wrapper<shamrock::patch::PatchDataLayer> &pdat) {
278 auto buf_field
279 = sham::DeviceBuffer<f_t>(pdat.get().get_obj_cnt() * block_size, dev_sched);
280 buf_field.fill(shamcomm::world_rank());
281 data.append(buf_field);
282 });
283 auto tmp_buf = data.copy_to_sycl_buffer();
284 writer.write_field("world_rank", tmp_buf, num_obj * block_size);
285 }
286 }
287
288 std::string _impl_get_label() { return "PatchDataLayerToVtk"; }
289
290 std::string _impl_get_tex() { return "TODO"; }
291};
292
293template<class Tvec, class TgridVec>
295
299
300 auto &sync_data = scheduler().synchronized_data;
301
302 // register a synchronized edge only if missing, as it may have been restored from a dump
303 auto ensure_sync_edge
304 = [&](const std::string &name, const std::string &tex_symbol, auto init_value) {
305 using T = decltype(init_value);
306 if (!sync_data.has_edge(name)) {
307 auto edge = sync_data.register_edge(
309 edge->data = std::move(init_value);
310 }
311 };
312
313 ensure_sync_edge("time", "t", Tscal{0});
314 ensure_sync_edge("dt", "dt", Tscal{0});
315
319
320 bool enable_mem_free = false;
321
322 auto get_optional_free_mem = [&](auto &bind_to, auto &add_to) {
323 if (enable_mem_free) {
325 node.set_edges(bind_to);
326 add_to.push_back(std::make_shared<decltype(node)>(std::move(node)));
327 }
328 };
329
330 {
331 storage.ghost_layout = std::make_shared<shamrock::patch::PatchDataLayerLayout>();
333 = shambase::get_check_ref(storage.ghost_layout);
334
335 ghost_layout.add_field<TgridVec>("cell_min", 1);
336 ghost_layout.add_field<TgridVec>("cell_max", 1);
337 ghost_layout.add_field<Tscal>("rho", AMRBlock::block_size);
338 ghost_layout.add_field<Tscal>("rhoetot", AMRBlock::block_size);
339 ghost_layout.add_field<Tvec>("rhovel", AMRBlock::block_size);
340
341 if (solver_config.is_dust_on()) {
342 auto ndust = solver_config.dust_config.ndust;
343 ghost_layout.add_field<Tscal>("rho_dust", ndust * AMRBlock::block_size);
344 ghost_layout.add_field<Tvec>("rhovel_dust", ndust * AMRBlock::block_size);
345 }
346
347 if (solver_config.is_gravity_on()) {
348 ghost_layout.add_field<Tscal>("phi", AMRBlock::block_size);
349 ghost_layout.add_field<Tscal>("phi_old", AMRBlock::block_size);
350 }
351
352 if (solver_config.is_gas_passive_scalar_on()) {
353 u32 npscal_gas = solver_config.npscal_gas_config.npscal_gas;
354 ghost_layout.add_field<Tscal>("rho_gas_pscal", npscal_gas * AMRBlock::block_size);
355 }
356 }
357
361
362 using namespace shamrock::solvergraph;
363
364 SolverGraph &graph = storage.solver_graph;
365
366 graph.register_edge("sptree", SerialPatchTreeRefEdge<TgridVec>("sptree", "sptree"));
367
368 graph.register_edge(
369 "global_patch_boxes",
370 ScalarsEdge<shammath::AABB<TgridVec>>("global_patch_boxes", "global_patch_boxes"));
371
372 graph.register_node(
373 "set_sptree",
375 edge.patch_tree = std::ref(storage.serial_patch_tree.get());
376 }));
377
379 .set_edges(graph.get_edge_ptr<SerialPatchTreeRefEdge<TgridVec>>("sptree"));
380
381 storage.local_patch_ids
382 = std::make_shared<shamrock::solvergraph::IDataEdge<std::vector<u64>>>("", "");
383
384 storage.sim_box_edge
385 = std::make_shared<shamrock::solvergraph::ScalarEdge<shammath::AABB<TgridVec>>>(
386 "sim_box", "sim_box");
387
388 storage.exchange_gz_edge = std::make_shared<shamrock::solvergraph::PatchDataLayerDDShared>(
389 "exchange_gz_edge", "exchange_gz_edge");
390
391 storage.idx_in_ghost = std::make_shared<shamrock::solvergraph::DDSharedBuffers<u32>>(
392 "idx_in_ghost", "idx_in_ghost");
393
394 storage.ghost_layers_candidates_edge = std::make_shared<
396 "ghost_layers_candidates", "ghost_layers_candidates");
397
398 storage.patch_rank_owner = std::make_shared<shamrock::solvergraph::RankGetter>(
399 [&](u64 patch_id) -> u32 {
400 return scheduler().get_patch_rank_owner(patch_id);
401 },
402 "patch_rank_owner",
403 "rank");
404
405 storage.source_patches = std::make_shared<shamrock::solvergraph::PatchDataLayerRefs>(
406 "source_patches", "P_{\\rm source}");
407
408 storage.merged_patchdata_ghost = std::make_shared<shamrock::solvergraph::PatchDataLayerEdge>(
409 "merged_patchdata_ghost", "patchdata_{\\rm ghost}", storage.ghost_layout);
410
411 storage.block_counts
412 = std::make_shared<shamrock::solvergraph::Indexes<u32>>("block_count", "N_{\\rm block}");
413
414 storage.block_counts_with_ghost = std::make_shared<shamrock::solvergraph::Indexes<u32>>(
415 "block_count_with_ghost", "N_{\\rm block, with ghost}");
416
417 // merged ghost spans
418 storage.refs_block_min = std::make_shared<shamrock::solvergraph::FieldRefs<TgridVec>>(
419 "block_min", "\\mathbf{r}_{\\rm block, min}");
420 storage.refs_block_max = std::make_shared<shamrock::solvergraph::FieldRefs<TgridVec>>(
421 "block_max", "\\mathbf{r}_{\\rm block, max}");
422
423 storage.refs_rho = std::make_shared<shamrock::solvergraph::FieldRefs<Tscal>>("rho", "\\rho");
424 storage.refs_rhov
425 = std::make_shared<shamrock::solvergraph::FieldRefs<Tvec>>("rhovel", "(\\rho \\mathbf{v})");
426 storage.refs_rhoe
427 = std::make_shared<shamrock::solvergraph::FieldRefs<Tscal>>("rhoetot", "(\\rho E)");
428
429 if (solver_config.is_dust_on()) {
430 storage.refs_rho_dust = std::make_shared<shamrock::solvergraph::FieldRefs<Tscal>>(
431 "rho_dust", "\\rho_{\\rm dust}");
432 storage.refs_rhov_dust = std::make_shared<shamrock::solvergraph::FieldRefs<Tvec>>(
433 "rhovel_dust", "(\\rho_{\\rm dust} \\mathbf{v}_{\\rm dust})");
434 }
435
436 // will be filled by NodeConsToPrimGasAdiabatic or NodeConsToPrimGasBarotropic
437 storage.vel = std::make_shared<shamrock::solvergraph::Field<Tvec>>(
438 AMRBlock::block_size, "vel", "\\mathbf{v}");
439 storage.press
440 = std::make_shared<shamrock::solvergraph::Field<Tscal>>(AMRBlock::block_size, "P", "P");
441
442 if (!solver_config.amr_mode.old_amr) { // TODO disable also if amr is none
443 storage.rho_primitive = std::make_shared<shamrock::solvergraph::Field<Tscal>>(
444 AMRBlock::block_size, "rho-prim", "rho-prim");
445 }
446
447 // will be filled only if valid refinement criterion is provided
448 using AMRmode_None = typename AMRMode<Tvec, TgridVec>::None;
449 if (std::get_if<AMRmode_None>(&solver_config.amr_mode.config) == nullptr) {
450 storage.rho_snap = std::make_shared<shamrock::solvergraph::Field<Tscal>>(
451 AMRBlock::block_size, "rho_snap", "rho_snap");
452 storage.rhoe_snap = std::make_shared<shamrock::solvergraph::Field<Tscal>>(
453 AMRBlock::block_size, "rhoe_snap", "rhoe_snap");
454 storage.rho_vel_snap = std::make_shared<shamrock::solvergraph::Field<Tvec>>(
455 AMRBlock::block_size, "rhov_snap", "rhov_snap");
456 }
457
458 if (solver_config.is_dust_on()) {
459 u32 ndust = solver_config.dust_config.ndust;
460
461 // will be filled by NodeConsToPrimDust
462 storage.vel_dust = std::make_shared<shamrock::solvergraph::Field<Tvec>>(
463 AMRBlock::block_size * ndust, "vel_dust", "{\\mathbf{v}_{\\rm dust}}");
464 }
465
466 storage.trees
467 = std::make_shared<solvergraph::TreeEdge<u_morton, TgridVec>>("trees", "\\text{trees}");
468
469 storage.block_graph_edge = std::make_shared<
471 "block_graph_edge", "\\text{block graph edge}");
472
473 storage.cell_graph_edge = std::make_shared<
475 "cell_graph_edge", "\\text{cell graph edge}");
476
477 // will be filled by NodeComputeCellAABB
478 storage.block_cell_sizes = std::make_shared<shamrock::solvergraph::Field<Tscal>>(
479 1, "block_cell_sizes", "s_{\\rm cell}");
480 storage.cell0block_aabb_lower = std::make_shared<shamrock::solvergraph::Field<Tvec>>(
481 1, "cell0block_aabb_lower", "\\mathbf{s}_{\\rm inf,block}");
482
483 if (solver_config.is_coordinate_field_required()) {
484 // will be filled by NodeComputeCoordinates
485 storage.coordinates = std::make_shared<shamrock::solvergraph::Field<Tvec>>(
486 AMRBlock::block_size, "coordinates", "\\mathbf{r}");
487 }
488
489 if (solver_config.amr_mode.need_level_zero_compute()) {
490 // get blocks at level0 sizes for all patches
491 storage.level0_size = std::make_shared<shamrock::solvergraph::ScalarsEdge<TgridVec>>(
492 "level0_amr", "level0_amr");
493 }
494
495 if (solver_config.amr_mode.need_amr_level_compute()) {
496 using TgridUint = typename std::make_unsigned<shambase::VecComponent<TgridVec>>::type;
497 storage.amr_block_levels
498 = std::make_shared<shamrock::solvergraph::Field<TgridUint>>(1, "", "");
499 }
500
501 storage.grad_rho = std::make_shared<shamrock::solvergraph::Field<Tvec>>(
502 AMRBlock::block_size, "grad_rho", "\\nabla \\rho");
503 storage.dx_v = std::make_shared<shamrock::solvergraph::Field<Tvec>>(
504 AMRBlock::block_size, "dx_v", "\\nabla_x \\mathbf{v}");
505 storage.dy_v = std::make_shared<shamrock::solvergraph::Field<Tvec>>(
506 AMRBlock::block_size, "dy_v", "\\nabla_y \\mathbf{v}");
507 storage.dz_v = std::make_shared<shamrock::solvergraph::Field<Tvec>>(
508 AMRBlock::block_size, "dz_v", "\\nabla_z \\mathbf{v}");
509 storage.grad_P = std::make_shared<shamrock::solvergraph::Field<Tvec>>(
510 AMRBlock::block_size, "grad_P", "\\nabla P");
511
512 // will be filled by NodeEulerTimeDerivativeGasAdiabatic or NodeEulerTimeDerivativeGasBarotropic
513 // euler_dt_press exists only for an adiabatic hydro step (Adiabatic EOS):
514 // with the Barotropic EOS the face pressure is recomputed from the face density, so no
515 // pressure time derivative is needed
516 storage.euler_dt_rho = std::make_shared<shamrock::solvergraph::Field<Tscal>>(
517 AMRBlock::block_size, "euler_dt_rho", "\\partial_t \\rho");
518 storage.euler_dt_vel = std::make_shared<shamrock::solvergraph::Field<Tvec>>(
519 AMRBlock::block_size, "euler_dt_vel", "\\partial_t \\mathbf{v}");
520 if (solver_config.eos_config.is_hydro_adiabatic()) {
521 storage.euler_dt_press = std::make_shared<shamrock::solvergraph::Field<Tscal>>(
522 AMRBlock::block_size, "euler_dt_press", "\\partial_t P");
523 }
524
525 if (solver_config.is_dust_on()) {
526 u32 ndust = solver_config.dust_config.ndust;
527 storage.grad_rho_dust = std::make_shared<shamrock::solvergraph::Field<Tvec>>(
528 AMRBlock::block_size * ndust, "grad_rho_dust", "\\nabla \\rho_{\\rm dust}");
529 storage.dx_v_dust = std::make_shared<shamrock::solvergraph::Field<Tvec>>(
530 AMRBlock::block_size * ndust, "dx_v_dust", "\\nabla_x \\mathbf{v}_{\\rm dust}");
531 storage.dy_v_dust = std::make_shared<shamrock::solvergraph::Field<Tvec>>(
532 AMRBlock::block_size * ndust, "dy_v_dust", "\\nabla_y \\mathbf{v}_{\\rm dust}");
533 storage.dz_v_dust = std::make_shared<shamrock::solvergraph::Field<Tvec>>(
534 AMRBlock::block_size * ndust, "dz_v_dust", "\\nabla_z \\mathbf{v}_{\\rm dust}");
535
536 // will be filled by NodeEulerTimeDerivativeDust
537 storage.euler_dt_rho_dust = std::make_shared<shamrock::solvergraph::Field<Tscal>>(
538 AMRBlock::block_size * ndust, "euler_dt_rho_dust", "\\partial_t \\rho_{\\rm dust}");
539 storage.euler_dt_vel_dust = std::make_shared<shamrock::solvergraph::Field<Tvec>>(
540 AMRBlock::block_size * ndust,
541 "euler_dt_vel_dust",
542 "\\partial_t \\mathbf{v}_{\\rm dust}");
543 }
544
545 {
546
547 storage.rho_face_xp
548 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tscal, 2>>>(
549 "rho_face_xp", "rho_face_xp", 1);
550 storage.rho_face_xm
551 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tscal, 2>>>(
552 "rho_face_xm", "rho_face_xm", 1);
553 storage.rho_face_yp
554 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tscal, 2>>>(
555 "rho_face_yp", "rho_face_yp", 1);
556 storage.rho_face_ym
557 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tscal, 2>>>(
558 "rho_face_ym", "rho_face_ym", 1);
559 storage.rho_face_zp
560 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tscal, 2>>>(
561 "rho_face_zp", "rho_face_zp", 1);
562 storage.rho_face_zm
563 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tscal, 2>>>(
564 "rho_face_zm", "rho_face_zm", 1);
565
566 storage.vel_face_xp
567 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tvec, 2>>>(
568 "vel_face_xp", "vel_face_xp", 1);
569 storage.vel_face_xm
570 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tvec, 2>>>(
571 "vel_face_xm", "vel_face_xm", 1);
572 storage.vel_face_yp
573 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tvec, 2>>>(
574 "vel_face_yp", "vel_face_yp", 1);
575 storage.vel_face_ym
576 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tvec, 2>>>(
577 "vel_face_ym", "vel_face_ym", 1);
578 storage.vel_face_zp
579 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tvec, 2>>>(
580 "vel_face_zp", "vel_face_zp", 1);
581 storage.vel_face_zm
582 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tvec, 2>>>(
583 "vel_face_zm", "vel_face_zm", 1);
584
585 storage.press_face_xp
586 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tscal, 2>>>(
587 "press_face_xp", "press_face_xp", 1);
588 storage.press_face_xm
589 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tscal, 2>>>(
590 "press_face_xm", "press_face_xm", 1);
591 storage.press_face_yp
592 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tscal, 2>>>(
593 "press_face_yp", "press_face_yp", 1);
594 storage.press_face_ym
595 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tscal, 2>>>(
596 "press_face_ym", "press_face_ym", 1);
597 storage.press_face_zp
598 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tscal, 2>>>(
599 "press_face_zp", "press_face_zp", 1);
600 storage.press_face_zm
601 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tscal, 2>>>(
602 "press_face_zm", "press_face_zm", 1);
603 }
604
605 if (solver_config.is_dust_on()) {
606 u32 ndust = solver_config.dust_config.ndust;
607
608 storage.rho_dust_face_xp
609 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tscal, 2>>>(
610 "rho_dust_face_xp", "rho_dust_face_xp", ndust);
611 storage.rho_dust_face_xm
612 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tscal, 2>>>(
613 "rho_dust_face_xm", "rho_dust_face_xm", ndust);
614 storage.rho_dust_face_yp
615 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tscal, 2>>>(
616 "rho_dust_face_yp", "rho_dust_face_yp", ndust);
617 storage.rho_dust_face_ym
618 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tscal, 2>>>(
619 "rho_dust_face_ym", "rho_dust_face_ym", ndust);
620 storage.rho_dust_face_zp
621 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tscal, 2>>>(
622 "rho_dust_face_zp", "rho_dust_face_zp", ndust);
623 storage.rho_dust_face_zm
624 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tscal, 2>>>(
625 "rho_dust_face_zm", "rho_dust_face_zm", ndust);
626
627 storage.vel_dust_face_xp
628 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tvec, 2>>>(
629 "vel_dust_face_xp", "vel_dust_face_xp", ndust);
630 storage.vel_dust_face_xm
631 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tvec, 2>>>(
632 "vel_dust_face_xm", "vel_dust_face_xm", ndust);
633 storage.vel_dust_face_yp
634 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tvec, 2>>>(
635 "vel_dust_face_yp", "vel_dust_face_yp", ndust);
636 storage.vel_dust_face_ym
637 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tvec, 2>>>(
638 "vel_dust_face_ym", "vel_dust_face_ym", ndust);
639 storage.vel_dust_face_zp
640 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tvec, 2>>>(
641 "vel_dust_face_zp", "vel_dust_face_zp", ndust);
642 storage.vel_dust_face_zm
643 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<std::array<Tvec, 2>>>(
644 "vel_dust_face_zm", "vel_dust_face_zm", ndust);
645 }
646
647 if (solver_config.should_compute_rho_mean()) {
648 storage.cell_mass = std::make_shared<shamrock::solvergraph::Field<Tscal>>(
649 AMRBlock::block_size, "cell_mass", "m");
650 storage.rho_mean
651 = std::make_shared<shamrock::solvergraph::ScalarEdge<Tscal>>("rho_mean", "< \\rho >");
652 storage.simulation_volume = std::make_shared<shamrock::solvergraph::ScalarEdge<Tscal>>(
653 "simulation_volume", "V_{\\rm sim}");
654 }
655
656 storage.dt = std::make_shared<shamrock::solvergraph::ScalarEdge<Tscal>>("dt", "\\Delta t");
657 storage.dt_over2
658 = std::make_shared<shamrock::solvergraph::ScalarEdge<Tscal>>("dt_half", "dt_{half}");
659
660 {
661
662 storage.flux_rho_face_xm = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tscal>>(
663 "flux_rho_face_xm", "flux_rho_face_xm", 1);
664
665 storage.flux_rho_face_xp = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tscal>>(
666 "flux_rho_face_xp", "flux_rho_face_xp", 1);
667
668 storage.flux_rho_face_ym = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tscal>>(
669 "flux_rho_face_ym", "flux_rho_face_ym", 1);
670
671 storage.flux_rho_face_yp = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tscal>>(
672 "flux_rho_face_yp", "flux_rho_face_yp", 1);
673
674 storage.flux_rho_face_zm = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tscal>>(
675 "flux_rho_face_zm", "flux_rho_face_zm", 1);
676
677 storage.flux_rho_face_zp = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tscal>>(
678 "flux_rho_face_zp", "flux_rho_face_zp", 1);
679
680 storage.flux_rhov_face_xm = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tvec>>(
681 "flux_rhov_face_xm", "flux_rhov_face_xm", 1);
682
683 storage.flux_rhov_face_xp = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tvec>>(
684 "flux_rhov_face_xp", "flux_rhov_face_xp", 1);
685
686 storage.flux_rhov_face_ym = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tvec>>(
687 "flux_rhov_face_ym", "flux_rhov_face_ym", 1);
688
689 storage.flux_rhov_face_yp = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tvec>>(
690 "flux_rhov_face_yp", "flux_rhov_face_yp", 1);
691
692 storage.flux_rhov_face_zm = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tvec>>(
693 "flux_rhov_face_zm", "flux_rhov_face_zm", 1);
694
695 storage.flux_rhov_face_zp = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tvec>>(
696 "flux_rhov_face_zp", "flux_rhov_face_zp", 1);
697
698 storage.flux_rhoe_face_xm = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tscal>>(
699 "flux_rhoe_face_xm", "flux_rhoe_face_xm", 1);
700
701 storage.flux_rhoe_face_xp = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tscal>>(
702 "flux_rhoe_face_xp", "flux_rhoe_face_xp", 1);
703
704 storage.flux_rhoe_face_ym = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tscal>>(
705 "flux_rhoe_face_ym", "flux_rhoe_face_ym", 1);
706
707 storage.flux_rhoe_face_yp = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tscal>>(
708 "flux_rhoe_face_yp", "flux_rhoe_face_yp", 1);
709
710 storage.flux_rhoe_face_zm = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tscal>>(
711 "flux_rhoe_face_zm", "flux_rhoe_face_zm", 1);
712
713 storage.flux_rhoe_face_zp = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tscal>>(
714 "flux_rhoe_face_zp", "flux_rhoe_face_zp", 1);
715 }
716
717 if (solver_config.is_dust_on()) {
718 u32 ndust = solver_config.dust_config.ndust;
719
720 storage.flux_rho_dust_face_xm
721 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tscal>>(
722 "flux_rho_dust_face_xm", "flux_rho_dust_face_xm", ndust);
723
724 storage.flux_rho_dust_face_xp
725 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tscal>>(
726 "flux_rho_dust_face_xp", "flux_rho_dust_face_xp", ndust);
727
728 storage.flux_rho_dust_face_ym
729 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tscal>>(
730 "flux_rho_dust_face_ym", "flux_rho_dust_face_ym", ndust);
731
732 storage.flux_rho_dust_face_yp
733 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tscal>>(
734 "flux_rho_dust_face_yp", "flux_rho_dust_face_yp", ndust);
735
736 storage.flux_rho_dust_face_zm
737 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tscal>>(
738 "flux_rho_dust_face_zm", "flux_rho_dust_face_zm", ndust);
739
740 storage.flux_rho_dust_face_zp
741 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tscal>>(
742 "flux_rho_dust_face_zp", "flux_rho_dust_face_zp", ndust);
743
744 storage.flux_rhov_dust_face_xm
745 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tvec>>(
746 "flux_rhov_dust_face_xm", "flux_rhov_dust_face_xm", ndust);
747
748 storage.flux_rhov_dust_face_xp
749 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tvec>>(
750 "flux_rhov_dust_face_xp", "flux_rhov_dust_face_xp", ndust);
751
752 storage.flux_rhov_dust_face_ym
753 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tvec>>(
754 "flux_rhov_dust_face_ym", "flux_rhov_dust_face_ym", ndust);
755
756 storage.flux_rhov_dust_face_yp
757 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tvec>>(
758 "flux_rhov_dust_face_yp", "flux_rhov_dust_face_yp", ndust);
759
760 storage.flux_rhov_dust_face_zm
761 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tvec>>(
762 "flux_rhov_dust_face_zm", "flux_rhov_dust_face_zm", ndust);
763
764 storage.flux_rhov_dust_face_zp
765 = std::make_shared<solvergraph::NeighGraphLinkFieldEdge<Tvec>>(
766 "flux_rhov_dust_face_zp", "flux_rhov_dust_face_zp", ndust);
767 }
768
769 storage.dtrho = std::make_shared<shamrock::solvergraph::Field<Tscal>>(
770 AMRBlock::block_size, "dtrho", "dtrho");
771 storage.dtrhov = std::make_shared<shamrock::solvergraph::Field<Tvec>>(
772 AMRBlock::block_size, "dtrhov", "dtrhov");
773 storage.dtrhoe = std::make_shared<shamrock::solvergraph::Field<Tscal>>(
774 AMRBlock::block_size, "dtrhoe", "dtrhoe");
775
776 if (solver_config.is_dust_on()) {
777 u32 ndust = solver_config.dust_config.ndust;
778 storage.dtrho_dust = std::make_shared<shamrock::solvergraph::Field<Tscal>>(
779 AMRBlock::block_size * ndust, "dtrho_dust", "dtrho_dust");
780 storage.dtrhov_dust = std::make_shared<shamrock::solvergraph::Field<Tvec>>(
781 AMRBlock::block_size * ndust, "dtrhov_dust", "dtrhov_dust");
782 }
783
787 std::vector<std::shared_ptr<shamrock::solvergraph::INode>> solver_sequence;
788
789 solver_sequence.push_back(graph.get_node_ptr_base("set_sptree"));
790
791 auto cfg_bc_to_geom = [](BCConfig::GhostType ghost_type) {
792 switch (ghost_type) {
793 case BCConfig::GhostType::Periodic : return modules::GhostType::Periodic;
794 case BCConfig::GhostType::Reflective: return modules::GhostType::Reflective;
795 case BCConfig::GhostType::Outflow : return modules::GhostType::Reflective;
796 default:
798 "Unsupported ghost type: " + std::to_string(static_cast<int>(ghost_type)));
799 }
800 };
801
802 modules::GhostLayerGenMode ghost_layer_gen_mode{
803 cfg_bc_to_geom(solver_config.bc_config.get_x()),
804 cfg_bc_to_geom(solver_config.bc_config.get_y()),
805 cfg_bc_to_geom(solver_config.bc_config.get_z())};
806
807 // if outflow we want zero gradient so we skip the vector transformation in TransformGhostLayer
808 bool transform_vec_x = solver_config.bc_config.get_x() != BCConfig::GhostType::Outflow;
809 bool transform_vec_y = solver_config.bc_config.get_y() != BCConfig::GhostType::Outflow;
810 bool transform_vec_z = solver_config.bc_config.get_z() != BCConfig::GhostType::Outflow;
811
812 { // Ghost zone finder
813
814 modules::FindGhostLayerCandidates<TgridVec> find_ghost_layer_candidates(
815 ghost_layer_gen_mode);
816 find_ghost_layer_candidates.set_edges(
817 storage.local_patch_ids,
818 storage.sim_box_edge,
820 graph.get_edge_ptr<ScalarsEdge<shammath::AABB<TgridVec>>>("global_patch_boxes"),
821 storage.ghost_layers_candidates_edge);
822 solver_sequence.push_back(
823 std::make_shared<decltype(find_ghost_layer_candidates)>(
824 std::move(find_ghost_layer_candidates)));
825
826 modules::FindGhostLayerIndices<TgridVec> find_ghost_layer_indices(ghost_layer_gen_mode);
827 find_ghost_layer_indices.set_edges(
828 storage.sim_box_edge,
829 storage.source_patches,
830 storage.ghost_layers_candidates_edge,
831 graph.get_edge_ptr<ScalarsEdge<shammath::AABB<TgridVec>>>("global_patch_boxes"),
832 storage.idx_in_ghost);
833 solver_sequence.push_back(
834 std::make_shared<decltype(find_ghost_layer_indices)>(
835 std::move(find_ghost_layer_indices)));
836 }
837
838 { // Ghost zone exchange
839 std::vector<std::shared_ptr<shamrock::solvergraph::INode>> gz_xchg_sequence;
840
841 auto &ghost_layout_ptr = storage.ghost_layout;
842 {
843 auto copy_fields = std::make_shared<shamrock::solvergraph::CopyPatchDataLayerFields>(
844 scheduler().get_layout_ptr_old(), ghost_layout_ptr);
845
846 copy_fields->set_edges(storage.source_patches, storage.merged_patchdata_ghost);
847 gz_xchg_sequence.push_back(std::move(copy_fields));
848 }
849
850 {
851 auto extract_gz_node
852 = std::make_shared<shammodels::basegodunov::modules::ExtractGhostLayer>(
853 ghost_layout_ptr);
854
855 extract_gz_node->set_edges(
856 storage.merged_patchdata_ghost, storage.idx_in_ghost, storage.exchange_gz_edge);
857 gz_xchg_sequence.push_back(std::move(extract_gz_node));
858 }
859
860 {
861 auto transform_gz_node = std::make_shared<
863 ghost_layer_gen_mode,
864 transform_vec_x,
865 transform_vec_y,
866 transform_vec_z,
867 ghost_layout_ptr);
868
869 transform_gz_node->set_edges(
870 storage.sim_box_edge,
871 storage.ghost_layers_candidates_edge,
872 storage.exchange_gz_edge);
873 gz_xchg_sequence.push_back(std::move(transform_gz_node));
874 }
875
876 {
877 auto exchange_gz_node
878 = std::make_shared<shamrock::solvergraph::ExchangeGhostLayer>(ghost_layout_ptr);
879 exchange_gz_node->set_edges(storage.patch_rank_owner, storage.exchange_gz_edge);
880 gz_xchg_sequence.push_back(std::move(exchange_gz_node));
881 }
882
883 {
884 auto fuse_gz_node
885 = std::make_shared<shammodels::basegodunov::modules::FuseGhostLayer>();
886 fuse_gz_node->set_edges(storage.exchange_gz_edge, storage.merged_patchdata_ghost);
887 gz_xchg_sequence.push_back(std::move(fuse_gz_node));
888 }
889
890 // enable this to debug GZ
891 //{
892 // auto filename_edge = std::make_shared<shamrock::solvergraph::IDataEdge<std::string>>(
893 // "debug_fuse.vtk", "debug_fuse.vtk");
894 // filename_edge->data = "debug_fuse.vtk";
895 //
896 // auto patch_data_layer_to_vtk_node
897 // = std::make_shared<PatchDataLayerToVtk<Tvec, TgridVec>>(true, true, 8);
898 // patch_data_layer_to_vtk_node->set_edges(filename_edge,
899 // storage.merged_patchdata_ghost);
900 // gz_xchg_sequence.push_back(std::move(patch_data_layer_to_vtk_node));
901 //}
902
904 "Ghost zone exchange", std::move(gz_xchg_sequence));
905 solver_sequence.push_back(std::make_shared<decltype(seq)>(std::move(seq)));
906 }
907
908 { // attach fields with ghosts
909
910 { // set element counts
911 shamrock::solvergraph::ExtractCounts extract_counts_node
913 extract_counts_node.set_edges(storage.source_patches, storage.block_counts);
914 solver_sequence.push_back(
915 std::make_shared<decltype(extract_counts_node)>(std::move(extract_counts_node)));
916 }
917
918 { // set element counts
919 shamrock::solvergraph::ExtractCounts extract_counts_node
921 extract_counts_node.set_edges(
922 storage.merged_patchdata_ghost, storage.block_counts_with_ghost);
923 solver_sequence.push_back(
924 std::make_shared<decltype(extract_counts_node)>(std::move(extract_counts_node)));
925 }
926
927 { // Attach spans to block coords
930 attach_block_min.set_edges(storage.merged_patchdata_ghost, storage.refs_block_min);
931 solver_sequence.push_back(
932 std::make_shared<decltype(attach_block_min)>(std::move(attach_block_min)));
933
936 attach_block_max.set_edges(storage.merged_patchdata_ghost, storage.refs_block_max);
937 solver_sequence.push_back(
938 std::make_shared<decltype(attach_block_max)>(std::move(attach_block_max)));
939 }
940
941 { // attach spans to gas field with ghosts
943 = shamrock::solvergraph::GetFieldRefFromLayer<Tscal>(storage.ghost_layout, "rho");
944 attach_rho.set_edges(storage.merged_patchdata_ghost, storage.refs_rho);
945 solver_sequence.push_back(
946 std::make_shared<decltype(attach_rho)>(std::move(attach_rho)));
947
949 = shamrock::solvergraph::GetFieldRefFromLayer<Tvec>(storage.ghost_layout, "rhovel");
950 attach_rhov.set_edges(storage.merged_patchdata_ghost, storage.refs_rhov);
951 solver_sequence.push_back(
952 std::make_shared<decltype(attach_rhov)>(std::move(attach_rhov)));
953
956 storage.ghost_layout, "rhoetot");
957 attach_rhoe.set_edges(storage.merged_patchdata_ghost, storage.refs_rhoe);
958 solver_sequence.push_back(
959 std::make_shared<decltype(attach_rhoe)>(std::move(attach_rhoe)));
960 }
961
962 if (solver_config.is_dust_on()) { // attach spans to dust field with ghosts
965 storage.ghost_layout, "rho_dust");
966 attach_rho_dust.set_edges(storage.merged_patchdata_ghost, storage.refs_rho_dust);
967 solver_sequence.push_back(
968 std::make_shared<decltype(attach_rho_dust)>(std::move(attach_rho_dust)));
969
972 storage.ghost_layout, "rhovel_dust");
973 attach_rhov_dust.set_edges(storage.merged_patchdata_ghost, storage.refs_rhov_dust);
974 solver_sequence.push_back(
975 std::make_shared<decltype(attach_rhov_dust)>(std::move(attach_rhov_dust)));
976 }
977 }
978
979 { // build trees
980
982 node.set_edges(
983 storage.block_counts_with_ghost,
984 storage.refs_block_min,
985 storage.refs_block_max,
986 storage.trees);
987
988 solver_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
989 }
990
991 { // build neigh tables
992 std::vector<std::shared_ptr<shamrock::solvergraph::INode>> neigh_table_sequence;
993
995 node1.set_edges(
996 storage.block_counts_with_ghost,
997 storage.refs_block_min,
998 storage.refs_block_max,
999 storage.trees,
1000 storage.block_graph_edge);
1001 node1.evaluate();
1002
1004 node2.set_edges(
1005 storage.block_counts_with_ghost,
1006 storage.refs_block_min,
1007 storage.refs_block_max,
1008 storage.block_graph_edge,
1009 storage.cell_graph_edge);
1010 node2.evaluate();
1011
1012 neigh_table_sequence.push_back(std::make_shared<decltype(node1)>(std::move(node1)));
1013 get_optional_free_mem(storage.trees, neigh_table_sequence);
1014 neigh_table_sequence.push_back(std::make_shared<decltype(node2)>(std::move(node2)));
1015 get_optional_free_mem(storage.block_graph_edge, neigh_table_sequence);
1016
1018 "Compute neigh table", std::move(neigh_table_sequence));
1019 solver_sequence.push_back(std::make_shared<decltype(seq)>(std::move(seq)));
1020 }
1021
1022 { // Compute cell infos
1023
1025 AMRBlock::Nside, solver_config.grid_coord_to_pos_fact};
1026
1027 node.set_edges(
1028 storage.block_counts_with_ghost,
1029 storage.refs_block_min,
1030 storage.refs_block_max,
1031 storage.block_cell_sizes,
1032 storage.cell0block_aabb_lower);
1033 solver_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1034 }
1035
1036 if (solver_config.is_coordinate_field_required()) { // Compute coordinates
1037
1039 AMRBlock::block_size,
1040 AMRBlock::Nside,
1041 solver_config.grid_coord_to_pos_fact,
1042 };
1043
1044 node_coordinates.set_edges(
1045 storage.block_counts,
1046 storage.refs_block_min,
1047 storage.refs_block_max,
1048 storage.coordinates);
1049
1050 solver_sequence.push_back(
1051 std::make_shared<decltype(node_coordinates)>(std::move(node_coordinates)));
1052 }
1053
1054 if (solver_config.amr_mode.need_level_zero_compute()) { // compute level0 sizes in patch (to be
1055 // enabled later when needed)
1056 modules::ComputeLevel0CellSize<TgridVec> node_level0_sizes{};
1057 node_level0_sizes.set_edges(
1058 graph.get_edge_ptr<ScalarsEdge<shammath::AABB<TgridVec>>>("global_patch_boxes"),
1059 storage.source_patches,
1060 storage.level0_size);
1061 solver_sequence.push_back(
1062 std::make_shared<decltype(node_level0_sizes)>(std::move(node_level0_sizes)));
1063 }
1064
1065 if (solver_config.amr_mode.need_amr_level_compute()) { // compute block amr level in patch
1066 modules::ComputeAMRLevel<TgridVec> node_amr_level{};
1067 node_amr_level.set_edges(
1068 storage.block_counts,
1069 storage.level0_size,
1070 storage.refs_block_min,
1071 storage.refs_block_max,
1072 storage.amr_block_levels);
1073 solver_sequence.push_back(
1074 std::make_shared<decltype(node_amr_level)>(std::move(node_amr_level)));
1075 }
1076
1077 if (solver_config.should_compute_rho_mean()) {
1078 modules::NodeComputeMass<Tvec, TgridVec> node{AMRBlock::block_size};
1079 node.set_edges(
1080 storage.block_counts, storage.block_cell_sizes, storage.refs_rho, storage.cell_mass);
1081 solver_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1082
1083 modules::NodeComputeSumOverV<Tscal> node2{AMRBlock::block_size};
1084 node2.set_edges(
1085 storage.block_counts, storage.cell_mass, storage.simulation_volume, storage.rho_mean);
1086 solver_sequence.push_back(std::make_shared<decltype(node2)>(std::move(node2)));
1087 }
1088
1089 { // Build ConsToPrim node
1090 std::vector<std::shared_ptr<shamrock::solvergraph::INode>> const_to_prim_sequence;
1091
1092 auto push_adiabatic_node = [&](Tscal gamma) {
1093 modules::NodeConsToPrimGasAdiabatic<Tvec> node{AMRBlock::block_size, gamma};
1094 node.set_edges(
1095 storage.block_counts_with_ghost,
1096 storage.refs_rho,
1097 storage.refs_rhov,
1098 storage.refs_rhoe,
1099 storage.vel,
1100 storage.press);
1101
1102 const_to_prim_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1103 };
1104
1105 using EOS = EOSConfig<Tvec>;
1106 std::visit(
1108 [&](const typename EOS::Adiabatic &cfg) {
1109 push_adiabatic_node(cfg.gamma);
1110 },
1111 [&](const typename EOS::Barotropic &cfg) {
1113 AMRBlock::block_size, cfg.rho_crit, cfg.cs0, cfg.gamma};
1114 node.set_edges(
1115 storage.block_counts_with_ghost,
1116 storage.refs_rho,
1117 storage.refs_rhov,
1118 storage.vel,
1119 storage.press);
1120
1121 const_to_prim_sequence.push_back(
1122 std::make_shared<decltype(node)>(std::move(node)));
1123 },
1124 },
1125 solver_config.eos_config.config);
1126
1127 if (solver_config.is_dust_on()) {
1128 u32 ndust = solver_config.dust_config.ndust;
1129 modules::NodeConsToPrimDust<Tvec> node{AMRBlock::block_size, ndust};
1130 node.set_edges(
1131 storage.block_counts_with_ghost,
1132 storage.refs_rho_dust,
1133 storage.refs_rhov_dust,
1134 storage.vel_dust);
1135
1136 const_to_prim_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1137 }
1138
1140 "Cons to Prim", std::move(const_to_prim_sequence));
1141 solver_sequence.push_back(std::make_shared<decltype(seq)>(std::move(seq)));
1142 }
1143
1144 { // Build slope limited gradients
1145
1146 std::vector<std::shared_ptr<shamrock::solvergraph::INode>> grad_sequence;
1147
1148 {
1150 AMRBlock::block_size, 1, solver_config.slope_config};
1151 node.set_edges(
1152 storage.block_counts_with_ghost,
1153 storage.cell_graph_edge,
1154 storage.block_cell_sizes,
1155 storage.refs_rho,
1156 storage.grad_rho);
1157 grad_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1158 }
1159
1160 {
1162 AMRBlock::block_size, 1, solver_config.slope_config};
1163 node.set_edges(
1164 storage.block_counts_with_ghost,
1165 storage.cell_graph_edge,
1166 storage.block_cell_sizes,
1167 storage.vel,
1168 storage.dx_v,
1169 storage.dy_v,
1170 storage.dz_v);
1171 grad_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1172 }
1173 {
1175 AMRBlock::block_size, 1, solver_config.slope_config};
1176 node.set_edges(
1177 storage.block_counts_with_ghost,
1178 storage.cell_graph_edge,
1179 storage.block_cell_sizes,
1180 storage.press,
1181 storage.grad_P);
1182 grad_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1183 }
1184
1185 if (solver_config.is_dust_on()) {
1186 u32 ndust = solver_config.dust_config.ndust;
1188 AMRBlock::block_size, ndust, solver_config.slope_config};
1189 node.set_edges(
1190 storage.block_counts_with_ghost,
1191 storage.cell_graph_edge,
1192 storage.block_cell_sizes,
1193 storage.refs_rho_dust,
1194 storage.grad_rho_dust);
1195 grad_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1196
1198 AMRBlock::block_size, ndust, solver_config.slope_config};
1199 node2.set_edges(
1200 storage.block_counts_with_ghost,
1201 storage.cell_graph_edge,
1202 storage.block_cell_sizes,
1203 storage.vel_dust,
1204 storage.dx_v_dust,
1205 storage.dy_v_dust,
1206 storage.dz_v_dust);
1207 grad_sequence.push_back(std::make_shared<decltype(node2)>(std::move(node2)));
1208 }
1209
1211 "Slope limited gradients", std::move(grad_sequence));
1212 solver_sequence.push_back(std::make_shared<decltype(seq)>(std::move(seq)));
1213 }
1214
1215 { // Euler time derivatives of the primitive state
1216 // Hoisted out of the face interpolation nodes: they only depend on cell
1217 // local quantities, so computing them once per cell here avoids
1218 // re-fetching the velocity gradients for every face link.
1219 std::vector<std::shared_ptr<shamrock::solvergraph::INode>> dt_prim_sequence;
1220
1221 {
1222 auto push_adiabatic_node = [&](Tscal gamma) {
1224 AMRBlock::block_size, gamma};
1225 node.set_edges(
1226 storage.block_counts_with_ghost,
1227 storage.refs_rho,
1228 storage.vel,
1229 storage.press,
1230 storage.grad_rho,
1231 storage.dx_v,
1232 storage.dy_v,
1233 storage.dz_v,
1234 storage.grad_P,
1235 storage.euler_dt_rho,
1236 storage.euler_dt_vel,
1237 storage.euler_dt_press);
1238 dt_prim_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1239 };
1240
1241 using EOS = EOSConfig<Tvec>;
1242 std::visit(
1244 [&](const typename EOS::Adiabatic &cfg) {
1245 push_adiabatic_node(cfg.gamma);
1246 },
1247 [&](const typename EOS::Barotropic &) {
1249 AMRBlock::block_size};
1250 node.set_edges(
1251 storage.block_counts_with_ghost,
1252 storage.refs_rho,
1253 storage.vel,
1254 storage.grad_rho,
1255 storage.dx_v,
1256 storage.dy_v,
1257 storage.dz_v,
1258 storage.grad_P,
1259 storage.euler_dt_rho,
1260 storage.euler_dt_vel);
1261 dt_prim_sequence.push_back(
1262 std::make_shared<decltype(node)>(std::move(node)));
1263 },
1264 },
1265 solver_config.eos_config.config);
1266 }
1267
1268 if (solver_config.is_dust_on()) {
1269 u32 ndust = solver_config.dust_config.ndust;
1270 modules::NodeEulerTimeDerivativeDust<Tvec> node{AMRBlock::block_size, ndust};
1271 node.set_edges(
1272 storage.block_counts_with_ghost,
1273 storage.refs_rho_dust,
1274 storage.vel_dust,
1275 storage.grad_rho_dust,
1276 storage.dx_v_dust,
1277 storage.dy_v_dust,
1278 storage.dz_v_dust,
1279 storage.euler_dt_rho_dust,
1280 storage.euler_dt_vel_dust);
1281 dt_prim_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1282 }
1283
1285 "Euler time derivatives", std::move(dt_prim_sequence));
1286 solver_sequence.push_back(std::make_shared<decltype(seq)>(std::move(seq)));
1287 }
1288
1289 { // interpolate to face
1290 std::vector<std::shared_ptr<shamrock::solvergraph::INode>> interp_sequence;
1291 {
1292 modules::InterpolateToFaceRho<Tvec, TgridVec> node{AMRBlock::block_size};
1293 node.set_edges(
1294 storage.dt_over2,
1295 storage.cell_graph_edge,
1296 storage.block_cell_sizes,
1297 storage.cell0block_aabb_lower,
1298 storage.refs_rho,
1299 storage.grad_rho,
1300 storage.euler_dt_rho,
1301 storage.rho_face_xp,
1302 storage.rho_face_xm,
1303 storage.rho_face_yp,
1304 storage.rho_face_ym,
1305 storage.rho_face_zp,
1306 storage.rho_face_zm);
1307 interp_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1308 }
1309
1310 {
1311 modules::InterpolateToFaceVel<Tvec, TgridVec> node{AMRBlock::block_size};
1312 node.set_edges(
1313 storage.dt_over2,
1314 storage.cell_graph_edge,
1315 storage.block_cell_sizes,
1316 storage.cell0block_aabb_lower,
1317 storage.vel,
1318 storage.dx_v,
1319 storage.dy_v,
1320 storage.dz_v,
1321 storage.euler_dt_vel,
1322 storage.vel_face_xp,
1323 storage.vel_face_xm,
1324 storage.vel_face_yp,
1325 storage.vel_face_ym,
1326 storage.vel_face_zp,
1327 storage.vel_face_zm);
1328 interp_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1329 }
1330
1331 // with the Barotropic EOS the face pressure is recomputed from the face density, so it is
1332 // not interpolated (and euler_dt_press does not exist)
1333 if (solver_config.eos_config.is_hydro_adiabatic()) {
1334 modules::InterpolateToFacePress<Tvec, TgridVec> node{AMRBlock::block_size};
1335 node.set_edges(
1336 storage.dt_over2,
1337 storage.cell_graph_edge,
1338 storage.block_cell_sizes,
1339 storage.cell0block_aabb_lower,
1340 storage.press,
1341 storage.grad_P,
1342 storage.euler_dt_press,
1343 storage.press_face_xp,
1344 storage.press_face_xm,
1345 storage.press_face_yp,
1346 storage.press_face_ym,
1347 storage.press_face_zp,
1348 storage.press_face_zm);
1349 interp_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1350 }
1351
1352 if (solver_config.is_dust_on()) {
1353 u32 ndust = solver_config.dust_config.ndust;
1354 modules::InterpolateToFaceRhoDust<Tvec, TgridVec> node{AMRBlock::block_size, ndust};
1355 node.set_edges(
1356 storage.dt_over2,
1357 storage.cell_graph_edge,
1358 storage.block_cell_sizes,
1359 storage.cell0block_aabb_lower,
1360 storage.refs_rho_dust,
1361 storage.grad_rho_dust,
1362 storage.euler_dt_rho_dust,
1363 storage.rho_dust_face_xp,
1364 storage.rho_dust_face_xm,
1365 storage.rho_dust_face_yp,
1366 storage.rho_dust_face_ym,
1367 storage.rho_dust_face_zp,
1368 storage.rho_dust_face_zm);
1369 interp_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1370 }
1371
1372 if (solver_config.is_dust_on()) {
1373 u32 ndust = solver_config.dust_config.ndust;
1374 modules::InterpolateToFaceVelDust<Tvec, TgridVec> node{AMRBlock::block_size, ndust};
1375 node.set_edges(
1376 storage.dt_over2,
1377 storage.cell_graph_edge,
1378 storage.block_cell_sizes,
1379 storage.cell0block_aabb_lower,
1380 storage.vel_dust,
1381 storage.dx_v_dust,
1382 storage.dy_v_dust,
1383 storage.dz_v_dust,
1384 storage.euler_dt_vel_dust,
1385 storage.vel_dust_face_xp,
1386 storage.vel_dust_face_xm,
1387 storage.vel_dust_face_yp,
1388 storage.vel_dust_face_ym,
1389 storage.vel_dust_face_zp,
1390 storage.vel_dust_face_zm);
1391 interp_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1392 }
1393
1395 "Interpolate to face", std::move(interp_sequence));
1396 solver_sequence.push_back(std::make_shared<decltype(seq)>(std::move(seq)));
1397 }
1398
1399 { // flux
1400
1401 std::vector<std::shared_ptr<shamrock::solvergraph::INode>> flux_sequence;
1402
1403 // Build the gas flux node for the Riemann solver mode carried by `mode_tag`
1404 auto push_gas_flux_node = [&](auto mode_tag) {
1405 constexpr modules::RiemannSolverMode mode = decltype(mode_tag)::value;
1407 "Gas flux compute",
1408 solver_config.get_eos_gamma(),
1409 storage.cell_graph_edge,
1410 storage.rho_face_xp,
1411 storage.rho_face_xm,
1412 storage.rho_face_yp,
1413 storage.rho_face_ym,
1414 storage.rho_face_zp,
1415 storage.rho_face_zm,
1416 storage.vel_face_xp,
1417 storage.vel_face_xm,
1418 storage.vel_face_yp,
1419 storage.vel_face_ym,
1420 storage.vel_face_zp,
1421 storage.vel_face_zm,
1422 storage.press_face_xp,
1423 storage.press_face_xm,
1424 storage.press_face_yp,
1425 storage.press_face_ym,
1426 storage.press_face_zp,
1427 storage.press_face_zm,
1428 storage.flux_rho_face_xp,
1429 storage.flux_rho_face_xm,
1430 storage.flux_rho_face_yp,
1431 storage.flux_rho_face_ym,
1432 storage.flux_rho_face_zp,
1433 storage.flux_rho_face_zm,
1434 storage.flux_rhov_face_xp,
1435 storage.flux_rhov_face_xm,
1436 storage.flux_rhov_face_yp,
1437 storage.flux_rhov_face_ym,
1438 storage.flux_rhov_face_zp,
1439 storage.flux_rhov_face_zm,
1440 storage.flux_rhoe_face_xp,
1441 storage.flux_rhoe_face_xm,
1442 storage.flux_rhoe_face_yp,
1443 storage.flux_rhoe_face_ym,
1444 storage.flux_rhoe_face_zp,
1445 storage.flux_rhoe_face_zm);
1446 flux_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1447 };
1448
1449 using RSM = modules::RiemannSolverMode;
1450 switch (solver_config.riemann_config) {
1451 case RSM::Rusanov: push_gas_flux_node(std::integral_constant<RSM, RSM::Rusanov>{}); break;
1452 case RSM::HLL : push_gas_flux_node(std::integral_constant<RSM, RSM::HLL>{}); break;
1453 case RSM::HLLC_PVRS:
1454 push_gas_flux_node(std::integral_constant<RSM, RSM::HLLC_PVRS>{});
1455 break;
1456 case RSM::HLLC_Davis:
1457 push_gas_flux_node(std::integral_constant<RSM, RSM::HLLC_Davis>{});
1458 break;
1459 case RSM::HLLC_RAMSES:
1460 push_gas_flux_node(std::integral_constant<RSM, RSM::HLLC_RAMSES>{});
1461 break;
1462 default: shambase::throw_unimplemented("unknown flux mode");
1463 }
1464
1465 if (solver_config.is_dust_on()) {
1466 u32 ndust = solver_config.dust_config.ndust;
1467 if (solver_config.dust_config.dust_riemann_config == DHLL) {
1468 modules::
1469 NodeComputeFluxDustMode<Tvec, TgridVec, modules::DustRiemannSolverMode::DHLL>
1470 node(
1471 "Dust flux compute",
1472 ndust,
1473 storage.cell_graph_edge,
1474 storage.rho_dust_face_xp,
1475 storage.rho_dust_face_xm,
1476 storage.rho_dust_face_yp,
1477 storage.rho_dust_face_ym,
1478 storage.rho_dust_face_zp,
1479 storage.rho_dust_face_zm,
1480 storage.vel_dust_face_xp,
1481 storage.vel_dust_face_xm,
1482 storage.vel_dust_face_yp,
1483 storage.vel_dust_face_ym,
1484 storage.vel_dust_face_zp,
1485 storage.vel_dust_face_zm,
1486 storage.flux_rho_dust_face_xp,
1487 storage.flux_rho_dust_face_xm,
1488 storage.flux_rho_dust_face_yp,
1489 storage.flux_rho_dust_face_ym,
1490 storage.flux_rho_dust_face_zp,
1491 storage.flux_rho_dust_face_zm,
1492 storage.flux_rhov_dust_face_xp,
1493 storage.flux_rhov_dust_face_xm,
1494 storage.flux_rhov_dust_face_yp,
1495 storage.flux_rhov_dust_face_ym,
1496 storage.flux_rhov_dust_face_zp,
1497 storage.flux_rhov_dust_face_zm);
1498 flux_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1499 } else if (solver_config.dust_config.dust_riemann_config == HB) {
1501 node(
1502 "Dust flux compute",
1503 ndust,
1504 storage.cell_graph_edge,
1505 storage.rho_dust_face_xp,
1506 storage.rho_dust_face_xm,
1507 storage.rho_dust_face_yp,
1508 storage.rho_dust_face_ym,
1509 storage.rho_dust_face_zp,
1510 storage.rho_dust_face_zm,
1511 storage.vel_dust_face_xp,
1512 storage.vel_dust_face_xm,
1513 storage.vel_dust_face_yp,
1514 storage.vel_dust_face_ym,
1515 storage.vel_dust_face_zp,
1516 storage.vel_dust_face_zm,
1517 storage.flux_rho_dust_face_xp,
1518 storage.flux_rho_dust_face_xm,
1519 storage.flux_rho_dust_face_yp,
1520 storage.flux_rho_dust_face_ym,
1521 storage.flux_rho_dust_face_zp,
1522 storage.flux_rho_dust_face_zm,
1523 storage.flux_rhov_dust_face_xp,
1524 storage.flux_rhov_dust_face_xm,
1525 storage.flux_rhov_dust_face_yp,
1526 storage.flux_rhov_dust_face_ym,
1527 storage.flux_rhov_dust_face_zp,
1528 storage.flux_rhov_dust_face_zm);
1529 flux_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1530 } else {
1531 shambase::throw_unimplemented("unknown flux mode");
1532 }
1533 }
1534
1535 shamrock::solvergraph::OperationSequence seq("Compute fluxes", std::move(flux_sequence));
1536 solver_sequence.push_back(std::make_shared<decltype(seq)>(std::move(seq)));
1537 }
1538
1539 {
1541 AMRBlock::block_size, solver_config.grid_coord_to_pos_fact};
1542 node.set_edges(
1543 storage.block_counts,
1544 storage.cell_graph_edge,
1545 storage.block_cell_sizes,
1546 storage.cell0block_aabb_lower,
1547 storage.flux_rho_face_xp,
1548 storage.flux_rho_face_xm,
1549 storage.flux_rho_face_yp,
1550 storage.flux_rho_face_ym,
1551 storage.flux_rho_face_zp,
1552 storage.flux_rho_face_zm,
1553 storage.flux_rhov_face_xp,
1554 storage.flux_rhov_face_xm,
1555 storage.flux_rhov_face_yp,
1556 storage.flux_rhov_face_ym,
1557 storage.flux_rhov_face_zp,
1558 storage.flux_rhov_face_zm,
1559 storage.flux_rhoe_face_xp,
1560 storage.flux_rhoe_face_xm,
1561 storage.flux_rhoe_face_yp,
1562 storage.flux_rhoe_face_ym,
1563 storage.flux_rhoe_face_zp,
1564 storage.flux_rhoe_face_zm,
1565 storage.dtrho,
1566 storage.dtrhov,
1567 storage.dtrhoe);
1568 solver_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1569 }
1570
1571 if (solver_config.is_dust_on()) {
1573 AMRBlock::block_size,
1574 solver_config.grid_coord_to_pos_fact,
1575 solver_config.dust_config.ndust};
1576 node.set_edges(
1577 storage.block_counts,
1578 storage.cell_graph_edge,
1579 storage.block_cell_sizes,
1580 storage.cell0block_aabb_lower,
1581 storage.flux_rho_dust_face_xp,
1582 storage.flux_rho_dust_face_xm,
1583 storage.flux_rho_dust_face_yp,
1584 storage.flux_rho_dust_face_ym,
1585 storage.flux_rho_dust_face_zp,
1586 storage.flux_rho_dust_face_zm,
1587 storage.flux_rhov_dust_face_xp,
1588 storage.flux_rhov_dust_face_xm,
1589 storage.flux_rhov_dust_face_yp,
1590 storage.flux_rhov_dust_face_ym,
1591 storage.flux_rhov_dust_face_zp,
1592 storage.flux_rhov_dust_face_zm,
1593 storage.dtrho_dust,
1594 storage.dtrhov_dust);
1595 solver_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1596 }
1597
1598 if (solver_config.has_ext_forces() || solver_config.is_gravity_on()) { // external forces
1599
1600 // The external forces are applied to the state at t^n (patch data without ghosts) before
1601 // the time integration, so that they are taken into account by every integrator (with or
1602 // without drag). Self-gravity is one of them.
1603
1604 using ExtForceConfig = typename Config::ExtForceConfig;
1605 using ConstantGravity = typename ExtForceConfig::ConstantGravity;
1606 using PointMassGravity = typename ExtForceConfig::PointMassGravity;
1607
1608 const bool trapezoidal
1609 = solver_config.ext_force_config.coupling == ExtForceCoupling::Trapezoidal;
1610
1611 std::vector<std::shared_ptr<shamrock::solvergraph::INode>> ext_force_sequence;
1612
1613 if (trapezoidal) {
1614 storage.a_ext = std::make_shared<shamrock::solvergraph::Field<Tvec>>(
1615 AMRBlock::block_size, "a_ext", "\\mathbf{a}_{\\rm ext}^{n}");
1616 storage.a_ext_next = std::make_shared<shamrock::solvergraph::Field<Tvec>>(
1617 AMRBlock::block_size, "a_ext_next", "\\mathbf{a}_{\\rm ext}^{n+1}");
1618 } else {
1619 storage.a_ext = std::make_shared<shamrock::solvergraph::Field<Tvec>>(
1620 AMRBlock::block_size, "a_ext", "\\mathbf{a}_{\\rm ext}");
1621 }
1622
1623 // accelerations at the time levels required by the coupling, paired with the time of the
1624 // level after t^n in units of dt (the state there is U^n + dt_level * dt * dU/dt):
1625 // t^{n+1/2} for the midpoint rule, t^n and t^{n+1} for the trapezoidal rule
1626 std::vector<std::pair<std::shared_ptr<shamrock::solvergraph::Field<Tvec>>, Tscal>>
1627 a_ext_levels;
1628 if (trapezoidal) {
1629 a_ext_levels.push_back({storage.a_ext, Tscal{0}});
1630 a_ext_levels.push_back({storage.a_ext_next, Tscal{1}});
1631 } else {
1632 a_ext_levels.push_back({storage.a_ext, Tscal{0.5}});
1633 }
1634
1635 // sum of the accelerations of all the forces, at each level
1636 for (auto &[a_ext_level, dt_level] : a_ext_levels) {
1637 modules::ResetExtForceAcc<Tvec> node{AMRBlock::block_size};
1638 node.set_edges(storage.block_counts, a_ext_level);
1639 ext_force_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1640 }
1641
1642 shamrock::patch::PatchDataLayerLayout &pdl = scheduler().pdl_old();
1643
1644 // refs to the fields of the patch data without ghosts (the ones that are integrated)
1645 auto attach_source_field = [&]<class T>(
1646 std::shared_ptr<shamrock::solvergraph::FieldRefs<T>> &refs,
1647 const std::string &field_name) {
1648 shamrock::solvergraph::GetFieldRefFromLayer<T> attach{pdl, field_name};
1649 attach.set_edges(storage.source_patches, refs);
1650 ext_force_sequence.push_back(std::make_shared<decltype(attach)>(std::move(attach)));
1651 };
1652
1653 if (solver_config.is_gravity_on()) {
1654 if (trapezoidal) {
1655 // Self-gravity scheme of the `new_amr_plus_grav` branch of Léodasce Sewanou (from
1656 // #1942): g^n is computed from rho^n and g^{n+1} from rho^{n+1} = rho^n + dt
1657 // drho/dt, known before the kick, then the momentum and energy get the trapezoidal
1658 // kick of ApplyExtForceGasTrapezoidal (the update of its NodeGetNextConsVar).
1659 const u32 block_size = AMRBlock::block_size;
1660
1661 storage.refs_phi = std::make_shared<FieldRefs<Tscal>>("phi_old", "\\phi^{n}");
1662 storage.refs_phi_new = std::make_shared<FieldRefs<Tscal>>("phi", "\\phi^{n+1}");
1663 storage.rho_next
1664 = std::make_shared<Field<Tscal>>(block_size, "rho_next", "\\rho^{n+1}");
1665 storage.phi_g
1666 = std::make_shared<Field<Tvec>>(block_size, "phi_g", "\\mathbf{g}_{\\rm sg}");
1667
1668 auto &work = storage.poisson_work;
1669 auto field = [&](const std::string &name) {
1670 return std::make_shared<Field<Tscal>>(block_size, name, name);
1671 };
1672 auto scal = [&](const std::string &name) {
1673 return IDataEdge<Tscal>::make_shared(name, name);
1674 };
1675 work.res = field("phi_res");
1676 work.res_bis = field("phi_res_bis");
1677 work.p = field("phi_p");
1678 work.a_p = field("phi_Ap");
1679 work.s = field("phi_s");
1680 work.a_s = field("phi_As");
1681 work.z = field("phi_z");
1682 work.rhs = field("phi_rhs");
1683 work.hadamard_prod = field("phi_hadamard_prod");
1684 work.rz_hadamard_prod = field("rz_hadamard_prod");
1685 work.old_values = scal("old_values");
1686 work.new_values = scal("new_values");
1687 work.e_norm = scal("e_norm");
1688 work.alpha = scal("alpha");
1689 work.beta = scal("beta");
1690 work.w_stab = scal("w_stab");
1691 work.shadow_res_norm = scal("shadow_res_norm");
1692 work.rhs_norm = scal("rhs_norm");
1693 work.rz_old_values = scal("rz_old_values");
1694 work.rz_new_values = scal("rz_new_values");
1695
1696 // mean density subtracted from the Poisson source term, zero if the boundaries
1697 // are not periodic (as in the reference)
1698 std::shared_ptr<ScalarEdge<Tscal>> rho_mean_n, rho_mean_np1;
1699 if (solver_config.should_compute_rho_mean()) {
1700 storage.rho_mean_next
1701 = std::make_shared<ScalarEdge<Tscal>>("rho_mean_next", "< \\rho^{n+1} >");
1702 rho_mean_n = storage.rho_mean;
1703 rho_mean_np1 = storage.rho_mean_next;
1704 } else {
1705 rho_mean_n = std::make_shared<ScalarEdge<Tscal>>("rho_mean_zero", "0");
1706 rho_mean_n->value = 0;
1707 rho_mean_np1 = rho_mean_n;
1708 }
1709
1710 // phi^n and phi^{n+1} with ghosts, they start from the values of the previous step
1711 // (warm start of the Poisson solvers)
1712 {
1713 GetFieldRefFromLayer<Tscal> attach_phi{storage.ghost_layout, "phi_old"};
1714 attach_phi.set_edges(storage.merged_patchdata_ghost, storage.refs_phi);
1715 ext_force_sequence.push_back(
1716 std::make_shared<decltype(attach_phi)>(std::move(attach_phi)));
1717
1718 GetFieldRefFromLayer<Tscal> attach_phi_new{storage.ghost_layout, "phi"};
1719 attach_phi_new.set_edges(storage.merged_patchdata_ghost, storage.refs_phi_new);
1720 ext_force_sequence.push_back(
1721 std::make_shared<decltype(attach_phi_new)>(std::move(attach_phi_new)));
1722 }
1723
1724 for (auto &[a_ext_level, dt_level] : a_ext_levels) {
1725
1726 std::shared_ptr<IFieldSpan<Tscal>> rho_level;
1727 std::shared_ptr<ScalarEdge<Tscal>> rho_mean_level;
1728 std::shared_ptr<FieldRefs<Tscal>> phi_level;
1729
1730 if (dt_level == 0) {
1731 rho_level = storage.refs_rho;
1732 rho_mean_level = rho_mean_n;
1733 phi_level = storage.refs_phi;
1734 } else if (dt_level == 1) {
1735 // rho^{n+1} = rho^n + dt drho/dt on the patch cells, the ghost cells keep
1736 // rho^n (the reference updated rho^n in place on the patch cells only)
1737 modules::ComputeNextRho<Tvec> node_rho_next{block_size};
1738 node_rho_next.set_edges(
1739 storage.dt,
1740 storage.block_counts,
1741 storage.block_counts_with_ghost,
1742 storage.refs_rho,
1743 storage.dtrho,
1744 storage.rho_next);
1745 ext_force_sequence.push_back(
1746 std::make_shared<decltype(node_rho_next)>(std::move(node_rho_next)));
1747
1748 if (solver_config.should_compute_rho_mean()) {
1749 modules::NodeComputeMass<Tvec, TgridVec> node_mass{block_size};
1750 node_mass.set_edges(
1751 storage.block_counts,
1752 storage.block_cell_sizes,
1753 storage.rho_next,
1754 storage.cell_mass);
1755 ext_force_sequence.push_back(
1756 std::make_shared<decltype(node_mass)>(std::move(node_mass)));
1757
1758 modules::NodeComputeSumOverV<Tscal> node_mean{block_size};
1759 node_mean.set_edges(
1760 storage.block_counts,
1761 storage.cell_mass,
1762 storage.simulation_volume,
1763 storage.rho_mean_next);
1764 ext_force_sequence.push_back(
1765 std::make_shared<decltype(node_mean)>(std::move(node_mean)));
1766 }
1767
1768 rho_level = storage.rho_next;
1769 rho_mean_level = rho_mean_np1;
1770 phi_level = storage.refs_phi_new;
1771 } else {
1773 sham::format("self-gravity at the time level t^n + {} dt", dt_level));
1774 }
1775
1776 // Poisson solve, the solvers end with the ghost exchange of phi
1777 switch (solver_config.gravity_config.gravity_mode) {
1778 case CG: {
1780 block_size,
1781 solver_config.get_constant_4piG(),
1782 solver_config.gravity_config.Niter_max,
1783 solver_config.get_grav_tol()};
1784 node.set_edges(
1785 storage.block_counts_with_ghost,
1786 storage.block_counts,
1787 storage.cell_graph_edge,
1788 storage.block_cell_sizes,
1789 rho_level,
1790 rho_mean_level,
1791 storage.idx_in_ghost,
1792 storage.patch_rank_owner,
1793 phi_level,
1794 work.res,
1795 work.p,
1796 work.a_p,
1797 work.hadamard_prod,
1798 work.rhs,
1799 work.z,
1800 work.old_values,
1801 work.new_values,
1802 work.e_norm,
1803 work.alpha,
1804 work.beta,
1805 work.rhs_norm,
1806 work.rz_old_values,
1807 work.rz_new_values,
1808 work.rz_hadamard_prod);
1809 ext_force_sequence.push_back(
1810 std::make_shared<decltype(node)>(std::move(node)));
1811 break;
1812 }
1813 case BICGSTAB: {
1815 block_size,
1816 solver_config.get_constant_4piG(),
1817 solver_config.gravity_config.Niter_max,
1818 solver_config.get_grav_tol(),
1819 solver_config.get_happy_bk_grav_tol()};
1820 node.set_edges(
1821 storage.block_counts_with_ghost,
1822 storage.block_counts,
1823 storage.cell_graph_edge,
1824 storage.block_cell_sizes,
1825 rho_level,
1826 rho_mean_level,
1827 storage.idx_in_ghost,
1828 storage.patch_rank_owner,
1829 phi_level,
1830 work.res,
1831 work.res_bis,
1832 work.p,
1833 work.a_p,
1834 work.s,
1835 work.a_s,
1836 work.hadamard_prod,
1837 work.old_values,
1838 work.new_values,
1839 work.e_norm,
1840 work.alpha,
1841 work.beta,
1842 work.w_stab,
1843 work.shadow_res_norm,
1844 work.rhs,
1845 work.rhs_norm);
1846 ext_force_sequence.push_back(
1847 std::make_shared<decltype(node)>(std::move(node)));
1848 break;
1849 }
1850 default:
1852 "self-gravity: only the cg and bicgstab Poisson solvers are "
1853 "implemented");
1854 }
1855
1856 // g = -grad phi on the patch cells (the stencil reads the ghost cells)
1857 {
1859 node.set_edges(
1860 storage.block_counts,
1861 storage.cell_graph_edge,
1862 storage.block_cell_sizes,
1863 phi_level,
1864 storage.phi_g);
1865 ext_force_sequence.push_back(
1866 std::make_shared<decltype(node)>(std::move(node)));
1867 }
1868
1869 {
1870 modules::AddExtForceField<Tvec> node{block_size};
1871 node.set_edges(storage.block_counts, storage.phi_g, a_ext_level);
1872 ext_force_sequence.push_back(
1873 std::make_shared<decltype(node)>(std::move(node)));
1874 }
1875 }
1876
1877 // save phi^n and phi^{n+1} in the patch data, as warm starts for the next step
1878 {
1879 auto refs_phi_source
1880 = std::make_shared<FieldRefs<Tscal>>("phi_old_source", "\\phi^{n}");
1881 auto refs_phi_new_source
1882 = std::make_shared<FieldRefs<Tscal>>("phi_source", "\\phi^{n+1}");
1883 attach_source_field(refs_phi_source, "phi_old");
1884 attach_source_field(refs_phi_new_source, "phi");
1885
1886 CopyPatchDataField<Tscal> copy_phi{};
1887 copy_phi.set_edges(storage.refs_phi, refs_phi_source);
1888 ext_force_sequence.push_back(
1889 std::make_shared<decltype(copy_phi)>(std::move(copy_phi)));
1890
1891 CopyPatchDataField<Tscal> copy_phi_new{};
1892 copy_phi_new.set_edges(storage.refs_phi_new, refs_phi_new_source);
1893 ext_force_sequence.push_back(
1894 std::make_shared<decltype(copy_phi_new)>(std::move(copy_phi_new)));
1895 }
1896 } else {
1898 "self-gravity requires the trapezoidal coupling of the external forces");
1899 }
1900 }
1901
1902 // Time at which the forces must be evaluated to keep the scheme second order in time:
1903 // - midpoint rule: at the half step t^{n+1/2}. This does not matter for a constant
1904 // acceleration, but velocity dependent forces would need the half step velocity,
1905 // including the half kick of the force itself (e.g. predictor-corrector, or implicit
1906 // midpoint for stiff or no-work forces).
1907 // - trapezoidal rule: at t^n and t^{n+1}. A force depending on the state at t^{n+1} must
1908 // only depend on the density there, which is known before the kick (this is the case
1909 // of self-gravity).
1910 for (const auto &var_force : solver_config.ext_force_config.ext_forces) {
1911 std::visit(
1913 [&](const ConstantGravity &cfg) {
1914 // time independent, the same g is added at every level
1915 for (auto &[a_ext_level, dt_level] : a_ext_levels) {
1917 AMRBlock::block_size, cfg.g};
1918 node.set_edges(storage.block_counts, a_ext_level);
1919 ext_force_sequence.push_back(
1920 std::make_shared<decltype(node)>(std::move(node)));
1921 }
1922 },
1923 [&](const PointMassGravity &cfg) {
1924 for (auto &[a_ext_level, dt_level] : a_ext_levels) {
1925
1926 // retrieve the value of G
1927 // TODO: move that somewhere else with a unitsystem edge for example
1928 auto constant_G
1929 = std::make_shared<shamrock::solvergraph::ScalarEdge<Tscal>>(
1930 "G", "G");
1931 constant_G->value = solver_config.get_constant_G();
1932
1934 AMRBlock::block_size, cfg.mass, cfg.pos, cfg.epsilon_soft};
1935 node.set_edges(
1936 storage.block_counts, storage.coordinates, constant_G, a_ext_level);
1937 ext_force_sequence.push_back(
1938 std::make_shared<decltype(node)>(std::move(node)));
1939 }
1940 },
1941 },
1942 var_force);
1943 }
1944
1945 { // apply to the gas
1946 auto refs_rho
1947 = std::make_shared<shamrock::solvergraph::FieldRefs<Tscal>>("rho_source", "\\rho");
1948 auto refs_rhov = std::make_shared<shamrock::solvergraph::FieldRefs<Tvec>>(
1949 "rhovel_source", "(\\rho \\mathbf{v})");
1950 auto refs_rhoe = std::make_shared<shamrock::solvergraph::FieldRefs<Tscal>>(
1951 "rhoetot_source", "(\\rho E)");
1952
1953 attach_source_field(refs_rho, "rho");
1954 attach_source_field(refs_rhov, "rhovel");
1955 attach_source_field(refs_rhoe, "rhoetot");
1956
1957 if (trapezoidal) {
1958 modules::ApplyExtForceGasTrapezoidal<Tvec> node{AMRBlock::block_size};
1959 node.set_edges(
1960 storage.dt,
1961 storage.block_counts,
1962 refs_rho,
1963 storage.dtrho,
1964 storage.dtrhov,
1965 storage.a_ext,
1966 storage.a_ext_next,
1967 refs_rhov,
1968 refs_rhoe);
1969 ext_force_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1970 } else {
1971 modules::ApplyExtForceGas<Tvec> node{AMRBlock::block_size};
1972 node.set_edges(
1973 storage.dt,
1974 storage.block_counts,
1975 refs_rho,
1976 storage.dtrho,
1977 storage.dtrhov,
1978 storage.a_ext,
1979 refs_rhov,
1980 refs_rhoe);
1981 ext_force_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
1982 }
1983 }
1984
1985 if (solver_config.is_dust_on()) { // apply to the dust
1986 auto refs_rho_dust = std::make_shared<shamrock::solvergraph::FieldRefs<Tscal>>(
1987 "rho_dust_source", "\\rho_{\\rm dust}");
1988 auto refs_rhov_dust = std::make_shared<shamrock::solvergraph::FieldRefs<Tvec>>(
1989 "rhovel_dust_source", "(\\rho_{\\rm dust} \\mathbf{v}_{\\rm dust})");
1990
1991 attach_source_field(refs_rho_dust, "rho_dust");
1992 attach_source_field(refs_rhov_dust, "rhovel_dust");
1993
1994 if (trapezoidal) {
1996 AMRBlock::block_size, solver_config.dust_config.ndust};
1997 node.set_edges(
1998 storage.dt,
1999 storage.block_counts,
2000 refs_rho_dust,
2001 storage.dtrho_dust,
2002 storage.a_ext,
2003 storage.a_ext_next,
2004 refs_rhov_dust);
2005 ext_force_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
2006 } else {
2008 AMRBlock::block_size, solver_config.dust_config.ndust};
2009 node.set_edges(
2010 storage.dt,
2011 storage.block_counts,
2012 refs_rho_dust,
2013 storage.dtrho_dust,
2014 storage.a_ext,
2015 refs_rhov_dust);
2016 ext_force_sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
2017 }
2018 }
2019
2021 "External forces", std::move(ext_force_sequence));
2022 solver_sequence.push_back(std::make_shared<decltype(seq)>(std::move(seq)));
2023 }
2024
2025 { // time integration (forward Euler, with or without drag)
2026
2027 shamrock::patch::PatchDataLayerLayout &pdl = scheduler().pdl_old();
2028
2029 // refs to the fields of the patch data without ghosts (the ones that are integrated)
2030 auto attach_source_field = [&]<class T>(
2031 std::vector<std::shared_ptr<INode>> &sequence,
2032 std::shared_ptr<FieldRefs<T>> &refs,
2033 const std::string &field_name) {
2034 GetFieldRefFromLayer<T> attach{pdl, field_name};
2035 attach.set_edges(storage.source_patches, refs);
2036 sequence.push_back(std::make_shared<decltype(attach)>(std::move(attach)));
2037 };
2038
2039 // U^{n+1} without drag starts as a copy of the state at t^n (patch data without ghosts),
2040 // then gets the forward Euler update in place
2041 auto add_forward_euler_before_drag = [&]() {
2042 const u32 ndust = solver_config.dust_config.ndust;
2043
2044 storage.rho_next_no_drag = std::make_shared<Field<Tscal>>(
2045 AMRBlock::block_size, "rho_next_bf_drag", "\\rho^{n+1}_{\\rm no\\,drag}");
2046 storage.rhov_next_no_drag = std::make_shared<Field<Tvec>>(
2047 AMRBlock::block_size,
2048 "rhov_next_bf_drag",
2049 "(\\rho \\mathbf{v})^{n+1}_{\\rm no\\,drag}");
2050 storage.rhoe_next_no_drag = std::make_shared<Field<Tscal>>(
2051 AMRBlock::block_size, "rhoe_next_bf_drag", "(\\rho E)^{n+1}_{\\rm no\\,drag}");
2052 storage.rho_d_next_no_drag = std::make_shared<Field<Tscal>>(
2053 ndust * AMRBlock::block_size,
2054 "rho_d_next_bf_drag",
2055 "\\rho^{n+1}_{\\rm dust,\\,no\\,drag}");
2056 storage.rhov_d_next_no_drag = std::make_shared<Field<Tvec>>(
2057 ndust * AMRBlock::block_size,
2058 "rhov_d_next_bf_drag",
2059 "(\\rho_{\\rm dust} \\mathbf{v}_{\\rm dust})^{n+1}_{\\rm no\\,drag}");
2060
2061 std::vector<std::shared_ptr<INode>> sequence;
2062
2063 auto copy_source_field = [&]<class T>(
2064 const std::string &field_name,
2065 const std::string &label,
2066 const std::string &tex,
2067 const std::shared_ptr<Field<T>> &target) {
2068 auto refs = std::make_shared<FieldRefs<T>>(label, tex);
2069 attach_source_field(sequence, refs, field_name);
2070
2071 CopyPatchDataField<T> copy{};
2072 copy.set_edges(refs, target);
2073 sequence.push_back(std::make_shared<decltype(copy)>(std::move(copy)));
2074 };
2075
2076 copy_source_field("rho", "rho_source", "\\rho", storage.rho_next_no_drag);
2077 copy_source_field(
2078 "rhovel", "rhovel_source", "(\\rho \\mathbf{v})", storage.rhov_next_no_drag);
2079 copy_source_field("rhoetot", "rhoetot_source", "(\\rho E)", storage.rhoe_next_no_drag);
2080 copy_source_field(
2081 "rho_dust", "rho_dust_source", "\\rho_{\\rm dust}", storage.rho_d_next_no_drag);
2082 copy_source_field(
2083 "rhovel_dust",
2084 "rhovel_dust_source",
2085 "(\\rho_{\\rm dust} \\mathbf{v}_{\\rm dust})",
2086 storage.rhov_d_next_no_drag);
2087
2088 {
2089 modules::ForwardEulerGas<Tvec> node{AMRBlock::block_size};
2090 node.set_edges(
2091 storage.dt,
2092 storage.block_counts,
2093 storage.dtrho,
2094 storage.dtrhov,
2095 storage.dtrhoe,
2096 storage.rho_next_no_drag,
2097 storage.rhov_next_no_drag,
2098 storage.rhoe_next_no_drag);
2099 sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
2100 }
2101
2102 {
2103 modules::ForwardEulerDust<Tvec> node{AMRBlock::block_size, ndust};
2104 node.set_edges(
2105 storage.dt,
2106 storage.block_counts,
2107 storage.dtrho_dust,
2108 storage.dtrhov_dust,
2109 storage.rho_d_next_no_drag,
2110 storage.rhov_d_next_no_drag);
2111 sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
2112 }
2113
2114 OperationSequence seq("Forward Euler before drag", std::move(sequence));
2115 solver_sequence.push_back(std::make_shared<decltype(seq)>(std::move(seq)));
2116 };
2117
2118 // apply the drag to U^{n+1} without drag, the result is written in the patch data
2119 auto add_drag = [&]<class NodeDrag>(const std::string &name) {
2120 const u32 ndust = solver_config.dust_config.ndust;
2121
2122 std::vector<std::shared_ptr<INode>> sequence;
2123
2124 auto refs_rho = std::make_shared<FieldRefs<Tscal>>("rho_source", "\\rho");
2125 auto refs_rhov
2126 = std::make_shared<FieldRefs<Tvec>>("rhovel_source", "(\\rho \\mathbf{v})");
2127 auto refs_rhoe = std::make_shared<FieldRefs<Tscal>>("rhoetot_source", "(\\rho E)");
2128 auto refs_rho_dust
2129 = std::make_shared<FieldRefs<Tscal>>("rho_dust_source", "\\rho_{\\rm dust}");
2130 auto refs_rhov_dust = std::make_shared<FieldRefs<Tvec>>(
2131 "rhovel_dust_source", "(\\rho_{\\rm dust} \\mathbf{v}_{\\rm dust})");
2132
2133 attach_source_field(sequence, refs_rho, "rho");
2134 attach_source_field(sequence, refs_rhov, "rhovel");
2135 attach_source_field(sequence, refs_rhoe, "rhoetot");
2136 attach_source_field(sequence, refs_rho_dust, "rho_dust");
2137 attach_source_field(sequence, refs_rhov_dust, "rhovel_dust");
2138
2139 {
2140 // alphas are dust collision rates
2141 const auto &alphas = solver_config.drag_config.alphas;
2142
2143 NodeDrag node{
2144 AMRBlock::block_size,
2145 ndust,
2146 std::vector<Tscal>(alphas.begin(), alphas.end()),
2147 solver_config.drag_config.enable_frictional_heating};
2148 node.set_edges(
2149 storage.dt,
2150 storage.block_counts,
2151 storage.rho_next_no_drag,
2152 storage.rhov_next_no_drag,
2153 storage.rhoe_next_no_drag,
2154 storage.rho_d_next_no_drag,
2155 storage.rhov_d_next_no_drag,
2156 refs_rho,
2157 refs_rhov,
2158 refs_rhoe,
2159 refs_rho_dust,
2160 refs_rhov_dust);
2161 sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
2162 }
2163
2164 OperationSequence seq(name, std::move(sequence));
2165 solver_sequence.push_back(std::make_shared<decltype(seq)>(std::move(seq)));
2166 };
2167
2168 if (solver_config.drag_config.drag_solver_config == DragSolverMode::NoDrag) {
2169
2170 std::vector<std::shared_ptr<INode>> sequence;
2171
2172 {
2173 auto refs_rho = std::make_shared<FieldRefs<Tscal>>("rho_source", "\\rho");
2174 auto refs_rhov
2175 = std::make_shared<FieldRefs<Tvec>>("rhovel_source", "(\\rho \\mathbf{v})");
2176 auto refs_rhoe = std::make_shared<FieldRefs<Tscal>>("rhoetot_source", "(\\rho E)");
2177
2178 attach_source_field(sequence, refs_rho, "rho");
2179 attach_source_field(sequence, refs_rhov, "rhovel");
2180 attach_source_field(sequence, refs_rhoe, "rhoetot");
2181
2182 modules::ForwardEulerGas<Tvec> node{AMRBlock::block_size};
2183 node.set_edges(
2184 storage.dt,
2185 storage.block_counts,
2186 storage.dtrho,
2187 storage.dtrhov,
2188 storage.dtrhoe,
2189 refs_rho,
2190 refs_rhov,
2191 refs_rhoe);
2192 sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
2193 }
2194
2195 if (solver_config.is_dust_on()) {
2196 auto refs_rho_dust
2197 = std::make_shared<FieldRefs<Tscal>>("rho_dust_source", "\\rho_{\\rm dust}");
2198 auto refs_rhov_dust = std::make_shared<FieldRefs<Tvec>>(
2199 "rhovel_dust_source", "(\\rho_{\\rm dust} \\mathbf{v}_{\\rm dust})");
2200
2201 attach_source_field(sequence, refs_rho_dust, "rho_dust");
2202 attach_source_field(sequence, refs_rhov_dust, "rhovel_dust");
2203
2205 AMRBlock::block_size, solver_config.dust_config.ndust};
2206 node.set_edges(
2207 storage.dt,
2208 storage.block_counts,
2209 storage.dtrho_dust,
2210 storage.dtrhov_dust,
2211 refs_rho_dust,
2212 refs_rhov_dust);
2213 sequence.push_back(std::make_shared<decltype(node)>(std::move(node)));
2214 }
2215
2216 OperationSequence seq("Forward Euler", std::move(sequence));
2217 solver_sequence.push_back(std::make_shared<decltype(seq)>(std::move(seq)));
2218
2219 } else if (solver_config.drag_config.drag_solver_config == DragSolverMode::IRK1) {
2220 add_forward_euler_before_drag();
2221 add_drag.template operator()<modules::ApplyDragIRK1<Tvec>>("Drag IRK1");
2222 } else if (solver_config.drag_config.drag_solver_config == DragSolverMode::EXPO) {
2223 add_forward_euler_before_drag();
2224 add_drag.template operator()<modules::ApplyDragExpo<Tvec>>("Drag expo");
2225 } else {
2227 }
2228 }
2229
2230 shamrock::solvergraph::OperationSequence seq("Solver", std::move(solver_sequence));
2231 storage.solver_sequence = std::make_shared<decltype(seq)>(std::move(seq));
2232
2233 if (false) {
2234 logger::raw_ln(" -- tex:\n" + shambase::get_check_ref(storage.solver_sequence).get_tex());
2236 " -- dot:\n" + shambase::get_check_ref(storage.solver_sequence).get_dot_graph());
2237 }
2238}
2239
2240template<class Tvec, class TgridVec>
2242
2243 StackEntry stack_loc{};
2244
2245 // has to be first since there is a barrier that may mess the other timers
2246 shamsys::SystemMetrics system_metrics_start = shamsys::get_system_metrics();
2247
2249 f64 mpi_timer_start = shamcomm::mpi::get_timer("total");
2250
2251 for (auto &callbacks : timestep_callbacks) {
2252 if (callbacks.step_begin_callback) {
2253 shambase::get_check_ref(callbacks.step_begin_callback)();
2254 }
2255 }
2256
2257 Tscal t_current = get_time();
2258 Tscal dt_input = get_dt();
2259
2260 if (shamcomm::world_rank() == 0) {
2261 logger::normal_ln("amr::Godunov", sham::format("t = {}, dt = {}", t_current, dt_input));
2262 }
2263
2264 shambase::get_check_ref(storage.dt).value = dt_input;
2265
2266 if (solver_config.face_half_time_interpolation) {
2267 shambase::get_check_ref(storage.dt_over2).value = dt_input / 2.0;
2268 }
2269
2270 shambase::Timer tstep;
2271 tstep.start();
2272
2273 // Scheduler step
2274 auto update_load_val = [&]() {
2275 shamlog_debug_ln("ComputeLoadBalanceValue", "update load balancing");
2276 scheduler().update_local_load_value([&](shamrock::patch::Patch p) {
2277 return scheduler().patch_data.owned_data.get(p.id_patch).get_obj_cnt();
2278 });
2279 };
2280 update_load_val();
2281 scheduler().scheduler_step(true, true);
2282 update_load_val();
2283 scheduler().scheduler_step(false, false);
2284
2285 if (solver_config.should_compute_rho_mean()) {
2286 auto [bmin, bmax] = scheduler().template get_box_volume<TgridVec>();
2287 Tscal dxfact = solver_config.grid_coord_to_pos_fact;
2288 Tvec dV = (bmax - bmin).template convert<Tscal>() * dxfact;
2289 Tscal Vsim = dV.x() * dV.y() * dV.z();
2290 shambase::get_check_ref(storage.simulation_volume).value = Vsim;
2291 }
2292
2294
2295 scheduler().for_each_patchdata_nonempty(
2297 storage.source_patches->patchdatas.add_obj(p.id_patch, std::ref(pdat));
2298 });
2299
2300 {
2301 shamrock::patch::SimulationBoxInfo &sim_box = scheduler().get_sim_box();
2302 auto [bmin, bmax] = sim_box.get_bounding_box<TgridVec>();
2303
2304 shambase::get_check_ref(storage.sim_box_edge).value = shammath::AABB<TgridVec>(bmin, bmax);
2305 }
2306
2307 SerialPatchTree<TgridVec> _sptree = SerialPatchTree<TgridVec>::build(scheduler());
2308 _sptree.attach_buf();
2309 storage.serial_patch_tree.set(std::move(_sptree));
2310
2314
2315 {
2316 auto &sim_box = scheduler().get_sim_box();
2317 auto transf = sim_box.template get_patch_transform<TgridVec>();
2318
2319 auto &global_patch_boxes_edge
2320 = shambase::get_check_ref(storage.solver_graph.template get_edge_ptr<
2322 "global_patch_boxes"));
2323
2324 global_patch_boxes_edge.values = {};
2325
2326 scheduler().for_each_global_patch([&](const shamrock::patch::Patch &p) {
2327 auto pbounds = transf.to_obj_coord(p);
2328 global_patch_boxes_edge.values.add_obj(
2329 p.id_patch, shammath::AABB<TgridVec>{pbounds.lower, pbounds.upper});
2330 });
2331 }
2332
2333 {
2334 auto &sim_box = scheduler().get_sim_box();
2335 auto transf = sim_box.template get_patch_transform<TgridVec>();
2336
2337 auto &local_patch_ids = shambase::get_check_ref(storage.local_patch_ids);
2338
2339 local_patch_ids.data = {};
2340
2341 scheduler().for_each_local_patch([&](const shamrock::patch::Patch &p) {
2342 local_patch_ids.data.push_back(p.id_patch);
2343 });
2344 }
2345
2349
2350 // Solvergraph evaluation
2351 {
2352 shambase::get_check_ref(storage.solver_sequence).evaluate();
2353 }
2354
2355 if (!solver_config.amr_mode.old_amr) {
2357 node_copy_rho.set_edges(storage.refs_rho, storage.rho_primitive);
2358 node_copy_rho.evaluate();
2359 }
2360
2361 // TODO: check if we can drop that
2362 if (dt_input > 0) {
2363 modules::AMRGridRefinementHandler refinement(context, solver_config, storage);
2364 if (solver_config.amr_mode.old_amr) {
2365 refinement.update_refinement_old();
2366 } else {
2367 using AMRmode_None = typename AMRMode<Tvec, TgridVec>::None;
2368 if (std::get_if<AMRmode_None>(&solver_config.amr_mode.config) == nullptr) {
2370 node_cpy_rho_snap.set_edges(storage.refs_rho, storage.rho_snap);
2371 node_cpy_rho_snap.evaluate();
2373 node_cpy_rhoe_snap.set_edges(storage.refs_rhoe, storage.rhoe_snap);
2374 node_cpy_rhoe_snap.evaluate();
2376 node_cpy_rho_vel_snap.set_edges(storage.refs_rhov, storage.rho_vel_snap);
2377 node_cpy_rho_vel_snap.evaluate();
2378 }
2379
2380 // Then refinement pass
2381 refinement.update_refinement_new();
2382 }
2383 }
2384
2385 // InstantBarotropic cooling: project the state onto the barotrope before the CFL. Done outside
2386 // of the dt_input > 0 branch so that the first step (dt_input = 0) also resets the initial
2387 // state
2388 if (std::holds_alternative<typename CoolingConfig<Tvec>::InstantBarotropic>(
2389 solver_config.cooling_config.config)) {
2390 modules::BarotropicEnergyReset energy_reset(context, solver_config, storage);
2391 energy_reset.reset_energy();
2392 }
2393
2394 modules::ComputeCFL cfl_compute(context, solver_config, storage);
2395 f64 new_dt = cfl_compute.compute_cfl();
2396
2397 // if new physics like dust is added then use the smallest dt
2398 if (solver_config.is_dust_on())
2399 new_dt = std::min(new_dt, cfl_compute.compute_dust_cfl());
2400
2401 set_next_dt(new_dt);
2402 set_time(t_current + dt_input);
2403
2404 if (solver_config.drag_config.drag_solver_config != DragSolverMode::NoDrag) {
2405 shambase::get_check_ref(storage.rho_next_no_drag).free_alloc();
2406 shambase::get_check_ref(storage.rhov_next_no_drag).free_alloc();
2407 shambase::get_check_ref(storage.rhoe_next_no_drag).free_alloc();
2408 shambase::get_check_ref(storage.rho_d_next_no_drag).free_alloc();
2409 shambase::get_check_ref(storage.rhov_d_next_no_drag).free_alloc();
2410 }
2411
2412 storage.merge_patch_bounds.reset();
2413
2414 storage.ghost_zone_infos.reset();
2415
2416 storage.serial_patch_tree.reset();
2417
2418 shambase::get_check_ref(storage.source_patches).free_alloc();
2419
2420 shambase::get_check_ref(storage.exchange_gz_edge).free_alloc();
2421 shambase::get_check_ref(storage.idx_in_ghost).free_alloc();
2422
2423 shambase::get_check_ref(storage.ghost_layers_candidates_edge).free_alloc();
2424
2425 tstep.stop();
2426
2427 for (auto it = timestep_callbacks.rbegin(); it != timestep_callbacks.rend(); ++it) {
2428 if (it->step_end_callback) {
2429 shambase::get_check_ref(it->step_end_callback)();
2430 }
2431 }
2432
2434
2435 shamsys::SystemMetrics system_metrics_end = shamsys::get_system_metrics();
2436 shamsys::SystemMetrics system_metrics_delta = system_metrics_end - system_metrics_start;
2437
2438 f64 delta_mpi_timer = shamcomm::mpi::get_timer("total") - mpi_timer_start;
2439 f64 t_dev_alloc
2440 = (mem_perf_infos_end.time_alloc_device - mem_perf_infos_start.time_alloc_device)
2441 + (mem_perf_infos_end.time_free_device - mem_perf_infos_start.time_free_device);
2442 f64 t_host_alloc = (mem_perf_infos_end.time_alloc_host - mem_perf_infos_start.time_alloc_host)
2443 + (mem_perf_infos_end.time_free_host - mem_perf_infos_start.time_free_host);
2444
2445 u64 rank_count = scheduler().get_rank_count() * AMRBlock::block_size;
2446 f64 rate = f64(rank_count) / tstep.elapsed_sec();
2447
2448 u64 npatch = scheduler().patch_list.local.size();
2449
2450 std::string log_step = report_perf_timestep(
2451 rate,
2452 rank_count,
2453 npatch,
2454 tstep.elapsed_sec(),
2455 delta_mpi_timer,
2456 t_dev_alloc,
2457 t_host_alloc,
2458 mem_perf_infos_end.max_allocated_byte_device,
2459 mem_perf_infos_end.max_allocated_byte_host,
2460 system_metrics_delta,
2461 shamsys::has_reporter());
2462
2463 if (shamcomm::world_rank() == 0) {
2464 logger::info_ln("amr::RAMSES", log_step);
2466 "amr::RAMSES",
2467 "estimated rate :",
2468 dt_input * (3600 / tstep.elapsed_sec()),
2469 "(tsim/hr)");
2470 }
2471
2472 solve_logs.register_log(
2473 {t_current, // f64 solver_t;
2474 dt_input, // f64 solver_dt;
2475 shamcomm::world_rank(), // i32 world_rank;
2476 rank_count, // u64 rank_count;
2477 rate, // f64 rate;
2478 tstep.elapsed_sec(), // f64 elapsed_sec;
2480 system_metrics_delta});
2481
2482 storage.timings_details.reset();
2483}
2484
2485template<class Tvec, class TgridVec>
2486void shammodels::basegodunov::Solver<Tvec, TgridVec>::do_debug_vtk_dump(std::string filename) {
2487
2488 StackEntry stack_loc{};
2489 shamrock::LegacyVtkWriter writer(filename, true, shamrock::UnstructuredGrid);
2490
2491 PatchScheduler &sched = shambase::get_check_ref(context.sched);
2492
2493 u32 block_size = Solver::AMRBlock::block_size;
2494
2495 u64 num_obj = sched.get_rank_count();
2496
2497 std::unique_ptr<sycl::buffer<TgridVec>> pos1 = sched.rankgather_field<TgridVec>(0);
2498 std::unique_ptr<sycl::buffer<TgridVec>> pos2 = sched.rankgather_field<TgridVec>(1);
2499
2500 sycl::buffer<Tvec> pos_min_cell(num_obj * block_size);
2501 sycl::buffer<Tvec> pos_max_cell(num_obj * block_size);
2502
2503 shamsys::instance::get_compute_queue().submit([&, block_size](sycl::handler &cgh) {
2504 sycl::accessor acc_p1{shambase::get_check_ref(pos1), cgh, sycl::read_only};
2505 sycl::accessor acc_p2{shambase::get_check_ref(pos2), cgh, sycl::read_only};
2506 sycl::accessor cell_min{pos_min_cell, cgh, sycl::write_only, sycl::no_init};
2507 sycl::accessor cell_max{pos_max_cell, cgh, sycl::write_only, sycl::no_init};
2508
2509 using Block = typename Solver::AMRBlock;
2510
2511 shambase::parallel_for(cgh, num_obj, "rescale cells", [=](u64 id_a) {
2512 Tvec block_min = acc_p1[id_a].template convert<Tscal>();
2513 Tvec block_max = acc_p2[id_a].template convert<Tscal>();
2514
2515 Tvec delta_cell = (block_max - block_min) / Block::side_size;
2516#pragma unroll
2517 for (u32 ix = 0; ix < Block::side_size; ix++) {
2518#pragma unroll
2519 for (u32 iy = 0; iy < Block::side_size; iy++) {
2520#pragma unroll
2521 for (u32 iz = 0; iz < Block::side_size; iz++) {
2522 u32 i = Block::get_index({ix, iy, iz});
2523 Tvec delta_val = delta_cell * Tvec{ix, iy, iz};
2524 cell_min[id_a * block_size + i] = block_min + delta_val;
2525 cell_max[id_a * block_size + i] = block_min + (delta_cell) + delta_val;
2526 }
2527 }
2528 }
2529 });
2530 });
2531
2532 writer.write_voxel_cells(pos_min_cell, pos_max_cell, num_obj * block_size);
2533
2534 writer.add_cell_data_section();
2535 writer.add_field_data_section(3);
2536
2537 std::unique_ptr<sycl::buffer<Tscal>> fields_rho = sched.rankgather_field<Tscal>(2);
2538 writer.write_field("rho", fields_rho, num_obj * block_size);
2539
2540 std::unique_ptr<sycl::buffer<Tvec>> fields_vel = sched.rankgather_field<Tvec>(3);
2541 writer.write_field("rhovel", fields_vel, num_obj * block_size);
2542
2543 std::unique_ptr<sycl::buffer<Tscal>> fields_eint = sched.rankgather_field<Tscal>(4);
2544 writer.write_field("rhoetot", fields_eint, num_obj * block_size);
2545 /*
2546 std::unique_ptr<sycl::buffer<Tvec>> grad_rho
2547 = storage.grad_rho.get().rankgather_computefield(sched);
2548 writer.write_field("grad_rho", grad_rho, num_obj * block_size);
2549
2550 std::unique_ptr<sycl::buffer<Tvec>> dx_v =
2551 storage.dx_v.get().rankgather_computefield(sched); writer.write_field("dx_v", dx_v,
2552 num_obj * block_size);
2553
2554 std::unique_ptr<sycl::buffer<Tvec>> dy_v =
2555 storage.dy_v.get().rankgather_computefield(sched); writer.write_field("dy_v", dy_v,
2556 num_obj * block_size);
2557
2558 std::unique_ptr<sycl::buffer<Tvec>> dz_v =
2559 storage.dz_v.get().rankgather_computefield(sched); writer.write_field("dz_v", dz_v,
2560 num_obj * block_size);
2561
2562 std::unique_ptr<sycl::buffer<Tvec>> grad_P
2563 = storage.grad_P.get().rankgather_computefield(sched);
2564 writer.write_field("grad_P", grad_P, num_obj * block_size);
2565 */
2566
2567 /*
2568 std::unique_ptr<sycl::buffer<Tscal>> dtrho =
2569 storage.dtrho.get().rankgather_computefield(sched); writer.write_field("dtrho", dtrho,
2570 num_obj * block_size);
2571
2572 std::unique_ptr<sycl::buffer<Tvec>> dtrhov
2573 = storage.dtrhov.get().rankgather_computefield(sched);
2574 writer.write_field("dtrhov", dtrhov, num_obj * block_size);
2575
2576 std::unique_ptr<sycl::buffer<Tscal>> dtrhoe
2577 = storage.dtrhoe.get().rankgather_computefield(sched);
2578 writer.write_field("dtrhoe", dtrhoe, num_obj * block_size);
2579 */
2580}
2581
Node adding a constant gravitational acceleration to the external forces acceleration.
Node adding a per cell acceleration field to the external forces acceleration.
Compute a gravitational acceleration at the center of each cell, using an analytical formula.
Node applying the gas-dust drag with the matrix exponential integrator.
Node applying the gas-dust drag with the first order implicit Runge-Kutta scheme (IRK1).
Node applying the external forces accelerations at t^n and t^{n+1} to the dust conservative state (tr...
Node applying the external forces acceleration to the dust conservative state.
Node applying the external forces accelerations at t^n and t^{n+1} to the gas conservative state (tra...
Node applying the external forces acceleration to the gas conservative state.
Internal energy reset onto the barotrope of the InstantBarotropic cooling.
Field variant object to instanciate a variant on the patch types.
Computes the coordinates of each cell.
Node computing the gas density at the end of the time step.
Field variant object to instanciate a variant on the patch types.
Field variant object to instanciate a variant on the patch types.
Conservative to primitive conversion of the gas for a barotropic equation of state.
Defines the CopyPatchDataField class for copying fields between patch data field references.
Defines the CopyPatchDataLayerFields class for copying fields between patch data layers.
Per cell Euler time derivatives of the dust primitive state.
Per cell Euler time derivatives of the gas primitive state for an adiabatic equation of state.
Per cell Euler time derivatives of the gas primitive state for a barotropic equation of state.
Solver graph node for exchanging ghost layer data between distributed processes.
Defines the ExtractCounts class for extracting object counts from patch data layer references.
Extract the ghost layer from the patch data layers.
Field variant object to instanciate a variant on the patch types.
Node performing the forward Euler time integration of the dust conservative state.
Node performing the forward Euler time integration of the gas conservative state.
A solver graph node to fuse a ghost layer into a set of patch data layers.
Defines the GetFieldRefFromLayer class for extracting field references from patch data layers.
BiCGSTAB solver of the Poisson equation for the self-gravity.
Jacobi preconditioned conjugate gradient solver of the Poisson equation for the self-gravity.
Field variant object to instanciate a variant on the patch types.
Field variant object to instanciate a variant on the patch types.
sycl::queue & get_compute_queue(u32 id=0)
Self-gravity acceleration on the AMR grid.
Node that applies a custom function to modify connected edges.
Shared distributed data layer for patch data management in solver graphs.
Defines the PatchDataLayerEdge class for managing patch data layer edges.
Node resetting the external forces acceleration field to zero.
Declare a class to register and retrieve nodes and edges from a unique container.
Sum the fluxes into the time derivative fields for Dust.
Sum the fluxes into the time derivative fields for Hydro.
Field variant object to instanciate a variant on the patch types.
double f64
Alias for double.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
void _impl_evaluate_internal()
evaluate the node
Definition Solver.cpp:121
The MPI scheduler.
A buffer allocated in USM (Unified Shared Memory).
void append(const DeviceBuffer &other)
Append the content of another buffer to this one.
size_t get_size() const
Gets the number of elements in the buffer.
sycl::buffer< T > copy_to_sycl_buffer() const
Copy the content of the buffer to a new SYCL buffer.
Class Timer measures the time elapsed since the timer was started.
Definition Timer.hpp:36
f64 elapsed_sec() const
Converts the stored nanosecond time to a floating point representation in seconds.
Definition Timer.hpp:88
void start()
Starts the timer.
Definition Timer.hpp:51
void stop()
Stops the timer and stores the elapsed time in nanoseconds.
Definition Timer.hpp:65
Add a constant gravitational acceleration g to the external forces acceleration.
Add a per cell acceleration field (e.g. the self-gravity acceleration) to the external forces acceler...
Apply the gas-dust drag with the matrix exponential integrator.
Apply the gas-dust drag with the first order implicit Runge-Kutta scheme (IRK1).
Apply the external forces accelerations to the momentum of every dust species with the trapezoidal ru...
Apply the external forces acceleration a_ext to the momentum of every dust species,...
Apply the external forces accelerations to the gas momentum and total energy with the trapezoidal rul...
Apply the external forces acceleration a_ext to the gas momentum and total energy,...
Overwrite the gas internal energy by the barotropic one (CoolingConfig::InstantBarotropic).
void reset_energy()
Apply the reset, does nothing if the cooling is not CoolingConfig::InstantBarotropic.
Tscal compute_cfl()
Gas CFL timestep, using the equation of state selected in solver_config.eos_config.
Compute the gas density at , , without modifying .
Forward Euler step of the conservative variables of every dust species, U <- U + dt * dU/dt.
Forward Euler step of the gas conservative variables, U <- U + dt * dU/dt.
Solve with the BiCGSTAB method, starting from the current content of spans_phi.
Solve with the Jacobi preconditioned conjugate gradient method, starting from the current content of...
Conservative to primitive conversion of the gas using shammath::FluidStateBarotropic.
Compute the Euler time derivatives of the dust primitive state per cell.
Compute the Euler time derivatives of the gas primitive state per cell.
Compute the Euler time derivatives of the gas primitive state per cell for a barotropic equation of s...
Compute the gravitational acceleration of every cell.
Resize the external forces acceleration field to the block counts and set it to zero,...
u32 get_field_idx(const std::string &field_name) const
Get the field id if matching name & type.
void add_field(const std::string &field_name, u32 nvar, SourceLocation loc=SourceLocation{})
add a field of type T to the layout
void for_each_field_any(Functor &&func) const
for each visit of each field
PatchDataLayer container class, the layout is described in patchdata_layout.
Store the information related to the size of the simulation box to convert patch integer coordinates ...
Definition SimBox.hpp:36
std::tuple< T, T > get_bounding_box() const
Get the stored bounding box of the domain.
Definition SimBox.hpp:248
A solver graph node that copies field data from source field references to target fields.
Inode is node between data edges, takes multiple inputs, multiple outputs.
Definition INode.hpp:31
void evaluate()
Evaluate the node.
Definition INode.hpp:156
void __internal_set_rw_edges(std::vector< std::shared_ptr< IEdge > > new_rw_edges)
Set the read write edges.
Definition INode.hpp:249
void __internal_set_ro_edges(std::vector< std::shared_ptr< IEdge > > new_ro_edges)
Set the read only edges.
Definition INode.hpp:238
virtual std::string _impl_get_label() const =0
get the label of the node
const T & get_ro_edge(int slot)
Get a read only edge and cast it to the type T.
Definition INode.hpp:91
virtual std::string _impl_get_tex() const =0
get the tex of the node
A node that simply frees the allocation of the connected node.
A node that applies a custom function to modify connected edges.
std::optional< std::reference_wrapper< SerialPatchTree< Tvec > > > patch_tree
The patch tree.
A graph container for managing solver nodes and edges with type-safe access.
std::shared_ptr< INode > & get_node_ptr_base(const std::string &name)
Retrieve a node by name as a shared pointer to the base interface.
std::shared_ptr< T > get_edge_ptr(const std::string &name)
Get a typed shared pointer to an edge by name.
std::shared_ptr< T > register_edge(const std::string &name, T &&edge)
Register an edge with automatic type deduction and shared pointer creation.
std::shared_ptr< T > register_node(const std::string &name, T &&node)
Register a node with automatic type deduction and shared pointer creation.
T & get_node_ref(const std::string &name)
Get a typed reference to a node by name.
This header file contains utility functions related to exception handling in the code.
MPI string gather / allgather helpers (declarations; implementations in shamalgs/src/collective/gathe...
MemPerfInfos get_mem_perf_info()
Retrieve the memory performance information.
void kernel_call(sham::DeviceQueue &q, RefIn in, RefOut in_out, u32 n, Functor &&func, SourceLocation &&callsite=SourceLocation{})
Submit a kernel to a SYCL queue.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
T & get_check_ref(const std::unique_ptr< T > &ptr, SourceLocation loc=SourceLocation())
Takes a std::unique_ptr and returns a reference to the object it holds. It throws a std::runtime_erro...
Definition memory.hpp:112
void throw_unimplemented(SourceLocation loc=SourceLocation{})
Throw a std::runtime_error saying that the function is unimplemented.
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
Definition worldInfo.cpp:41
@ HB
Huang and Bai. Pressureless Riemann solver by Huang and Bai (2022) in Athena++.
@ DHLL
Dust HLL. This is merely the HLL solver for dust. It's then a Rusanov like.
void normal_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
Definition logs.hpp:132
void raw_ln(Types... var2)
Prints a log message with multiple arguments followed by a newline.
Definition logs.hpp:89
void info_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
Definition logs.hpp:132
#define __shamrock_stack_entry()
Macro to create a stack entry.
shambase::details::BasicStackEntry StackEntry
Alias for shambase::details::BasicStackEntry.
f64 get_wtime()
Returns the current wall clock time in seconds.
Structure to store the performance informations about memory allocation and deallocation.
f64 time_alloc_host
Time spent allocating memory on the host.
size_t max_allocated_byte_host
max bytes allocated on the host
f64 time_free_device
Time spent deallocating memory on the device.
size_t max_allocated_byte_device
max bytes allocated on the device
f64 time_alloc_device
Time spent allocating memory on the device.
f64 time_free_host
Time spent deallocating memory on the host.
A class that references multiple buffers or similar objects.
Definition MultiRef.hpp:33
Build an overload set out of several callables, for use with std::visit.
Axis-Aligned bounding box.
Definition AABB.hpp:99
utility class to handle AMR blocks
Definition AMRBlock.hpp:35
Instantaneous cooling onto a barotrope (RAMSES-like).
Equation of state of the gas, each alternative maps to a shammath FluidStateSpec.
List of the external forces applied to the gas.
Patch object that contain generic patch information.
Definition Patch.hpp:33
u64 id_patch
unique key that identify the patch
Definition Patch.hpp:86
f64 get_timer(std::string timername)
get a timer value
Definition wrapper.cpp:46