4 #include "MeshMetadata.h"
6 #include <svtkPolyData.h>
7 #include <svtkDataSetAttributes.h>
8 #include <svtkCellData.h>
9 #include <svtkPointData.h>
10 #include <svtkMultiBlockDataSet.h>
21 template <
typename ParticleType,
int NArrayReal,
int NArrayInt>
22 ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>*
23 ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::New()
25 auto result =
new ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>;
26 result->InitializeObjectBase();
32 template <
typename ParticleType,
int NArrayReal,
int NArrayInt>
33 int ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::SetDataSource(
35 const std::map<std::string, std::vector<int>> & rStructs,
36 const std::map<std::string, int> & iStructs,
37 const std::map<std::string, std::vector<int>> & rArrays,
38 const std::map<std::string, int> & iArrays)
42 this->m_particles = particles;
45 int ret = this->SetArrayNames(rStructs, iStructs, rArrays, iArrays);
48 SENSEI_ERROR(
"problem with array names in SetDataSource");
55 template <
typename ParticleType,
int NArrayReal,
int NArrayInt>
56 int ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::SetArrayNames(
57 const std::map<std::string, std::vector<int>> & rStructs,
58 const std::map<std::string, int> & iStructs,
59 const std::map<std::string, std::vector<int>> & rArrays,
60 const std::map<std::string, int> & iArrays)
62 if(rStructs.size() <= ParticleType::NReal)
65 for(
auto s : rStructs)
67 for(
auto i : s.second)
69 if(i >= ParticleType::NReal)
71 SENSEI_ERROR(
"rStruct index exceeds internal storage size");
76 m_realStructs = rStructs;
80 SENSEI_ERROR(
"rStructs array size exceeds internal storage size");
84 if(iStructs.size() <= ParticleType::NInt)
87 for(
auto s : iStructs)
89 if(s.second >= ParticleType::NInt)
91 SENSEI_ERROR(
"iStructs index exceeds internal storage size");
95 m_intStructs = iStructs;
99 SENSEI_ERROR(
"iStructs array size exceeds internal storage size");
104 if(rArrays.size() <= NArrayReal)
107 for(
auto s : rArrays)
109 for(
auto i : s.second)
113 SENSEI_ERROR(
"rArrays index exceeds internal storage size");
118 m_realArrays = rArrays;
122 SENSEI_ERROR(
"rArrays array size exceeds internal storage size");
125 if(iArrays.size() <= NArrayInt)
128 for(
auto s : iArrays)
130 if(s.second >= NArrayInt)
132 SENSEI_ERROR(
"iArray index exceeds internal storage size");
136 m_intArrays = iArrays;
140 SENSEI_ERROR(
"iArrays array size exceeds internal storage size");
146 template <
typename ParticleType,
int NArrayReal,
int NArrayInt>
147 int ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetNumberOfMeshes(
unsigned int &numMeshes)
154 #if SENSEI_VERSION_MAJOR < 3
155 template <
typename ParticleType,
int NArrayReal,
int NArrayInt>
156 int ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetMeshName(
157 unsigned int id, std::string &meshName)
159 meshName = m_particlesName;
165 #if SENSEI_VERSION_MAJOR < 3
166 template <
typename ParticleType,
int NArrayReal,
int NArrayInt>
167 int ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetMeshHasGhostNodes(
168 const std::string &meshName,
177 #if SENSEI_VERSION_MAJOR < 3
178 template <
typename ParticleType,
int NArrayReal,
int NArrayInt>
179 int ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetMeshHasGhostCells(
180 const std::string &meshName,
189 #if SENSEI_VERSION_MAJOR < 3
190 template <
typename ParticleType,
int NArrayReal,
int NArrayInt>
191 int ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetNumberOfArrays(
192 const std::string &meshName,
194 unsigned int &numberOfArrays)
197 if(association == svtkDataObject::POINT)
199 numberOfArrays = m_realStructs.size()
200 + m_intStructs.size()
201 + m_realArrays.size()
202 + m_intArrays.size();
208 #if SENSEI_VERSION_MAJOR < 3
209 template <
typename ParticleType,
int NArrayReal,
int NArrayInt>
210 int ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetArrayName(
211 const std::string &meshName,
214 std::string &arrayName)
216 if(association == svtkDataObject::POINT)
218 if(index < m_realStructs.size())
220 auto a = m_realStructs.begin() + index;
221 arrayName = *(a).first;
224 if(index < m_intStructs.size())
226 int ind = index - m_realStructs.size();
227 auto a = m_intStructs.begin() + ind;
228 arrayName = *(a).first;
231 if(index < m_realArrays.size())
233 int ind = index - m_realStructs.size() - m_intStructs.size();
234 auto a = m_realArrays.begin() + ind;
235 arrayName = *(a).first;
238 if(index < m_intArrays.size())
240 int ind = index - m_realStructs.size() - m_intStructs.size() - m_realArrays.size();
241 auto a = m_intArrays.begin() + ind;
242 arrayName = *(a).first;
252 template <
typename ParticleType,
int NArrayReal,
int NArrayInt>
253 int ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetMesh(
254 const std::string &meshName,
256 svtkDataObject *&mesh)
261 MPI_Comm_size(this->GetCommunicator(), &nprocs);
262 MPI_Comm_rank(this->GetCommunicator(), &rank);
264 if (meshName != m_particlesName)
266 SENSEI_ERROR(
"No mesh named \"" << meshName <<
"\"")
269 svtkMultiBlockDataSet* mb = svtkMultiBlockDataSet::New();
277 mb->SetNumberOfBlocks(nprocs);
278 svtkPolyData *pd = BuildParticles();
279 mb->SetBlock(rank, pd);
287 template <
typename ParticleType,
int NArrayReal,
int NArrayInt>
288 int ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::AddGhostNodesArray(
290 const std::string &meshName)
292 if (meshName != m_particlesName)
294 SENSEI_ERROR(
"no mesh named \"" << meshName <<
"\"")
301 template <typename ParticleType,
int NArrayReal,
int NArrayInt>
302 int ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::AddGhostCellsArray(
304 const std::
string &meshName)
306 if (meshName != m_particlesName)
308 SENSEI_ERROR(
"no mesh named \"" << meshName <<
"\"")
315 template <typename ParticleType,
int NArrayReal,
int NArrayInt>
316 int ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::AddArray(
317 svtkDataObject* mesh,
318 const std::
string &meshName,
320 const std::
string &arrayName)
322 if (meshName != m_particlesName)
324 SENSEI_ERROR(
"no mesh named \"" << meshName <<
"\"");
328 if (association != svtkDataObject::POINT)
330 SENSEI_ERROR(
"Invalid association " << association);
334 if(m_realStructs.find(arrayName) != m_realStructs.end())
336 return this->AddParticlesAOSRealArray(arrayName, mesh);
339 if(m_intStructs.find(arrayName) != m_intStructs.end())
341 return this->AddParticlesAOSIntArray(arrayName, mesh);
344 if(m_realArrays.find(arrayName) != m_realArrays.end())
346 return this->AddParticlesSOARealArray(arrayName, mesh);
349 if(m_intArrays.find(arrayName) != m_intArrays.end())
351 return this->AddParticlesSOAIntArray(arrayName, mesh);
354 SENSEI_ERROR(
"Invalid array name " << arrayName);
359 template <
typename ParticleType,
int NArrayReal,
int NArrayInt>
360 int ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::ReleaseData()
362 this->m_particles =
nullptr;
367 #if SENSEI_VERSION_MAJOR >= 3
368 template <
typename ParticleType,
int NArrayReal,
int NArrayInt>
369 int ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetMeshMetadata(
371 sensei::MeshMetadataPtr &metadata)
373 sensei::TimeEvent<64> event(
"AmrMeshDataAdaptor::GetMeshMetadata");
377 MPI_Comm_size(this->GetCommunicator(), &nprocs);
378 MPI_Comm_rank(this->GetCommunicator(), &rank);
379 if (
id != 0 &&
id != 1)
381 SENSEI_ERROR(
"invalid mesh id " <<
id)
387 metadata->GlobalView =
false;
393 metadata->MeshName = m_particlesName;
396 metadata->MeshType = SVTK_MULTIBLOCK_DATA_SET;
399 metadata->BlockType = SVTK_POLY_DATA;
402 metadata->NumBlocks = nprocs;
405 metadata->NumBlocksLocal = {1};
414 #ifdef AMREX_SINGLE_PRECISION_PARTICLES
415 metadata->CoordinateType = SVTK_FLOAT;
417 metadata->CoordinateType = SVTK_DOUBLE;
430 metadata->NumArrays = m_realStructs.size()
431 + m_intStructs.size()
432 + m_realArrays.size()
433 + m_intArrays.size();
436 metadata->NumGhostCells = 0;
439 metadata->NumGhostNodes = 0;
445 metadata->StaticMesh = 0;
448 metadata->ArrayName = {};
449 for(
auto s : m_realStructs)
451 metadata->ArrayName.push_back(s.first);
453 for(
auto s : m_intStructs)
455 metadata->ArrayName.push_back(s.first);
457 for(
auto s : m_realArrays)
459 metadata->ArrayName.push_back(s.first);
461 for(
auto s : m_intArrays)
463 metadata->ArrayName.push_back(s.first);
467 metadata->ArrayCentering = {};
468 for(
auto s : m_realStructs)
470 metadata->ArrayCentering.push_back(svtkDataObject::POINT);
472 for(
auto s : m_intStructs)
474 metadata->ArrayCentering.push_back(svtkDataObject::POINT);
476 for(
auto s : m_realArrays)
478 metadata->ArrayCentering.push_back(svtkDataObject::POINT);
480 for(
auto s : m_intArrays)
482 metadata->ArrayCentering.push_back(svtkDataObject::POINT);
486 metadata->ArrayComponents = {};
487 for(
auto s : m_realStructs)
489 metadata->ArrayComponents.push_back(s.second.size());
491 for(
auto s : m_intStructs)
493 metadata->ArrayComponents.push_back(1);
495 for(
auto s : m_realArrays)
497 metadata->ArrayComponents.push_back(s.second.size());
499 for(
auto s : m_intArrays)
501 metadata->ArrayComponents.push_back(1);
505 metadata->ArrayType = {};
506 for(
auto s : m_realStructs)
508 #ifdef AMREX_SINGLE_PRECISION_PARTICLES
509 metadata->ArrayType.push_back(SVTK_FLOAT);
511 metadata->ArrayType.push_back(SVTK_DOUBLE);
514 for(
auto s : m_intStructs)
516 metadata->ArrayType.push_back(SVTK_INT);
518 for(
auto s : m_realArrays)
520 #ifdef AMREX_SINGLE_PRECISION_PARTICLES
521 metadata->ArrayType.push_back(SVTK_FLOAT);
523 metadata->ArrayType.push_back(SVTK_DOUBLE);
526 for(
auto s : m_intArrays)
528 metadata->ArrayType.push_back(SVTK_INT);
535 metadata->BlockOwner = {rank};
538 metadata->BlockIds = metadata->BlockOwner;
541 auto nptsOnProc = this->m_particles->TotalNumberOfParticles(
true,
true);
542 metadata->BlockNumPoints = {nptsOnProc};
545 metadata->BlockNumCells = {nptsOnProc};
548 metadata->BlockCellArraySize = {nptsOnProc};
556 if (metadata->Flags.BlockBoundsSet())
558 std::array<double,6> bounds({
560 std::numeric_limits<double>::lowest(),
561 #if (AMREX_SPACEDIM == 1)
563 #elif (AMREX_SPACEDIM == 2)
565 std::numeric_limits<double>::lowest(),
567 #elif (AMREX_SPACEDIM == 3)
569 std::numeric_limits<double>::lowest(),
571 std::numeric_limits<double>::lowest()
576 const auto& particles = this->m_particles->
GetParticles();
577 for (
int lev = 0; lev < particles.size(); lev++)
580 auto& pmap = particles[lev];
581 for (
const auto& kv : pmap)
584 auto& particle_tile = kv.second;
585 auto ptd = particle_tile.getConstParticleTileData();
588 long long numReal = particle_tile.numRealParticles();
589 for (
long long i = 0; i < numReal; ++i)
591 const auto &part = ptd[i];
594 #if (AMREX_SPACEDIM == 1)
595 bounds[0] = bounds[0] > part.pos(0) ? part.pos(0) : bounds[0];
596 bounds[1] = bounds[1] < part.pos(0) ? part.pos(0) : bounds[1];
597 #elif (AMREX_SPACEDIM == 2)
598 bounds[0] = bounds[0] > part.pos(0) ? part.pos(0) : bounds[0];
599 bounds[1] = bounds[1] < part.pos(0) ? part.pos(0) : bounds[1];
600 bounds[2] = bounds[2] > part.pos(1) ? part.pos(1) : bounds[2];
601 bounds[3] = bounds[3] < part.pos(1) ? part.pos(1) : bounds[3];
602 #elif (AMREX_SPACEDIM == 3)
603 bounds[0] = bounds[0] > part.pos(0) ? part.pos(0) : bounds[0];
604 bounds[1] = bounds[1] < part.pos(0) ? part.pos(0) : bounds[1];
605 bounds[2] = bounds[2] > part.pos(1) ? part.pos(1) : bounds[2];
606 bounds[3] = bounds[3] < part.pos(1) ? part.pos(1) : bounds[3];
607 bounds[4] = bounds[4] > part.pos(2) ? part.pos(2) : bounds[4];
608 bounds[5] = bounds[5] < part.pos(2) ? part.pos(2) : bounds[5];
615 metadata->BlockBounds = {bounds};
621 if (metadata->Flags.BlockArrayRangeSet())
623 SENSEI_ERROR(
"BlockArrayRange requested but not yet implemented.")
638 #if defined(SENSEI_DEBUG)
639 metadata->Validate(this->GetCommunicator(), sensei::MeshMetadataFlags());
640 metadata->ToStream(std::cerr);
648 template <
typename ParticleType,
int NArrayReal,
int NArrayInt>
649 svtkPolyData* ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::BuildParticles()
652 svtkPolyData* pd = svtkPolyData::New();
654 const auto& particles = this->m_particles->GetParticles();
655 long long numParticles = this->m_particles->TotalNumberOfParticles(
true,
true);
658 #ifdef AMREX_SINGLE_PRECISION_PARTICLES
659 svtkNew<svtkFloatArray> coords;
661 svtkNew<svtkDoubleArray> coords;
663 coords->SetName(
"coords");
664 coords->SetNumberOfComponents(3);
665 coords->SetNumberOfTuples(numParticles);
666 #ifdef AMREX_SINGLE_PRECISION_PARTICLES
667 float *pCoords = coords->GetPointer(0);
669 double *pCoords = coords->GetPointer(0);
677 svtkNew<svtkCellArray> vertex;
678 vertex->AllocateExact(numParticles, 1);
683 for (
int lev = 0; lev < particles.size(); lev++)
685 using MyParIter = ParIter_impl<ParticleType, NArrayReal, NArrayInt>;
686 for (MyParIter pti(*this->m_particles, lev); pti.isValid(); ++pti)
688 auto ptd = pti.GetParticleTile().getParticleTileData();
689 auto numReal = pti.numParticles();
691 for (
long long i = 0; i < numReal; ++i)
697 vertex->InsertNextCell(1);
698 vertex->InsertCellPoint(ptId);
700 #if (AMREX_SPACEDIM == 1)
701 pCoords[0] = part.pos(0);
704 #elif (AMREX_SPACEDIM == 2)
705 pCoords[0] = part.pos(0);
706 pCoords[1] = part.pos(1);
708 #elif (AMREX_SPACEDIM == 3)
709 pCoords[0] = part.pos(0);
710 pCoords[1] = part.pos(1);
711 pCoords[2] = part.pos(2);
721 svtkNew<svtkPoints> points;
722 points->SetData(coords);
725 pd->SetPoints(points);
726 pd->SetVerts(vertex);
732 template <
typename ParticleType,
int NArrayReal,
int NArrayInt>
733 int ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::AddParticlesIDArray(
734 svtkDataObject* mesh)
736 auto svtk_particles =
dynamic_cast<svtkPolyData*
>(mesh);
737 const auto& particles = this->m_particles->GetParticles();
738 auto nptsOnProc = this->m_particles->TotalNumberOfParticles(
true,
true);
741 svtkNew<svtkIntArray> idArray;
742 idArray->SetName(
"id");
743 idArray->SetNumberOfComponents(1);
744 idArray->SetNumberOfValues(nptsOnProc);
747 int *partIds = idArray->GetPointer(0);
750 using MyParIter = ParIter_impl<ParticleType, NArrayReal, NArrayInt>;
752 for (
int level = 0; level < particles.size(); ++level)
754 for (MyParIter pti(*this->m_particles, level); pti.isValid(); ++pti)
756 auto ptd = pti.GetParticleTile().getParticleTileData();
757 auto numReal = pti.numParticles();
758 for (
long long i = 0; i < numReal; ++i)
763 partIds[i] = part.id();
771 svtk_particles->GetPointData()->AddArray(idArray);
777 template <
typename ParticleType,
int NArrayReal,
int NArrayInt>
778 int ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::AddParticlesCPUArray(
779 svtkDataObject* mesh)
781 auto svtk_particles =
dynamic_cast<svtkPolyData*
>(mesh);
782 const auto& particles = this->m_particles->GetParticles();
783 auto nptsOnProc = this->m_particles->TotalNumberOfParticles(
true,
true);
786 svtkNew<svtkIntArray> cpuArray;
787 cpuArray->SetName(
"cpu");
788 cpuArray->SetNumberOfComponents(1);
789 cpuArray->SetNumberOfValues(nptsOnProc);
792 int* partCpu = cpuArray->GetPointer(0);
795 using MyParIter = ParIter_impl<ParticleType, NArrayReal, NArrayInt>;
796 for (
int level = 0; level < particles.size(); ++level)
798 for (MyParIter pti(*this->m_particles, level); pti.isValid(); ++pti)
800 auto ptd = pti.GetParticleTile().getParticleTileData();
801 auto numReal = pti.numParticles();
802 for (
long long i = 0; i < numReal; ++i)
807 partCpu[i] = part.cpu();
815 svtk_particles->GetPointData()->AddArray(cpuArray);
821 template <
typename ParticleType,
int NArrayReal,
int NArrayInt>
822 int ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::AddParticlesSOARealArray(
823 const std::string &arrayName,
824 svtkDataObject* mesh)
826 const long nParticles = this->m_particles->TotalNumberOfParticles(
true,
true);
829 RealDataMapType::iterator ait = m_realArrays.find(arrayName);
830 if (ait == m_realArrays.end())
832 SENSEI_ERROR(
"No real SOA named \"" << arrayName <<
"\"");
837 const std::vector<int> &indices = ait->second;
838 int nComps = indices.size();
841 for(
auto i : indices)
845 SENSEI_ERROR(
"Index out of bounds for real SOA named \"" << arrayName <<
"\"");
851 #ifdef AMREX_SINGLE_PRECISION_PARTICLES
852 svtkNew<svtkFloatArray> data;
854 svtkNew<svtkDoubleArray> data;
856 data->SetName(arrayName.c_str());
857 data->SetNumberOfComponents(nComps);
858 data->SetNumberOfTuples(nParticles);
860 #ifdef AMREX_SINGLE_PRECISION_PARTICLES
861 float* pData = data->GetPointer(0);
863 double* pData = data->GetPointer(0);
866 using MyParIter = ParIter_impl<ParticleType, NArrayReal, NArrayInt>;
867 for (
int level = 0; level < this->m_particles->numLevels(); ++level)
869 for (MyParIter pti(*this->m_particles, level); pti.isValid(); ++pti)
871 auto& particle_attributes = pti.GetStructOfArrays();
872 auto ptd = pti.GetParticleTile().getParticleTileData();
874 auto numReal = pti.numParticles();
876 for (
int j = 0; j < nComps; ++j)
878 int compInd = indices[j];
880 const auto &realData = particle_attributes.GetRealData(compInd);
882 for (
long long i = 0; i < numReal; ++i)
884 const auto &part = ptd[i];
887 pData[i*nComps + j] = realData[i];
891 pData += numReal * nComps;
897 MPI_Comm_rank(this->GetCommunicator(), &rank);
899 auto blocks =
dynamic_cast<svtkMultiBlockDataSet*
>(mesh);
901 auto block =
dynamic_cast<svtkPolyData*
>(blocks->GetBlock(rank));
902 block->GetPointData()->AddArray(data);
908 template <
typename ParticleType,
int NArrayReal,
int NArrayInt>
909 int ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::AddParticlesSOAIntArray(
910 const std::string &arrayName,
911 svtkDataObject* mesh)
914 auto nptsOnProc = this->m_particles->TotalNumberOfParticles(
true,
true);
917 IntDataMapType::iterator ait = m_intArrays.find(arrayName);
918 if (ait == m_intArrays.end())
920 SENSEI_ERROR(
"No int SOA named \"" << arrayName <<
"\"");
925 int index = ait->second;
928 if(index >= NArrayInt)
930 SENSEI_ERROR(
"Index out of bounds for int SOA named \"" << arrayName <<
"\"");
934 svtkNew<svtkIntArray> data;
935 data->SetName(arrayName.c_str());
936 data->SetNumberOfComponents(1);
937 data->SetNumberOfValues(nptsOnProc);
938 int* pData = data->GetPointer(0);
941 using MyParIter = ParIter_impl<ParticleType, NArrayReal, NArrayInt>;
942 for (
int level = 0; level< this->m_particles->numLevels(); level++)
944 for (MyParIter pti(*this->m_particles, level); pti.isValid(); ++pti)
946 auto& particle_attributes = pti.GetStructOfArrays();
947 auto ptd = pti.GetParticleTile().getParticleTileData();
949 auto numReal = pti.numParticles();
952 const auto &intData = particle_attributes.GetIntData(index);
954 for (
long long i = 0; i < numReal; ++i)
956 const auto &part = ptd[i];
959 pData[i] = intData[i];
968 MPI_Comm_rank(this->GetCommunicator(), &rank);
970 auto blocks =
dynamic_cast<svtkMultiBlockDataSet*
>(mesh);
972 auto block =
dynamic_cast<svtkPolyData*
>(blocks->GetBlock(rank));
973 block->GetPointData()->AddArray(data);
979 template <
typename ParticleType,
int NArrayReal,
int NArrayInt>
980 int ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::AddParticlesAOSRealArray(
981 const std::string &arrayName,
982 svtkDataObject* mesh)
985 const auto& particles = this->m_particles->GetParticles();
986 auto nptsOnProc = this->m_particles->TotalNumberOfParticles(
true,
true);
989 RealDataMapType::iterator ait = m_realStructs.find(arrayName);
990 if (ait == m_realStructs.end())
992 SENSEI_ERROR(
"No real AOS named \"" << arrayName <<
"\"");
997 std::vector<int> indices = ait->second;
998 int nComps = indices.size();
1001 for (
auto i : indices)
1003 if (i >= ParticleType::NReal)
1005 SENSEI_ERROR(
"Index out of bounds for real AOS named \"" << arrayName <<
"\"");
1011 #ifdef AMREX_SINGLE_PRECISION_PARTICLES
1012 svtkNew<svtkFloatArray> data;
1014 svtkNew<svtkDoubleArray> data;
1017 data->SetName(arrayName.c_str());
1018 data->SetNumberOfComponents(nComps);
1019 data->SetNumberOfTuples(nptsOnProc);
1021 #ifdef AMREX_SINGLE_PRECISION_PARTICLES
1022 float *pData = data->GetPointer(0);
1024 double *pData = data->GetPointer(0);
1027 if constexpr(!ParticleType::is_soa_particle) {
1030 using MyParIter = ParIter_impl<ParticleType, NArrayReal, NArrayInt>;
1031 for (
int level = 0; level<particles.size();level++)
1033 for (MyParIter pti(*this->m_particles, level); pti.isValid(); ++pti)
1035 auto& aos = pti.GetArrayOfStructs();
1037 auto numReal = pti.numParticles();
1039 for (
int j = 0; j < nComps; ++j)
1041 for (
long long i = 0; i < numReal; ++i)
1043 const auto &part = aos[i];
1046 pData[i*nComps + j] = part.rdata(indices[j]);
1050 pData += numReal * nComps;
1056 MPI_Comm_rank(this->GetCommunicator(), &rank);
1058 auto blocks =
dynamic_cast<svtkMultiBlockDataSet*
>(mesh);
1060 auto block =
dynamic_cast<svtkPolyData*
>(blocks->GetBlock(rank));
1061 block->GetPointData()->AddArray(data);
1069 template <
typename ParticleType,
int NArrayReal,
int NArrayInt>
1070 int ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::AddParticlesAOSIntArray(
1071 const std::string &arrayName,
1072 svtkDataObject* mesh)
1075 const auto& particles = this->m_particles->GetParticles();
1077 auto nptsOnProc = this->m_particles->TotalNumberOfParticles(
true,
true);
1080 IntDataMapType::iterator ait = m_intStructs.find(arrayName);
1081 if (ait == m_intStructs.end())
1083 SENSEI_ERROR(
"No int AOS named \"" << arrayName <<
"\"");
1088 int index = ait->second;
1091 if(index >= ParticleType::NInt)
1093 SENSEI_ERROR(
"Index out of bounds for int AOS named \"" << arrayName <<
"\"");
1097 if constexpr(!ParticleType::is_soa_particle) {
1100 svtkNew<svtkIntArray> data;
1101 data->SetName(arrayName.c_str());
1102 data->SetNumberOfComponents(1);
1103 data->SetNumberOfValues(nptsOnProc);
1104 int* pData = data->GetPointer(0);
1106 using MyParIter = ParIter_impl<ParticleType, NArrayReal, NArrayInt>;
1107 for (
int level = 0; level<particles.size(); ++level)
1109 for (MyParIter pti(*this->m_particles, level); pti.isValid(); ++pti)
1111 const auto& aos = pti.GetArrayOfStructs();
1113 long long numReal = pti.numParticles();
1114 for (
long long i = 0; i < numReal; ++i)
1116 const auto &part = aos[i];
1119 pData[i] = part.idata(index);
1128 MPI_Comm_rank(this->GetCommunicator(), &rank);
1130 auto blocks =
dynamic_cast<svtkMultiBlockDataSet*
>(mesh);
1132 auto block =
dynamic_cast<svtkPolyData*
>(blocks->GetBlock(rank));
1133 block->GetPointData()->AddArray(data);
double amrex_particle_real
Definition: AMReX_REAL.H:64
if(!(yy_init))
Definition: amrex_iparser.lex.nolint.H:935
A distributed container for Particles sorted onto the levels, grids, and tiles of a block-structured ...
Definition: AMReX_ParticleContainer.H:145
const Vector< ParticleLevel > & GetParticles() const
Return the underlying Vector (over AMR levels) of ParticleLevels. Const version.
Definition: AMReX_ParticleContainer.H:986
@ max
Definition: AMReX_ParallelReduce.H:17
Definition: AMReX_Amr.cpp:49
Definition: AMReX_MakeParticle.H:16