25template<
class Tvec,
class Tgr
idVec>
26auto shammodels::basegodunov::modules::AnalysisSodTube<Tvec, TgridVec>::compute_L2_dist()
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(
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];
96 auto prim_state = adiab_fluid.cons_to_prim(conststate);
98 Tscal P = prim_state.press;
99 Tvec v = prim_state.vel;
101 Tscal x = sham::dot(xyz, direction) - x_ref;
103 if ((x + x_ref) > x_min && (x + x_ref) < x_max) {
105 auto result_sod = solution.get_value(time_val, x);
107 Tscal d_rho = rho - result_sod.rho;
108 Tscal d_P = P - result_sod.P;
109 Tvec d_vxyz = v - result_sod.vx * direction;
111 sum_L2_rho += d_rho * d_rho;
112 sum_L2_P += d_P * d_P;
113 sum_L2_v += d_vxyz * d_vxyz;
120 Tscal tot_N = shamalgs::collective::allreduce_sum(N);
126 Tscal mpi_sum_L2_P = shamalgs::collective::allreduce_sum(sum_L2_P) / tot_N;
127 Tscal mpi_sum_L2_rho = shamalgs::collective::allreduce_sum(sum_L2_rho) / tot_N;
128 Tvec mpi_sum_L2_v = shamalgs::collective::allreduce_sum(sum_L2_v) / tot_N;
130 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.
u32 get_obj_cnt() const
get the number of objects (particles) stored in this layer
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
Umbrella header pulling in the gas states and all gas Riemann solvers (Rusanov, HLL,...
FluidStateSpec implementation for an ideal (adiabatic) gas equation of state.
Patch object that contain generic patch information.