Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(PROJECT_NAME entity)

project(
${PROJECT_NAME}
VERSION 1.2.3
VERSION 1.2.4
LANGUAGES CXX C)
add_compile_options("-D ENTITY_VERSION=\"${PROJECT_VERSION}\"")
set(hash_cmd "git diff --quiet src/ && echo $(git rev-parse HEAD) ")
Expand Down
21 changes: 17 additions & 4 deletions src/framework/domain/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ namespace ntt {
template <SimEngine::type S, class M, StatsID::type P>
auto ComputeMoments(const SimulationParams& params,
const Mesh<M>& mesh,
const M& global_metric,
const std::vector<Particles<M::Dim, M::CoordType>>& prtl_species,
const std::vector<spidx_t>& species,
const std::vector<unsigned short>& components) -> real_t {
Expand Down Expand Up @@ -99,6 +100,7 @@ namespace ntt {
if (P == StatsID::Rho and cmp::AlmostZero_host(prtl_spec.mass())) {
continue;
}
real_t temp_buff = ZERO;
Kokkos::parallel_reduce(
"ComputeMoments",
prtl_spec.rangeActiveParticles(),
Expand All @@ -111,9 +113,15 @@ namespace ntt {
prtl_spec.mass(), prtl_spec.charge(),
use_weights, mesh.metric),
// clang-format on
buffer);
temp_buff);
buffer += temp_buff;
}
if (P != StatsID::Npart) {
return buffer / (global_metric.totVolume() *
params.template get<real_t>("particles.ppc0"));
} else {
return buffer;
}
return buffer;
}

template <SimEngine::type S, class M, StatsID::type F>
Expand Down Expand Up @@ -193,8 +201,8 @@ namespace ntt {
}
auto local_domain = subdomain_ptr(l_subdomain_indices()[0]);
logger::Checkpoint("Writing stats", HERE);
g_stats_writer.write(current_step);
g_stats_writer.write(current_time);
g_stats_writer.write(current_step, false);
g_stats_writer.write(current_time, false);
for (const auto& stat : g_stats_writer.statsWriters()) {
if (stat.id() == StatsID::Custom) {
if (CustomStat != nullptr) {
Expand All @@ -206,27 +214,31 @@ namespace ntt {
} else if (stat.id() == StatsID::N) {
g_stats_writer.write(ComputeMoments<S, M, StatsID::N>(params,
local_domain->mesh,
g_mesh.metric,
local_domain->species,
stat.species,
{}));
} else if (stat.id() == StatsID::Npart) {
g_stats_writer.write(
ComputeMoments<S, M, StatsID::Npart>(params,
local_domain->mesh,
g_mesh.metric,
local_domain->species,
stat.species,
{}));
} else if (stat.id() == StatsID::Rho) {
g_stats_writer.write(
ComputeMoments<S, M, StatsID::Rho>(params,
local_domain->mesh,
g_mesh.metric,
local_domain->species,
stat.species,
{}));
} else if (stat.id() == StatsID::Charge) {
g_stats_writer.write(
ComputeMoments<S, M, StatsID::Charge>(params,
local_domain->mesh,
g_mesh.metric,
local_domain->species,
stat.species,
{}));
Expand All @@ -235,6 +247,7 @@ namespace ntt {
g_stats_writer.write(
ComputeMoments<S, M, StatsID::T>(params,
local_domain->mesh,
g_mesh.metric,
local_domain->species,
stat.species,
comp));
Expand Down
133 changes: 74 additions & 59 deletions src/kernels/reduced_stats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,82 +466,97 @@ namespace kernel {
}

Inline void operator()(index_t p, real_t& buff) const {
if (tag(p) == ParticleTag::dead) {
if (tag(p) != ParticleTag::alive) {
return;
}
auto dV = ONE;

if constexpr (P == StatsID::Npart) {
buff += ONE;
return;
} else if constexpr (P == StatsID::N or P == StatsID::Rho or
P == StatsID::Charge) {
buff += use_weights ? weight(p) : contrib;
return;
} else {
// for stress-energy tensor
real_t energy { ZERO };
vec_t<Dim::_3D> u_Phys { ZERO };
if constexpr (S == SimEngine::SRPIC) {
// SR
// stress-energy tensor for SR is computed in the tetrad (hatted) basis
if constexpr (M::CoordType == Coord::Cart) {
u_Phys[0] = ux1(p);
u_Phys[1] = ux2(p);
u_Phys[2] = ux3(p);
coord_t<D> x_Code { ZERO };
if constexpr ((D == Dim::_1D) or (D == Dim::_2D) or (D == Dim::_3D)) {
x_Code[0] = static_cast<real_t>(i1(p)) + static_cast<real_t>(dx1(p));
}
if constexpr ((D == Dim::_2D) or (D == Dim::_3D)) {
x_Code[1] = static_cast<real_t>(i2(p)) + static_cast<real_t>(dx2(p));
}
if constexpr (D == Dim::_3D) {
x_Code[2] = static_cast<real_t>(i3(p)) + static_cast<real_t>(dx3(p));
}
dV = metric.sqrt_det_h(x_Code);
if constexpr (P == StatsID::N or P == StatsID::Rho or P == StatsID::Charge) {
buff += dV * (use_weights ? weight(p) : contrib);
} else {
// for stress-energy tensor
real_t energy { ZERO };
vec_t<Dim::_3D> u_Phys { ZERO };
if constexpr (S == SimEngine::SRPIC) {
// SR
// stress-energy tensor for SR is computed in the tetrad (hatted) basis
if constexpr (M::CoordType == Coord::Cart) {
u_Phys[0] = ux1(p);
u_Phys[1] = ux2(p);
u_Phys[2] = ux3(p);
} else {
static_assert(D != Dim::_1D, "non-Cartesian SRPIC 1D");
coord_t<M::PrtlDim> x_Code { ZERO };
x_Code[0] = static_cast<real_t>(i1(p)) + static_cast<real_t>(dx1(p));
x_Code[1] = static_cast<real_t>(i2(p)) + static_cast<real_t>(dx2(p));
if constexpr (D == Dim::_3D) {
x_Code[2] = static_cast<real_t>(i3(p)) +
static_cast<real_t>(dx3(p));
} else {
x_Code[2] = phi(p);
}
metric.template transform_xyz<Idx::XYZ, Idx::T>(
x_Code,
{ ux1(p), ux2(p), ux3(p) },
u_Phys);
}
if (mass == ZERO) {
energy = NORM(u_Phys[0], u_Phys[1], u_Phys[2]);
} else {
energy = mass * math::sqrt(
ONE + NORM_SQR(u_Phys[0], u_Phys[1], u_Phys[2]));
}
} else {
static_assert(D != Dim::_1D, "non-Cartesian SRPIC 1D");
coord_t<M::PrtlDim> x_Code { ZERO };
// GR
// stress-energy tensor for GR is computed in contravariant basis
static_assert(D != Dim::_1D, "GRPIC 1D");
coord_t<D> x_Code { ZERO };
x_Code[0] = static_cast<real_t>(i1(p)) + static_cast<real_t>(dx1(p));
x_Code[1] = static_cast<real_t>(i2(p)) + static_cast<real_t>(dx2(p));
if constexpr (D == Dim::_3D) {
x_Code[2] = static_cast<real_t>(i3(p)) + static_cast<real_t>(dx3(p));
}
vec_t<Dim::_3D> u_Cntrv { ZERO };
// compute u_i u^i for energy
metric.template transform<Idx::D, Idx::U>(x_Code,
{ ux1(p), ux2(p), ux3(p) },
u_Cntrv);
energy = u_Cntrv[0] * ux1(p) + u_Cntrv[1] * ux2(p) +
u_Cntrv[2] * ux3(p);
if (mass == ZERO) {
energy = math::sqrt(energy);
} else {
x_Code[2] = phi(p);
energy = mass * math::sqrt(ONE + energy);
}
metric.template transform_xyz<Idx::XYZ, Idx::T>(
x_Code,
{ ux1(p), ux2(p), ux3(p) },
u_Phys);
metric.template transform<Idx::U, Idx::PU>(x_Code, u_Cntrv, u_Phys);
}
if (mass == ZERO) {
energy = NORM(u_Phys[0], u_Phys[1], u_Phys[2]);
} else {
energy = mass *
math::sqrt(ONE + NORM_SQR(u_Phys[0], u_Phys[1], u_Phys[2]));
}
} else {
// GR
// stress-energy tensor for GR is computed in contravariant basis
static_assert(D != Dim::_1D, "GRPIC 1D");
coord_t<D> x_Code { ZERO };
x_Code[0] = static_cast<real_t>(i1(p)) + static_cast<real_t>(dx1(p));
x_Code[1] = static_cast<real_t>(i2(p)) + static_cast<real_t>(dx2(p));
if constexpr (D == Dim::_3D) {
x_Code[2] = static_cast<real_t>(i3(p)) + static_cast<real_t>(dx3(p));
}
vec_t<Dim::_3D> u_Cntrv { ZERO };
// compute u_i u^i for energy
metric.template transform<Idx::D, Idx::U>(x_Code,
{ ux1(p), ux2(p), ux3(p) },
u_Cntrv);
energy = u_Cntrv[0] * ux1(p) + u_Cntrv[1] * ux2(p) + u_Cntrv[2] * ux3(p);
if (mass == ZERO) {
energy = math::sqrt(energy);
} else {
energy = mass * math::sqrt(ONE + energy);
}
metric.template transform<Idx::U, Idx::PU>(x_Code, u_Cntrv, u_Phys);
}
// compute the corresponding moment
real_t coeff = ONE;
// compute the corresponding moment
real_t coeff = ONE;
#pragma unroll
for (const auto& c : { c1, c2 }) {
if (c == 0) {
coeff *= energy;
} else {
coeff *= u_Phys[c - 1];
for (const auto& c : { c1, c2 }) {
if (c == 0) {
coeff *= energy;
} else {
coeff *= u_Phys[c - 1];
}
}
buff += dV * coeff / energy;
}
buff += coeff / energy;
}
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/output/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ namespace stats {
// determine the stats ID
const auto pos = name.find("_");
auto name_raw = (pos == std::string::npos) ? name : name.substr(0, pos);
if ((name_raw[0] != 'E') and (name_raw[0] != 'B') and (name_raw[0] != 'J')) {
if ((name_raw[0] != 'E') and (name_raw[0] != 'B') and
(name_raw[0] != 'J') and (name_raw[0] != 'N')) {
name_raw = name_raw.substr(0, name_raw.find_first_of("0123ijxyzt"));
}
if (StatsID::contains(fmt::toLower(name_raw).c_str())) {
Expand Down
21 changes: 13 additions & 8 deletions src/output/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,22 @@ namespace stats {
auto shouldWrite(timestep_t, simtime_t) -> bool;

template <typename T>
inline void write(const T& value) const {
inline void write(const T& value, bool communicate = true) const {
auto tot_value { static_cast<T>(0) };
#if defined(MPI_ENABLED)
MPI_Reduce(&value,
&tot_value,
1,
mpi::get_type<T>(),
MPI_SUM,
MPI_ROOT_RANK,
MPI_COMM_WORLD);
if (communicate) {
MPI_Reduce(&value,
&tot_value,
1,
mpi::get_type<T>(),
MPI_SUM,
MPI_ROOT_RANK,
MPI_COMM_WORLD);
} else {
tot_value = value;
}
#else
(void)communicate;
tot_value = value;
#endif
CallOnce(
Expand Down