25template<
class Tvec,
class Tgr
idVec>
29 auto get_gamma = [&]() -> Tscal {
30 return solver_config.eos_gamma;
34 Tscal gamma = get_gamma();
36 auto &sched = scheduler();
38 using namespace shamrock::patch;
52 Tvec sum_L2_v = {0, 0, 0};
56 Tscal one_over_Nside = 1. / AMRBlock::Nside;
58 Tscal dxfact = solver_config.grid_coord_to_pos_fact;
60 scheduler().for_each_patchdata_nonempty(
62 u32 cell_count = pdat.get_obj_cnt() * AMRBlock::block_size;
72 auto acc_block_max = buf_block_max.copy_to_stdvec();
73 auto acc_rho = buf_rho.copy_to_stdvec();
74 auto acc_rhov = buf_rhov.copy_to_stdvec();
75 auto acc_rhoe = buf_rhoe.copy_to_stdvec();
77 for (
u32 i = 0; i < cell_count; i++) {
78 const u32 block_id = i / AMRBlock::block_size;
79 const u32 cell_loc_id = i % AMRBlock::block_size;
81 TgridVec lower = acc_block_min[block_id];
82 TgridVec upper = acc_block_max[block_id];
84 Tvec lower_flt = lower.template convert<Tscal>() * dxfact;
85 Tvec upper_flt = upper.template convert<Tscal>() * dxfact;
87 Tvec block_cell_size = (upper_flt - lower_flt) * one_over_Nside;
89 Tvec
xyz = lower_flt + (block_cell_size / 2);
90 Tscal rho = acc_rho[i];
91 Tvec rhov = acc_rhov[i];
92 Tscal rhoe = acc_rhoe[i];
95 auto prim_state = shammath::cons_to_prim(conststate, gamma);
97 Tscal P = prim_state.press;
98 Tvec v = prim_state.vel;
100 Tscal x = sham::dot(xyz, direction) - x_ref;
102 if ((x + x_ref) > x_min && (x + x_ref) < x_max) {
104 auto result_sod = solution.get_value(time_val, x);
106 Tscal d_rho = rho - result_sod.rho;
107 Tscal d_P = P - result_sod.P;
108 Tvec d_vxyz = v - result_sod.vx * direction;
110 sum_L2_rho += d_rho * d_rho;
111 sum_L2_P += d_P * d_P;
112 sum_L2_v += d_vxyz * d_vxyz;
119 Tscal tot_N = shamalgs::collective::allreduce_sum(N);
125 Tscal mpi_sum_L2_P = shamalgs::collective::allreduce_sum(sum_L2_P) / tot_N;
126 Tscal mpi_sum_L2_rho = shamalgs::collective::allreduce_sum(sum_L2_rho) / tot_N;
127 Tvec mpi_sum_L2_v = shamalgs::collective::allreduce_sum(sum_L2_v) / tot_N;
129 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.
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
namespace for the main framework
From original version by Thomas Guillet (T.A.Guillet@exeter.ac.uk)
Patch object that contain generic patch information.