aboutsummaryrefslogtreecommitdiff
path: root/Source/Diagnostics/ReducedDiags/FieldProbe.H
blob: 2b23226432991cc78be8085c6530929973274d54 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* Copyright 2021 Lorenzo Giacomel, Neil Zaim, Yinjian Zhao
 *                Elisa Rheaume, Axel Huebl
 *
 * This file is part of WarpX.
 *
 * License: BSD-3-Clause-LBNL
 */

#ifndef WARPX_DIAGNOSTICS_REDUCEDDIAGS_FIELDPROBE_H_
#define WARPX_DIAGNOSTICS_REDUCEDDIAGS_FIELDPROBE_H_

#include "ReducedDiags.H"
#include "FieldProbeParticleContainer.H"

#include <AMReX.H>
#include <AMReX_Vector.H>

#include <unordered_map>
#include <string>
#include <vector>

/**
 * This enumeration is used for assigning structural geometry levels (point vs line vs plane)
 */
enum struct DetectorGeometry
{
    Point = 0,
    Line,
    Plane
};

/**
 *  This class mainly contains a function that computes the value of each component
 * of the EM field at a given point
 */
class FieldProbe : public ReducedDiags
{
public:

    /**
     * constructor
     * @param[in] rd_name reduced diags names
     */
    FieldProbe (std::string rd_name);

    /**
     * This function assins test/data particles to constructed environemnt
     */
    void InitData () override final;

    /** Redistribute parallel data structures during load balance
     */
    void LoadBalance () override final;

    /**
     * This function computes the value of Ex, Ey, Ez, Bx, By, Bz and at a given point
     *
     * @param[in] step current time step
     */
    void ComputeDiags (int step) override final;

    /*
     * Define constants used throughout FieldProbe
     */

    //! noutputs is 11 for particle id + (x, y, z, Ex, Ey, Ez, Bx, By, Bz, S)
    static const int noutputs = 11;

private:
    amrex::Real x_probe = 0.;
    amrex::Real y_probe = 0.;
    amrex::Real x1_probe = 0.;
    amrex::Real y1_probe = 0.;
    amrex::Real target_normal_x = 0.;
    amrex::Real target_normal_y = 1.;
    amrex::Real target_normal_z = 0.;
    amrex::Real target_up_x = 0.;
    amrex::Real target_up_y = 0.;
    amrex::Real target_up_z = 1.;
    amrex::Real z_probe, z1_probe;
    amrex::Real detector_radius;

    //! counts number of particles for all MPI ranks
    long m_valid_particles {0};

    //! remember the last time @see ComputeDiags was called to count the number of steps in between (for non-integrated detectors)
    int m_last_compute_step = 0;

    //! determines geometry of detector point distribution
    DetectorGeometry m_probe_geometry = DetectorGeometry::Point;

    //! determines number of particles places for non-point geometries
    int m_resolution = 0;

    //! Empty vector for to which data is pushed
    amrex::Vector<amrex::Real> m_data;

    //! Empty array to be used by IOProcessor node to store and output data
    amrex::Vector<amrex::Real> m_data_out;

    //! this is the particle container in which probe particles are stored
    FieldProbeParticleContainer m_probe;

    //! if true, integrate values over time instead of probing instantaneous values
    bool m_field_probe_integrate = false;

    //! particle shape used for field gather
    int interp_order = 1;

    //! Judges whether to follow a moving window
    bool do_moving_window_FP = false;

    /**
     * Built-in function in ReducedDiags to write out test data
     */
    virtual void WriteToFile (int step) const override;

    /** Check if the probe is in the simulation domain boundary
     */
    bool ProbeInDomain () const;

    /**
     * Simple utility function to normalize the components of a "vector"
     */
    void normalize(amrex::Real &AMREX_RESTRICT x, amrex::Real &AMREX_RESTRICT y,
                   amrex::Real &AMREX_RESTRICT z){
        const amrex::Real mag = std::sqrt(x*x + y*y + z*z);
        x /= mag;
        y /= mag;
        z /= mag;
    }
};

#endif // WARPX_DIAGNOSTICS_REDUCEDDIAGS_FIELDPROBE_H_