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