Block-Structured AMR Software Framework
AMReX_AmrParticleInSituBridge.H
Go to the documentation of this file.
1 #ifndef AMReX_AmrParticleInSituBridge_H
2 #define AMReX_AmrParticleInSituBridge_H
3 
4 #include <AMReX_Config.H>
5 #ifdef AMREX_PARTICLES
6 #include <AMReX_Vector.H>
7 #include <AMReX_AmrParticles.H>
8 #include <AMReX_Amr.H>
9 #ifdef AMREX_USE_SENSEI_INSITU
11 #include <AMReX_InSituBridge.H>
12 #include <AnalysisAdaptor.h>
13 #include <Profiler.h>
14 #include <chrono>
15 #endif
16 
17 namespace amrex
18 {
19 
21 class AmrParticleInSituBridge : public InSituBridge
22 {
23 public:
24  AmrParticleInSituBridge() {}
25  ~AmrParticleInSituBridge() {}
26 
27  AmrParticleInSituBridge(const AmrParticleInSituBridge&) = delete;
28  void operator=(const AmrParticleInSituBridge&) = delete;
29 
33  template<typename ParticleType, int NArrayReal, int NArrayInt>
34  int update(amrex::Amr *amr,
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 AmrParticleInSituBridge::update(
44  amrex::Amr *amr,
46  const std::map<std::string, std::vector<int>> & particles_rStructs,
47  const std::map<std::string, int> & particles_iStructs,
48  const std::map<std::string, std::vector<int>> & particles_rArrays,
49  const std::map<std::string, int> & particles_iArrays)
50 {
51  int ret = 0;
52 #if defined(AMREX_USE_SENSEI_INSITU)
53  if (doUpdate())
54  {
55  sensei::TimeEvent<64> event("AmrParticleInSituBridge::update");
56 
57  amrex::Print() << "SENSEI Particles Begin update..." << std::endl;
58  auto t0 = std::chrono::high_resolution_clock::now();
59 
60  if(!particles)
61  {
62  SENSEI_ERROR("no particles presented at update call");
63  return -1;
64  }
65 
66  amrex::AmrParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt> *data_adaptor
67  = amrex::AmrParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::New();
68 
69  if (comm != MPI_COMM_NULL)
70  data_adaptor->SetCommunicator(comm);
71 
72  data_adaptor->SetDataSource(amr, particles, particles_rStructs,
73  particles_iStructs, particles_rArrays, particles_iArrays);
74 
75  data_adaptor->SetDataTime(amr->cumTime());
76  data_adaptor->SetDataTimeStep(amr->levelSteps(0));
77  ret = analysis_adaptor->Execute(data_adaptor, nullptr) ? 0 : -1;
78  data_adaptor->ReleaseData();
79  data_adaptor->Delete();
80 
81  auto t1 = std::chrono::high_resolution_clock::now();
82  auto dt = std::chrono::duration_cast<std::chrono::duration<double>>(t1 - t0);
83  amrex::Print() << "SENSEI update complete (" << dt.count() << " sec)" << std::endl;
84  }
85 #endif
86  return ret;
87 }
88 }
89 #endif
90 #endif
static constexpr int MPI_COMM_NULL
Definition: AMReX_ccse-mpi.H:55
Manage hierarchy of levels for time-dependent AMR computations.
Definition: AMReX_Amr.H:35
int levelSteps(int lev) const noexcept
Number of time steps at specified level.
Definition: AMReX_Amr.H:103
Real cumTime() const noexcept
Physical time.
Definition: AMReX_Amr.H:89
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