Block-Structured AMR Software Framework
AMReX_ParticleInSituBridge.H
Go to the documentation of this file.
1 #ifndef AMReX_ParticleInSituBridge_H
2 #define AMReX_ParticleInSituBridge_H
3 
4 #include <AMReX_Config.H>
5 #ifdef AMREX_PARTICLES
6 #include <AMReX_Vector.H>
7 #include <AMReX_AmrParticles.H>
8 #ifdef AMREX_USE_SENSEI_INSITU
9 #include <AMReX_InSituBridge.H>
11 #include <AnalysisAdaptor.h>
12 #include <Profiler.h>
13 #include <chrono>
14 #endif
15 
16 namespace amrex
17 {
20 class ParticleInSituBridge : public InSituBridge
21 {
22 public:
23  ParticleInSituBridge() {}
24  ~ParticleInSituBridge() {}
25 
26  ParticleInSituBridge(const ParticleInSituBridge&) = delete;
27  void operator=(const ParticleInSituBridge&) = delete;
28 
29  // invoke the in situ analysis with data from an AmrMesh
30  // instance.
31  template<typename ParticleType, int NArrayReal, int NArrayInt>
32  int update(
33  const double time,
34  const int time_step,
36  const std::map<std::string, std::vector<int>> & particles_rStructs = {},
37  const std::map<std::string, int> & particles_iStructs = {},
38  const std::map<std::string, std::vector<int>> & particles_rArrays = {},
39  const std::map<std::string, int> & particles_iArrays = {});
40 };
41 
42 template<typename ParticleType, int NArrayReal, int NArrayInt>
43 int ParticleInSituBridge::update(
44  const double time,
45  const int time_step,
47  const std::map<std::string, std::vector<int>> & particles_rStructs,
48  const std::map<std::string, int> & particles_iStructs,
49  const std::map<std::string, std::vector<int>> & particles_rArrays,
50  const std::map<std::string, int> & particles_iArrays)
51 {
52  int ret = 0;
53 #if defined(AMREX_USE_SENSEI_INSITU)
54  if (doUpdate())
55  {
56  sensei::TimeEvent<64> event("ParticleInSituBridge::update");
57 
58  amrex::Print() << "SENSEI Particles Begin update..." << std::endl;
59  auto t0 = std::chrono::high_resolution_clock::now();
60 
61  if (!particles)
62  {
63  SENSEI_ERROR("no particles presented at update call");
64  return -1;
65  }
66 
67  ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt> *data_adaptor
68  = ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::New();
69 
70  if (comm != MPI_COMM_NULL)
71  data_adaptor->SetCommunicator(comm);
72 
73  data_adaptor->SetDataSource(particles, particles_rStructs,
74  particles_iStructs, particles_rArrays, particles_iArrays);
75 
76  data_adaptor->SetDataTime(time);
77  data_adaptor->SetDataTimeStep(time_step);
78  ret = analysis_adaptor->Execute(data_adaptor, nullptr) ? 0 : -1;
79  data_adaptor->ReleaseData();
80  data_adaptor->Delete();
81 
82  auto t1 = std::chrono::high_resolution_clock::now();
83  auto dt = std::chrono::duration_cast<std::chrono::duration<double>>(t1 - t0);
84  amrex::Print() << "SENSEI update complete (" << dt.count() << " sec)" << std::endl;
85  }
86 #endif
87  return ret;
88 }
89 }
90 #endif
91 #endif
static constexpr int MPI_COMM_NULL
Definition: AMReX_ccse-mpi.H:55
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
Definition: AMReX_Amr.cpp:49