ARTEMIS
BTDiagnostics.H
Go to the documentation of this file.
1 /* Copyright 2021 Revathi Jambunathan
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 #ifndef WARPX_BTDIAGNOSTICS_H_
8 #define WARPX_BTDIAGNOSTICS_H_
9 
10 #include "Diagnostics.H"
12 #include "Utils/WarpXConst.H"
14 
15 #include <AMReX_Box.H>
16 #include <AMReX_Geometry.H>
17 #include <AMReX_IntVect.H>
18 #include <AMReX_MultiFab.H>
19 #include <AMReX_REAL.H>
20 #include <AMReX_RealBox.H>
21 #include <AMReX_Vector.H>
22 
23 #include <limits>
24 #include <memory>
25 #include <string>
26 
27 class
28 BTDiagnostics final : public Diagnostics
29 {
30 public:
31 
32  BTDiagnostics (int i, std::string name);
33 
34 private:
36  bool m_plot_raw_fields = false;
38  bool m_plot_raw_fields_guards = false;
40  void ReadParameters ();
50  void Flush (int i_buffer) override;
59  bool DoDump (int step, int i_buffer, bool force_flush=false) override;
67  bool DoComputeAndPack (int step, bool force_flush=false) override;
69  void DerivedInitData () override;
76  void InitializeFieldFunctors (int lev) override;
83  void InitializeFieldFunctorsRZopenPMD (int lev) override;
95  void AddRZModesToOutputNames (const std::string& field, const int ncomp, bool cellcenter_data);
100  void InitializeParticleBuffer () override;
104  void PrepareBufferData () override;
106  void UpdateBufferData () override;
114  void PrepareFieldDataForOutput () override;
116  void PrepareParticleDataForOutput() override;
117 
126  bool GetZSliceInDomainFlag (const int i_buffer, const int lev);
127 
134  bool GetKIndexInSnapshotBoxFlag (const int i_buffer, const int lev);
135 
141  void InitializeBufferData ( int i_buffer , int lev, bool restart=false) override;
145  bool m_do_back_transformed_fields = true;
149  bool m_do_back_transformed_particles = true;
150 
158  amrex::Real m_gamma_boost;
159  amrex::Real m_beta_boost;
165 
167  int m_num_snapshots_lab = std::numeric_limits<int>::lowest();
169  amrex::Real m_dt_snapshots_lab = std::numeric_limits<amrex::Real>::lowest();
173  amrex::Real m_dz_snapshots_lab = 0.0;
174 
176  int m_buffer_size = 256;
178  int m_max_box_size = 256;
179 
260  void DefineCellCenteredMultiFab(int lev);
267  void DefineFieldBufferMultiFab (const int i_buffer, const int lev);
268 
275  void DefineSnapshotGeometry (const int i_buffer, const int lev);
276 
281  amrex::Real UpdateCurrentZBoostCoordinate(amrex::Real t_lab, amrex::Real t_boost)
282  {
283  amrex::Real current_z_boost = (t_lab / m_gamma_boost - t_boost) * PhysConst::c / m_beta_boost;
284  return current_z_boost;
285  }
290  amrex::Real UpdateCurrentZLabCoordinate(amrex::Real t_lab, amrex::Real t_boost)
291  {
292  amrex::Real current_z_lab = (t_lab - t_boost / m_gamma_boost ) * PhysConst::c / m_beta_boost;
293  return current_z_lab;
294  }
300  amrex::Real dz_lab (amrex::Real dt, amrex::Real ref_ratio);
306  int k_index_zlab (int i_buffer, int lev);
312  bool buffer_full (int i_buffer) {
313  return (k_index_zlab(i_buffer,0) == m_buffer_box[i_buffer].smallEnd(m_moving_window_dir));
314  }
315 
320  bool buffer_empty (int i_buffer) {
321  return ( m_buffer_counter[i_buffer] == 0) ;
322  }
323 
326 
330  void NullifyFirstFlush(int i_buffer) {m_first_flush_after_restart[i_buffer] = 0;}
331 
336 
340  void ResetBufferCounter(int i_buffer) {
341  m_buffer_counter[i_buffer] = 0;
342  }
346  void IncrementBufferFlushCounter(int i_buffer) {
347  m_buffer_flush_counter[i_buffer]++;
348  }
354  void SetSnapshotFullStatus (const int i_buffer);
359 #ifdef WARPX_DIM_RZ
360  amrex::Vector< std::string > m_cellcenter_varnames = {"Er", "Et", "Ez",
361  "Br", "Bt", "Bz",
362  "jr", "jt", "jz", "rho"};
363  amrex::Vector< std::string > m_cellcenter_varnames_fields = {"Er", "Et", "Ez",
364  "Br", "Bt", "Bz",
365  "jr", "jt", "jz",
366  "rho"};
367 #else
368  amrex::Vector< std::string > m_cellcenter_varnames = {"Ex", "Ey", "Ez",
369  "Bx", "By", "Bz",
370  "jx", "jy", "jz", "rho"};
371 #endif
372 
373 
377  void MergeBuffersForPlotfile (int i_snapshot);
381  void InterleaveBufferAndSnapshotHeader ( std::string buffer_Header,
382  std::string snapshot_Header);
386  void InterleaveFabArrayHeader( std::string Buffer_FabHeaderFilename,
387  std::string snapshot_FabHeaderFilename,
388  std::string newsnapshot_FabFilename);
392  void InterleaveSpeciesHeader(std::string buffer_species_Header_path,
393  std::string snapshot_species_Header_path,
394  std::string species_name, const int new_data_index);
395 
399  void InterleaveParticleDataHeader( std::string buffer_ParticleHdrFilename,
400  std::string snapshot_ParticleHdrFilename);
403  void InitializeParticleFunctors () override;
404 
406  void UpdateTotalParticlesFlushed(int i_buffer);
408  void ResetTotalParticlesInBuffer(int i_buffer);
410  void ClearParticleBuffer(int i_buffer);
412  void RedistributeParticleBuffer (const int i_buffer);
413  void UpdateVarnamesForRZopenPMD();
414 
415  amrex::Real gettlab (int i_buffer) override {return m_t_lab[i_buffer];}
416  void settlab (int i_buffer, amrex::Real tlab) override {m_t_lab[i_buffer] = tlab; }
417  int get_buffer_k_index_hi (int i_buffer) override {return m_buffer_k_index_hi[i_buffer]; }
418  void set_buffer_k_index_hi (int i_buffer, int kindex) override {m_buffer_k_index_hi[i_buffer] = kindex;}
419  amrex::Real get_snapshot_domain_lo (int i_buffer, int idim) override {return m_snapshot_domain_lab[i_buffer].lo(idim); }
420  amrex::Real get_snapshot_domain_hi (int i_buffer, int idim) override {return m_snapshot_domain_lab[i_buffer].hi(idim); }
421  int get_flush_counter (int i_buffer) override {return m_buffer_flush_counter[i_buffer]; }
422  void set_flush_counter ([[maybe_unused]] int i_buffer, int flush_counter) override { m_buffer_flush_counter[i_buffer] = flush_counter; }
423  int get_last_valid_Zslice ( int i_buffer) override { return m_lastValidZSlice[i_buffer]; }
424  void set_last_valid_Zslice ( int i_buffer, int last_valid_Zslice) override { m_lastValidZSlice[i_buffer] = last_valid_Zslice; }
425  int get_snapshot_full_flag ( int i_buffer) override { return m_snapshot_full[i_buffer]; }
426  void set_snapshot_full ( int i_buffer, int snapshot_full) override { m_snapshot_full[i_buffer] = snapshot_full; }
427 };
428 #endif // WARPX_BTDIAGNOSTICS_H_
Definition: BTDiagnostics.H:29
amrex::Real m_beta_boost
Definition: BTDiagnostics.H:159
int m_moving_window_dir
Definition: BTDiagnostics.H:164
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_cell_centered_data
Definition: BTDiagnostics.H:250
void IncrementBufferFlushCounter(int i_buffer)
Definition: BTDiagnostics.H:346
amrex::Real UpdateCurrentZLabCoordinate(amrex::Real t_lab, amrex::Real t_boost)
Definition: BTDiagnostics.H:290
amrex::Vector< amrex::RealBox > m_snapshot_domain_lab
Definition: BTDiagnostics.H:184
amrex::Vector< int > m_lastValidZSlice
Definition: BTDiagnostics.H:236
void set_last_valid_Zslice(int i_buffer, int last_valid_Zslice) override
Definition: BTDiagnostics.H:424
amrex::Vector< amrex::RealBox > m_buffer_domain_lab
Definition: BTDiagnostics.H:187
amrex::Vector< int > m_buffer_counter
Definition: BTDiagnostics.H:222
amrex::Vector< amrex::Real > m_old_z_boost
Definition: BTDiagnostics.H:204
void set_snapshot_full(int i_buffer, int snapshot_full) override
Definition: BTDiagnostics.H:426
amrex::Vector< int > m_snapshot_full
Definition: BTDiagnostics.H:231
int get_snapshot_full_flag(int i_buffer) override
Definition: BTDiagnostics.H:425
void NullifyFirstFlush(int i_buffer)
Definition: BTDiagnostics.H:330
amrex::Vector< amrex::Vector< std::unique_ptr< ComputeDiagFunctor const > > > m_cell_center_functors
Definition: BTDiagnostics.H:254
amrex::Real gettlab(int i_buffer) override
Definition: BTDiagnostics.H:415
utils::parser::BTDIntervalsParser m_intervals
Definition: BTDiagnostics.H:42
void settlab(int i_buffer, amrex::Real tlab) override
Definition: BTDiagnostics.H:416
amrex::Vector< amrex::Real > m_current_z_lab
Definition: BTDiagnostics.H:198
amrex::Real get_snapshot_domain_hi(int i_buffer, int idim) override
Definition: BTDiagnostics.H:420
bool buffer_full(int i_buffer)
Definition: BTDiagnostics.H:312
amrex::Vector< int > m_field_buffer_multifab_defined
Definition: BTDiagnostics.H:335
amrex::Vector< int > m_max_buffer_multifabs
Definition: BTDiagnostics.H:227
bool buffer_empty(int i_buffer)
Definition: BTDiagnostics.H:320
void set_buffer_k_index_hi(int i_buffer, int kindex) override
Definition: BTDiagnostics.H:418
amrex::Vector< int > m_buffer_flush_counter
Definition: BTDiagnostics.H:239
amrex::Vector< amrex::Box > m_buffer_box
Definition: BTDiagnostics.H:195
amrex::Vector< amrex::Real > m_current_z_boost
Definition: BTDiagnostics.H:201
amrex::Vector< int > m_buffer_k_index_hi
Definition: BTDiagnostics.H:243
amrex::Real m_gamma_boost
Definition: BTDiagnostics.H:158
amrex::Vector< amrex::IntVect > m_snapshot_ncells_lab
Definition: BTDiagnostics.H:189
amrex::Vector< amrex::Vector< amrex::Geometry > > m_geom_snapshot
Definition: BTDiagnostics.H:215
int get_last_valid_Zslice(int i_buffer) override
Definition: BTDiagnostics.H:423
amrex::Real get_snapshot_domain_lo(int i_buffer, int idim) override
Definition: BTDiagnostics.H:419
int get_flush_counter(int i_buffer) override
Definition: BTDiagnostics.H:421
void ResetBufferCounter(int i_buffer)
Definition: BTDiagnostics.H:340
amrex::Vector< int > m_first_flush_after_restart
Definition: BTDiagnostics.H:325
amrex::Vector< amrex::Box > m_snapshot_box
Definition: BTDiagnostics.H:192
amrex::Real UpdateCurrentZBoostCoordinate(amrex::Real t_lab, amrex::Real t_boost)
Definition: BTDiagnostics.H:281
amrex::Vector< amrex::Real > m_t_lab
Definition: BTDiagnostics.H:181
void set_flush_counter([[maybe_unused]] int i_buffer, int flush_counter) override
Definition: BTDiagnostics.H:422
int get_buffer_k_index_hi(int i_buffer) override
Definition: BTDiagnostics.H:417
amrex::Vector< int > m_snapshot_geometry_defined
Definition: BTDiagnostics.H:333
base class for diagnostics. Contains main routines to filter, compute and flush diagnostics.
Definition: Diagnostics.H:31
This class is a parser for multiple slices of the form x,y,z,... where x, y and z are slices of the f...
Definition: IntervalsParser.H:177
static constexpr auto c
vacuum speed of light [m/s]
Definition: constant.H:44
i
Definition: check_interp_points_and_weights.py:174
string name
Definition: stencil.py:452
int dt
Definition: stencil.py:440
string field
Definition: video_yt.py:31