27template<
class Tvec,
template<
class>
class SPHKernel>
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;
38 "The sod analysis is only available for adiabatic EOS");
42 Tscal gamma = get_gamma();
44 auto rho_h = [&](Tscal h) {
45 return shamrock::sph::rho_h(solver_config.gpart_mass, h, Kernel::hfactd);
48 auto &sched = scheduler();
50 using namespace shamrock::patch;
59 Tvec sum_L2_v = {0, 0, 0};
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);
70 u32 len = pdat.get_obj_cnt();
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();
78 for (
u32 i = 0; i < len; i++) {
80 Tvec
xyz = acc_xyz[i];
81 Tscal h = acc_hpart[i];
82 Tvec
vxyz = acc_vxyz[i];
83 Tscal u = acc_uint[i];
88 Tscal x = sham::dot(xyz, direction) - x_ref;
90 if ((x + x_ref) > x_min && (x + x_ref) < x_max) {
92 auto result_sod = solution.get_value(time_val, x);
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;
98 sum_L2_rho += d_rho * d_rho;
99 sum_L2_P += d_P * d_P;
100 sum_L2_v += d_vxyz * d_vxyz;
107 Tscal tot_N = shamalgs::collective::allreduce_sum(N);
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;
117 return field_val{mpi_sum_L2_rho, mpi_sum_L2_v, mpi_sum_L2_P};
constexpr const char * vxyz
3-velocity field
constexpr const char * xyz
Position field (3D coordinates)
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
Adiabatic equation of state.
Patch object that contain generic patch information.