1#ifndef __CORE_POST_PROCESS_PUBLIC_HPP__
2#define __CORE_POST_PROCESS_PUBLIC_HPP__
3#include <Kokkos_Core.hpp>
4#include <Kokkos_Core_fwd.hpp>
5#include <Kokkos_ScatterView.hpp>
6#include <common/common.hpp>
8#include <mc/particles_container.hpp>
9#include <mc/traits.hpp>
11template <
typename MemorySpace>
12using ParticlePropertyViewType
13 = Kokkos::View<double**, Kokkos::LayoutRight, MemorySpace>;
15using SubViewtype = Kokkos::Subview<ParticlePropertyViewType<ComputeSpace>,
16 decltype(Kokkos::ALL),
24 std::optional<ParticlePropertyViewType<HostSpace> >
ages;
25 std::vector<std::string>
vnames;
30 template <
typename Model,
typename ExecutionSpace>
31 struct GetPropertiesFunctor
33 using ComputeSpace =
typename ExecutionSpace::memory_space;
38 typename Model::SelfParticle model,
40 ParticlePropertyViewType<ComputeSpace> particle_values,
41 ParticlePropertyViewType<ComputeSpace> spatial_values,
42 ParticlePropertyViewType<ComputeSpace> ages_value,
44 : n_p(n_p), position(std::move(position)), model(std::move(model)),
45 ages(std::move(ages)), particle_values(std::move(particle_values)),
46 spatial_values(std::move(spatial_values)),
47 ages_value(std::move(ages_value)), status(std::move(status))
51 KOKKOS_INLINE_FUNCTION
53 operator()(
const int i_particle)
const
61 auto access = scatter_spatial_values.access();
62 for (
size_t k_var = 0; k_var < Model::n_var; ++k_var)
64 const auto current = model(i_particle, k_var);
65 access(k_var, position(i_particle)) += current;
66 particle_values(k_var, i_particle) = current;
69 const auto mass = Model::mass(i_particle, model);
70 access(Model::n_var, position(i_particle)) += mass;
71 particle_values(Model::n_var, i_particle) = mass;
72 ages_value(0, i_particle) = ages(i_particle, 0);
73 ages_value(1, i_particle) = ages(i_particle, 1);
76 KOKKOS_INLINE_FUNCTION
78 operator()(
const int i_particle)
const
86 auto access = scatter_spatial_values.access();
87 for (
size_t k_var = 0; k_var < kindices.extent(0); ++k_var)
89 const auto current = model(i_particle, kindices(k_var));
90 access(k_var, position(i_particle)) += current;
91 particle_values(k_var, i_particle) = current;
94 const auto mass = Model::mass(i_particle, model);
95 access(kindices.extent(0), position(i_particle)) += mass;
96 particle_values(kindices.extent(0), i_particle) = mass;
97 ages_value(0, i_particle) = ages(i_particle, 0);
98 ages_value(1, i_particle) = ages(i_particle, 1);
105 scatter_spatial_values
106 = Kokkos::Experimental::create_scatter_view(spatial_values);
111 static const auto indices = Model::get_number();
112 Kokkos::View<size_t*, HostSpace> host_index(
"host_index",
114 for (
size_t i = 0; i < indices.size(); ++i)
116 host_index(i) = indices[i];
119 = Kokkos::create_mirror_view_and_copy(ComputeSpace(), host_index);
122 Kokkos::parallel_for(
"get_properties",
123 Kokkos::RangePolicy<ExecutionSpace>(0, n_p),
127 Kokkos::Experimental::contribute(spatial_values,
128 scatter_spatial_values);
133 typename Model::SelfParticle model;
135 ParticlePropertyViewType<ComputeSpace> particle_values;
136 ParticlePropertyViewType<ComputeSpace> spatial_values;
137 ParticlePropertyViewType<ComputeSpace> ages_value;
139 Kokkos::View<const size_t*, ComputeSpace> kindices;
140 Kokkos::Experimental::
141 ScatterView<double**, Kokkos::LayoutRight, ComputeSpace>
142 scatter_spatial_values;
146 template <ModelType M>
147 std::optional<PostProcessing::BonceBuffer>
149 const std::size_t n_compartment,
156 const std::size_t n_p
160 auto ar = M::names();
161 properties.
vnames = std::vector<std::string>(ar.begin(), ar.end());
162 properties.
vnames.emplace_back(
"mass");
164 std::size_t n_var = M::n_var + 1;
167 n_var = ar.size() + 1;
170 ParticlePropertyViewType<ComputeSpace> spatial_values(
171 "property_spatial", n_var, n_compartment);
172 ParticlePropertyViewType<ComputeSpace> particle_values(
173 "property_values", n_var, n_p);
177 ParticlePropertyViewType<ComputeSpace> ages_values(
"ages_values", 2, n_p);
179 GetPropertiesFunctor<M, Kokkos::DefaultExecutionSpace>(n_p,
190 Kokkos::HostSpace(), particle_values);
192 Kokkos::HostSpace(), spatial_values);
197 properties.
ages = Kokkos::create_mirror_view_and_copy(
198 Kokkos::HostSpace(), ages_values);
202 properties.
ages = std::nullopt;
Main owning object for Monte-Carlo particles.
Definition particles_container.hpp:57
void force_remove_dead()
Clean all the non-idle particle even if number smaller than threshold.
Definition particles_container.hpp:474
Model::SelfParticle model
Definition particles_container.hpp:83
KOKKOS_INLINE_FUNCTION std::size_t n_particles() const
Gets the number of particles in the container.
Definition particles_container.hpp:460
MC::ParticlePositions position
Definition particles_container.hpp:84
ParticleAges ages
Definition particles_container.hpp:87
MC::ParticleStatus status
Definition particles_container.hpp:85
SFNIAE way to check whether model allow all value saving.
Definition traits.hpp:165
SFNIAE way to check whether model allow partial value saving.
Definition traits.hpp:174
Model that can export properties.
Definition traits.hpp:187
Kokkos::View< Status *, ComputeSpace > ParticleStatus
Definition alias.hpp:74
Kokkos::View< uint64_t *, ComputeSpace > ParticlePositions
Definition alias.hpp:73
@ Idle
Definition alias.hpp:59
ParticleAgesBase< ComputeSpace > ParticleAges
Definition alias.hpp:76
Definition impl_post_process.hpp:21
std::optional< PostProcessing::BonceBuffer > get_properties(MC::ParticlesContainer< M > &container, const std::size_t n_compartment, const bool with_age)
Definition post_process.hpp:147
Definition post_process.hpp:20
std::optional< ParticlePropertyViewType< HostSpace > > ages
Definition post_process.hpp:23
ParticlePropertyViewType< HostSpace > spatial_values
Definition post_process.hpp:22
std::vector< std::string > vnames
Definition post_process.hpp:24
ParticlePropertyViewType< HostSpace > particle_values
Definition post_process.hpp:21