Skip to content
Open
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
9 changes: 4 additions & 5 deletions demos/fel/MithraBunch.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,14 @@ void initializeBunchEllipsoid(BunchInitialize<Double> bunchInit, ChargeVector<Do
unsigned int Np = bunchInit.numberOfParticles_, i, Np0 = chargeVector.size();

/* Declare the required parameters for the initialization of charge vectors. */
Charge<Double> charge;
Charge<Double> charge{};
charge.q = bunchInit.cloudCharge_ / Np;
FieldVector<Double> gb = bunchInit.initialGamma_ * bunchInit.betaVector_;
FieldVector<Double> r(0.0);
FieldVector<Double> t(0.0);
Double t0; //, g;
Double zmin = 1e100;
Double Ne;
Double bF = bunchInit.bF_;
Double bFi;
unsigned int bmi;
std::vector<Double> randomNumbers;

Expand Down Expand Up @@ -235,7 +233,7 @@ void initializeBunchEllipsoid(BunchInitialize<Double> bunchInit, ChargeVector<Do

/* Obtain the phase and amplitude of the modulation.
*/
bFi = bF * sqrt(-2.0 * log(generate(8, bmi)));
const Double bFi = bF * sqrt(-2.0 * log(generate(8, bmi)));

q.rnp[2] = charge.rnp[2] - bunchInit.lambda_ / 4 * ii;

Expand Down Expand Up @@ -291,7 +289,8 @@ void initializeBunchEllipsoid(BunchInitialize<Double> bunchInit, ChargeVector<Do

/* Obtain the average number of electrons per FEL beamlet.
*/
Ne = bunchInit.cloudCharge_ * bunchInit.lambda_ / (2.0 * bunchInit.sigmaPosition_[2]);
const Double Ne =
bunchInit.cloudCharge_ * bunchInit.lambda_ / (2.0 * bunchInit.sigmaPosition_[2]);

/* Set the bunching factor level for the shot noise depending on the given values.
*/
Expand Down
9 changes: 7 additions & 2 deletions src/Communicate/Archive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,11 @@ namespace ippl {
size_t size = sizeof(T);
auto base = bufferData();
auto writepos = writepos_m;
auto viewSpan = view.to_mdspan();
Kokkos::parallel_for(
"Archive::serialize()", policy_type(0, nsends), KOKKOS_LAMBDA(const size_type i) {
const char* src = reinterpret_cast<const char*>(view.data() + i);
const T value = viewSpan(i);
const char* src = reinterpret_cast<const char*>(&value);
char* dst = base + i * size + writepos;
copyBytes(dst, src, size);
});
Expand Down Expand Up @@ -303,11 +305,14 @@ namespace ippl {
}
auto base = bufferData();
auto readpos = readpos_m;
auto viewSpan = view.to_mdspan();
Kokkos::parallel_for(
"Archive::deserialize()", policy_type(0, nrecvs), KOKKOS_LAMBDA(const size_type i) {
const char* src = base + i * size + readpos;
char* dst = reinterpret_cast<char*>(view.data() + i);
T value{};
char* dst = reinterpret_cast<char*>(&value);
copyBytes(dst, src, size);
viewSpan(i) = value;
});
// Wait for deserialization kernel to complete
// (as with serialization kernels)
Expand Down
44 changes: 29 additions & 15 deletions src/Expression/IpplOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,14 @@ namespace ippl {
struct meta_grad
: public Expression<
meta_grad<E>,
sizeof(E) + sizeof(typename E::Mesh_t::vector_type[E::Mesh_t::Dimension])> {
sizeof(typename E::view_type)
+ sizeof(typename E::Mesh_t::vector_type[E::Mesh_t::Dimension])> {
constexpr static unsigned dim = E::dim;
using value_type = typename E::value_type;

KOKKOS_FUNCTION
meta_grad(const E& u, const typename E::Mesh_t::vector_type vectors[])
meta_grad(const typename E::view_type& u,
const typename E::Mesh_t::vector_type vectors[])
: u_m(u) {
for (unsigned d = 0; d < E::Mesh_t::Dimension; d++) {
vectors_m[d] = vectors[d];
Expand Down Expand Up @@ -348,7 +350,8 @@ namespace ippl {
private:
using Mesh_t = typename E::Mesh_t;
using vector_type = typename Mesh_t::vector_type;
const E u_m;
using view_type = typename E::view_type;
const view_type u_m;
vector_type vectors_m[dim];
};
} // namespace detail
Expand All @@ -362,11 +365,13 @@ namespace ippl {
struct meta_div
: public Expression<
meta_div<E>,
sizeof(E) + sizeof(typename E::Mesh_t::vector_type[E::Mesh_t::Dimension])> {
sizeof(typename E::view_type)
+ sizeof(typename E::Mesh_t::vector_type[E::Mesh_t::Dimension])> {
constexpr static unsigned dim = E::dim;

KOKKOS_FUNCTION
meta_div(const E& u, const typename E::Mesh_t::vector_type vectors[])
meta_div(const typename E::view_type& u,
const typename E::Mesh_t::vector_type vectors[])
: u_m(u) {
for (unsigned d = 0; d < E::Mesh_t::Dimension; d++) {
vectors_m[d] = vectors[d];
Expand Down Expand Up @@ -404,7 +409,8 @@ namespace ippl {
private:
using Mesh_t = typename E::Mesh_t;
using vector_type = typename Mesh_t::vector_type;
const E u_m;
using view_type = typename E::view_type;
const view_type u_m;
vector_type vectors_m[dim];
};

Expand All @@ -414,12 +420,14 @@ namespace ippl {
template <typename E>
struct meta_laplace
: public Expression<meta_laplace<E>,
sizeof(E) + sizeof(typename E::Mesh_t::vector_type)> {
sizeof(typename E::view_type)
+ sizeof(typename E::Mesh_t::vector_type)> {
constexpr static unsigned dim = E::dim;
using value_type = typename E::value_type;

KOKKOS_FUNCTION
meta_laplace(const E& u, const typename E::Mesh_t::vector_type& hvector)
meta_laplace(const typename E::view_type& u,
const typename E::Mesh_t::vector_type& hvector)
: u_m(u)
, hvector_m(hvector) {}

Expand Down Expand Up @@ -456,7 +464,8 @@ namespace ippl {
private:
using Mesh_t = typename E::Mesh_t;
using vector_type = typename Mesh_t::vector_type;
const E u_m;
using view_type = typename E::view_type;
const view_type u_m;
const vector_type hvector_m;
};
} // namespace detail
Expand All @@ -469,11 +478,13 @@ namespace ippl {
template <typename E>
struct meta_curl
: public Expression<meta_curl<E>,
sizeof(E) + 4 * sizeof(typename E::Mesh_t::vector_type)> {
sizeof(typename E::view_type)
+ 4 * sizeof(typename E::Mesh_t::vector_type)> {
constexpr static unsigned dim = E::dim;

KOKKOS_FUNCTION
meta_curl(const E& u, const typename E::Mesh_t::vector_type& xvector,
meta_curl(const typename E::view_type& u,
const typename E::Mesh_t::vector_type& xvector,
const typename E::Mesh_t::vector_type& yvector,
const typename E::Mesh_t::vector_type& zvector,
const typename E::Mesh_t::vector_type& hvector)
Expand Down Expand Up @@ -501,7 +512,8 @@ namespace ippl {
private:
using Mesh_t = typename E::Mesh_t;
using vector_type = typename Mesh_t::vector_type;
const E u_m;
using view_type = typename E::view_type;
const view_type u_m;
const vector_type xvector_m;
const vector_type yvector_m;
const vector_type zvector_m;
Expand All @@ -517,13 +529,14 @@ namespace ippl {
template <typename E>
struct meta_hess
: public Expression<meta_hess<E>,
sizeof(E)
sizeof(typename E::view_type)
+ sizeof(typename E::Mesh_t::vector_type[E::Mesh_t::Dimension])
+ sizeof(typename E::Mesh_t::vector_type)> {
constexpr static unsigned dim = E::dim;

KOKKOS_FUNCTION
meta_hess(const E& u, const typename E::Mesh_t::vector_type vectors[],
meta_hess(const typename E::view_type& u,
const typename E::Mesh_t::vector_type vectors[],
const typename E::Mesh_t::vector_type& hvector)
: u_m(u)
, hvector_m(hvector) {
Expand All @@ -546,8 +559,9 @@ namespace ippl {
using Mesh_t = typename E::Mesh_t;
using vector_type = typename Mesh_t::vector_type;
using matrix_type = typename Mesh_t::matrix_type;
using view_type = typename E::view_type;

const E u_m;
const view_type u_m;
vector_type vectors_m[dim];
const vector_type hvector_m;

Expand Down
Loading
Loading