Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
AnalysisSodTube.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
22#include "shamphys/eos.hpp"
26
27template<class Tvec, template<class> class SPHKernel>
29
30 auto get_gamma = [&]() -> Tscal {
31 using SolverConfigEOS = typename Config::EOSConfig;
32 using SolverEOS_Adiabatic = typename SolverConfigEOS::Adiabatic;
33 if (SolverEOS_Adiabatic *eos_config
34 = std::get_if<SolverEOS_Adiabatic>(&solver_config.eos_config.config)) {
35 return eos_config->gamma;
36 }
38 "The sod analysis is only available for adiabatic EOS");
39 return {};
40 };
41
42 Tscal gamma = get_gamma();
43
44 auto rho_h = [&](Tscal h) {
45 return shamrock::sph::rho_h(solver_config.gpart_mass, h, Kernel::hfactd);
46 };
47
48 auto &sched = scheduler();
49
50 using namespace shamrock::patch;
51 PatchDataLayerLayout &pdl = sched.pdl_old();
52
53 const u32 ixyz = pdl.get_field_idx<Tvec>("xyz");
54 const u32 ihpart = pdl.get_field_idx<Tscal>("hpart");
55 const u32 ivxyz = pdl.get_field_idx<Tvec>("vxyz");
56 const u32 iuint = pdl.get_field_idx<Tscal>("uint");
57
58 Tscal sum_L2_rho = 0;
59 Tvec sum_L2_v = {0, 0, 0};
60 Tscal sum_L2_P = 0;
61 Tscal N = 0;
62
63 scheduler().for_each_patchdata_nonempty(
65 auto &xyz_buf = pdat.get_field_buf_ref<Tvec>(ixyz);
66 auto &hpart_buf = pdat.get_field_buf_ref<Tscal>(ihpart);
67 auto &vxyz_buf = pdat.get_field_buf_ref<Tvec>(ivxyz);
68 auto &uint_buf = pdat.get_field_buf_ref<Tscal>(iuint);
69
70 u32 len = pdat.get_obj_cnt();
71
72 {
73 auto acc_xyz = xyz_buf.copy_to_stdvec();
74 auto acc_hpart = hpart_buf.copy_to_stdvec();
75 auto acc_vxyz = vxyz_buf.copy_to_stdvec();
76 auto acc_uint = uint_buf.copy_to_stdvec();
77
78 for (u32 i = 0; i < len; i++) {
79
80 Tvec xyz = acc_xyz[i];
81 Tscal h = acc_hpart[i];
82 Tvec vxyz = acc_vxyz[i];
83 Tscal u = acc_uint[i];
84
85 Tscal rho = rho_h(h);
86 Tscal P = shamphys::EOS_Adiabatic<Tscal>::pressure(gamma, rho, u);
87
88 Tscal x = sham::dot(xyz, direction) - x_ref;
89
90 if ((x + x_ref) > x_min && (x + x_ref) < x_max) {
91
92 auto result_sod = solution.get_value(time_val, x);
93
94 Tscal d_rho = rho - result_sod.rho;
95 Tscal d_P = P - result_sod.P;
96 Tvec d_vxyz = vxyz - result_sod.vx * direction;
97
98 sum_L2_rho += d_rho * d_rho;
99 sum_L2_P += d_P * d_P;
100 sum_L2_v += d_vxyz * d_vxyz;
101 N += 1;
102 }
103 }
104 }
105 });
106
107 Tscal tot_N = shamalgs::collective::allreduce_sum(N);
108
109 if (tot_N == 0) {
110 shambase::throw_with_loc<std::runtime_error>("no particle in wanted region");
111 }
112
113 Tscal mpi_sum_L2_P = shamalgs::collective::allreduce_sum(sum_L2_P) / tot_N;
114 Tscal mpi_sum_L2_rho = shamalgs::collective::allreduce_sum(sum_L2_rho) / tot_N;
115 Tvec mpi_sum_L2_v = shamalgs::collective::allreduce_sum(sum_L2_v) / tot_N;
116
117 return field_val{mpi_sum_L2_rho, mpi_sum_L2_v, mpi_sum_L2_P};
118}
119
120using namespace shammath;
124
constexpr const char * vxyz
3-velocity field
constexpr const char * xyz
Position field (3D coordinates)
MPI scheduler.
std::uint32_t u32
32 bit unsigned integer
u32 get_field_idx(const std::string &field_name) const
Get the field id if matching name & type.
PatchDataLayer container class, the layout is described in patchdata_layout.
This header file contains utility functions related to exception handling in the code.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
namespace for math utility
Definition AABB.hpp:26
sph kernels
Adiabatic equation of state.
Definition eos.hpp:45
Patch object that contain generic patch information.
Definition Patch.hpp:33