12 #include <conduit/conduit_blueprint.hpp>
13 #include <conduit/conduit_relay.hpp>
23 template <
typename ParticleType,
int NArrayReal,
int NArrayInt>
31 const std::string &topology_name)
33 int num_particles = ptile.size();
40 std::string coordset_name = topology_name +
"_coords";
41 conduit::Node &n_coords = res[
"coordsets"][coordset_name];
42 n_coords[
"type"] =
"explicit";
45 conduit::Node &n_topo = res[
"topologies"][topology_name];
46 n_topo[
"coordset"] = coordset_name;
47 n_topo[
"type"] =
"unstructured";
48 n_topo[
"elements/shape"] =
"point";
49 n_topo[
"elements/connectivity"].set(
50 conduit::DataType::c_int(num_particles));
51 int *conn = n_topo[
"elements/connectivity"].value();
53 for(
int i = 0; i < num_particles ; i++)
63 if constexpr(ParticleType::is_soa_particle)
67 const auto &soa = ptile.GetStructOfArrays();
72 n_coords[
"values/x"].set_external(
const_cast<ParticleReal*
>(soa.GetRealData(0).data()),
74 #if AMREX_SPACEDIM > 1
75 n_coords[
"values/y"].set_external(
const_cast<ParticleReal*
>(soa.GetRealData(1).data()),
78 #if AMREX_SPACEDIM > 2
79 n_coords[
"values/z"].set_external(
const_cast<ParticleReal*
>(soa.GetRealData(2).data()),
85 const auto &pstruct = ptile.GetArrayOfStructs();
86 const int struct_size =
sizeof(ParticleType);
88 const char* pbuf_const =
reinterpret_cast<const char*
>(pstruct.data());
89 pbuf =
const_cast<char*
>(pbuf_const);
91 ParticleReal* xp =
reinterpret_cast<ParticleReal*
>(pbuf); pbuf +=
sizeof(ParticleReal);
92 n_coords[
"values/x"].set_external(xp,
96 #if AMREX_SPACEDIM > 1
97 ParticleReal* yp =
reinterpret_cast<ParticleReal*
>(pbuf); pbuf +=
sizeof(ParticleReal);
98 n_coords[
"values/y"].set_external(yp,
103 #if AMREX_SPACEDIM > 2
104 ParticleReal* zp =
reinterpret_cast<ParticleReal*
>(pbuf); pbuf +=
sizeof(ParticleReal);
105 n_coords[
"values/z"].set_external(zp,
113 conduit::Node &n_fields = res[
"fields"];
119 int vname_real_idx = 0;
120 if constexpr(!ParticleType::is_soa_particle)
122 constexpr
int struct_size =
sizeof(ParticleType);
123 constexpr
int NStructReal = ParticleType::NReal;
127 for (
int i = 0; i < NStructReal; i++)
129 ParticleReal* val =
reinterpret_cast<ParticleReal*
>(pbuf); pbuf +=
sizeof(ParticleReal);
130 conduit::Node &n_f = n_fields[real_comp_names.at(vname_real_idx)];
131 n_f[
"topology"] = topology_name;
132 n_f[
"association"] =
"element";
133 n_f[
"values"].set_external(val,
147 if constexpr(!ParticleType::is_soa_particle)
149 const int struct_size =
sizeof(ParticleType);
152 int*
id =
reinterpret_cast<int*
>(pbuf); pbuf +=
sizeof(
int);
153 conduit::Node &n_f_id = n_fields[topology_name +
"_id"];
155 n_f_id[
"topology"] = topology_name;
156 n_f_id[
"association"] =
"element";
157 n_f_id[
"values"].set_external(
id,
163 int* cpu =
reinterpret_cast<int*
>(pbuf); pbuf +=
sizeof(
int);
164 conduit::Node &n_f_cpu = n_fields[topology_name +
"_cpu"];
166 n_f_cpu[
"topology"] = topology_name;
167 n_f_cpu[
"association"] =
"element";
168 n_f_cpu[
"values"].set_external(cpu,
173 const auto &soa = ptile.GetStructOfArrays();
178 conduit::Node &n_f_idcpu = n_fields[topology_name +
"_idcpu"];
180 n_f_idcpu[
"topology"] = topology_name;
181 n_f_idcpu[
"association"] =
"element";
182 n_f_idcpu[
"values"].set_external(
const_cast<uint64_t*
>(soa.GetIdCPUData().data()),
190 int vname_int_idx = 0;
191 if constexpr(!ParticleType::is_soa_particle)
193 constexpr
int struct_size =
sizeof(ParticleType);
194 constexpr
int NStructInt = ParticleType::NInt;
196 for (
int i = 0; i < NStructInt; i++)
198 int* val =
reinterpret_cast<int*
>(pbuf); pbuf +=
sizeof(
int);
199 conduit::Node &n_f = n_fields[int_comp_names.at(vname_int_idx)];
200 n_f[
"topology"] = topology_name;
201 n_f[
"association"] =
"element";
202 n_f[
"values"].set_external(val,
214 const auto &soa = ptile.GetStructOfArrays();
220 for (
int i = 0; i < NArrayReal; i++)
222 conduit::Node &n_f = n_fields[real_comp_names.at(vname_real_idx)];
223 n_f[
"topology"] = topology_name;
224 n_f[
"association"] =
"element";
225 n_f[
"values"].set_external(
const_cast<ParticleReal*
>(soa.GetRealData(i).data()),
232 for (
int i = 0; i < NArrayInt; i++)
234 conduit::Node &n_f = n_fields[int_comp_names.at(vname_int_idx)];
235 n_f[
"topology"] = topology_name;
236 n_f[
"association"] =
"element";
237 n_f[
"values"].set_external(
const_cast<int*
>(soa.GetIntData(i).data()),
247 template <
typename ParticleType,
int NArrayReal,
int NArrayInt>
255 const std::string &topology_name)
262 if constexpr(ParticleType::is_soa_particle) {
266 BL_ASSERT(real_comp_names.
size() == (ParticleType::NReal + NArrayReal) );
267 BL_ASSERT(int_comp_names.
size() == (ParticleType::NInt + NArrayInt) );
270 int num_levels = pc.maxLevel() + 1;
274 long domain_offset = (long)res.number_of_children();
294 std::vector<int> my_lvl_offsets;
295 my_lvl_offsets.resize(num_levels);
298 std::vector<int> within_lvl_counts;
299 std::vector<int> within_lvl_offsets;
300 within_lvl_counts.resize(nprocs);
301 within_lvl_offsets.resize(nprocs);
303 int total_num_domains = 0;
304 for (
int lev = 0; lev < num_levels; ++lev)
307 long level_num_domains = 0;
308 for (MyParConstIter pti(pc, lev); pti.isValid(); ++pti)
310 level_num_domains+=1;
314 for(
int rank_idx = 0; rank_idx < nprocs ; rank_idx++)
316 within_lvl_counts[rank_idx] = 0;
317 within_lvl_offsets[rank_idx] = 0;
321 within_lvl_counts[rank] = level_num_domains;
326 long level_total_num_domains = 0;
328 for(
int rank_idx = 0; rank_idx < nprocs ; rank_idx++)
330 within_lvl_offsets[rank_idx] = level_total_num_domains;
331 level_total_num_domains += within_lvl_counts[rank_idx];
336 my_lvl_offsets[lev] = within_lvl_offsets[rank] + total_num_domains;
338 total_num_domains += level_num_domains;
341 for (
int lev = 0; lev < num_levels; ++lev)
344 int lvl_offset = my_lvl_offsets[lev];
346 int num_lvl_local_tiles = 0;
347 for (MyParConstIter pti(pc, lev); pti.isValid(); ++pti)
350 int domain_id = lvl_offset + num_lvl_local_tiles + domain_offset;
352 const auto& ptile = pti.GetParticleTile();
356 conduit::Node &patch = res[patch_name];
358 patch[
"state/domain_id"] = domain_id;
364 num_lvl_local_tiles += 1;
371 if(!conduit::blueprint::mesh::verify(res,info))
375 amrex::Print() <<
"ERROR: Conduit Mesh Blueprint Verify Failed!\n"
#define BL_PROFILE(a)
Definition: AMReX_BLProfiler.H:551
#define BL_ASSERT(EX)
Definition: AMReX_BLassert.H:39
Definition: AMReX_ParIter.H:142
A distributed container for Particles sorted onto the levels, grids, and tiles of a block-structured ...
Definition: AMReX_ParticleContainer.H:145
This class provides the user with a few print options.
Definition: AMReX_Print.H:35
Long size() const noexcept
Definition: AMReX_Vector.H:50
void ReduceIntSum(int &)
Integer sum reduction.
Definition: AMReX_ParallelDescriptor.cpp:1252
int MyProc() noexcept
return the rank number local to the current Parallel Context
Definition: AMReX_ParallelDescriptor.H:125
void ReduceLongSum(Long &)
Long sum reduction.
Definition: AMReX_ParallelDescriptor.cpp:1223
int NProcs() noexcept
return the number of MPI ranks local to the current Parallel Context
Definition: AMReX_ParallelDescriptor.H:243
Definition: AMReX_Amr.cpp:49
std::string Concatenate(const std::string &root, int num, int mindigits)
Returns rootNNNN where NNNN == num.
Definition: AMReX_String.cpp:34
void ParticleTileToBlueprint(const ParticleTile< ParticleType, NArrayReal, NArrayInt > &ptile, const Vector< std::string > &real_comp_names, const Vector< std::string > &int_comp_names, conduit::Node &res, const std::string &topology_name)
Definition: AMReX_Conduit_Blueprint_ParticlesI.H:25
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ignore_unused(const Ts &...)
This shuts up the compiler about unused variables.
Definition: AMReX.H:111
const int[]
Definition: AMReX_BLProfiler.cpp:1664
void ParticleContainerToBlueprint(const ParticleContainer_impl< ParticleType, NArrayReal, NArrayInt > &pc, const Vector< std::string > &real_comp_names, const Vector< std::string > &int_comp_names, conduit::Node &res, const std::string &topology_name)
Definition: AMReX_Conduit_Blueprint_ParticlesI.H:249
Definition: AMReX_ParticleTile.H:693