18template<
class Tvec,
class Tgr
idVec>
21 auto get_gamma = [&]() -> Tscal {
22 return solver_config.eos_gamma;
26 Tscal gamma = get_gamma();
28 auto &sched = scheduler();
30 using namespace shamrock::patch;
43 Tvec sum_L2_v = {0, 0, 0};
47 Tscal one_over_Nside = 1. / AMRBlock::Nside;
49 Tscal dxfact = solver_config.grid_coord_to_pos_fact;
51 scheduler().for_each_patchdata_nonempty(
53 u32 cell_count = pdat.get_obj_cnt() * AMRBlock::block_size;
63 auto acc_block_max = buf_block_max.copy_to_stdvec();
64 auto acc_rho = buf_rho.copy_to_stdvec();
65 auto acc_vel = buf_vel.copy_to_stdvec();
66 auto acc_eint = buf_eint.copy_to_stdvec();
68 for (
u32 i = 0; i < cell_count; i++) {
69 const u32 block_id = i / AMRBlock::block_size;
70 const u32 cell_loc_id = i % AMRBlock::block_size;
72 TgridVec lower = acc_block_min[block_id];
73 TgridVec upper = acc_block_max[block_id];
75 Tvec lower_flt = lower.template convert<Tscal>() * dxfact;
76 Tvec upper_flt = upper.template convert<Tscal>() * dxfact;
78 Tvec block_cell_size = (upper_flt - lower_flt) * one_over_Nside;
80 Tvec
xyz = lower_flt + (block_cell_size / 2);
81 Tscal rho = acc_rho[i];
83 Tscal eint = acc_eint[i];
85 Tscal P = eint * (gamma - 1);
87 Tscal x = sham::dot(xyz, direction) - x_ref;
89 if ((x + x_ref) > x_min && (x + x_ref) < x_max) {
91 auto result_sod = solution.get_value(time_val, x);
93 Tscal d_rho = rho - result_sod.rho;
94 Tscal d_P = P - result_sod.P;
95 Tvec d_vxyz = v - result_sod.vx * direction;
97 sum_L2_rho += d_rho * d_rho;
98 sum_L2_P += d_P * d_P;
99 sum_L2_v += d_vxyz * d_vxyz;
106 Tscal tot_N = shamalgs::collective::allreduce_sum(N);
112 Tscal mpi_sum_L2_P = shamalgs::collective::allreduce_sum(sum_L2_P) / tot_N;
113 Tscal mpi_sum_L2_rho = shamalgs::collective::allreduce_sum(sum_L2_rho) / tot_N;
114 Tvec mpi_sum_L2_v = shamalgs::collective::allreduce_sum(sum_L2_v) / tot_N;
116 return field_val{mpi_sum_L2_rho, mpi_sum_L2_v, mpi_sum_L2_P};
constexpr const char * xyz
Position field (3D coordinates)
std::uint32_t u32
32 bit unsigned integer
A buffer allocated in USM (Unified Shared Memory)
std::vector< T > copy_to_stdvec() const
Copy the content of the buffer to a std::vector.
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.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
namespace for math utility
namespace for the main framework
Patch object that contain generic patch information.