aboutsummaryrefslogtreecommitdiff
path: root/Source/QED/BreitWheelerEngineWrapper.cpp
blob: 97934589a64eab10995a323fbff42825728fcb55 (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
#include "BreitWheelerEngineWrapper.h"
//This file provides a wrapper aroud the breit_wheeler engine
//provided by the PICSAR library

// Functors ==================================

// Initialization of the optical depth
AMREX_GPU_DEVICE
amrex::Real
BreitWheelerGetOpticalDepth::operator() () const
{
    return WarpXBreitWheelerWrapper::
        internal_get_optical_depth(amrex::Random());
}
//____________________________________________

// Evolution of the optical depth (returns true if
// an event occurs)
AMREX_GPU_DEVICE
bool BreitWheelerEvolveOpticalDepth::operator()(
    amrex::Real px, amrex::Real py, amrex::Real pz, 
    amrex::Real ex, amrex::Real ey, amrex::Real ez,
    amrex::Real bx, amrex::Real by, amrex::Real bz,
    amrex::Real dt, amrex::Real& opt_depth) const
{
    bool has_event_happend = false;
    amrex::Real dummy_lambda = 1.0;
    amrex::Real unused_event_time = 0.0;

    const auto table = picsar::multi_physics::lookup_1d<amrex::Real>
        (innards->TTfunc_data.size(),
         innards->TTfunc_coords.data(),
         innards->TTfunc_data.data());

    WarpXBreitWheelerWrapper::internal_evolve_opt_depth_and_determine_event(
        px, py, pz,
        ex, ey, ez,
        bx, by, bz,
        dt, opt_depth, 
        has_event_happend, unused_event_time,
        dummy_lambda, 
        table,
        innards->ctrl);

    return has_event_happend;
}

// Factory class =============================

BreitWheelerEngine::BreitWheelerEngine (){}

//Builds the functor to initialize the optical depth
BreitWheelerGetOpticalDepth BreitWheelerEngine::build_optical_depth_functor ()
{
    return BreitWheelerGetOpticalDepth();
}

//Builds the functor to evolve the optical depth
BreitWheelerEvolveOpticalDepth BreitWheelerEngine::build_evolve_functor ()
{
    AMREX_ALWAYS_ASSERT(lookup_tables_initialized);

    return BreitWheelerEvolveOpticalDepth(&innards);         
}
    

//Initializes the Lookup tables using the default settings 
//provided by the library
void BreitWheelerEngine::computes_lookup_tables_default ()
{
    //A control parameters structure
    //with the default values provided by the library
    WarpXBreitWheelerWrapperCtrl ctrl_default;

    computes_lookup_tables(ctrl_default);

    lookup_tables_initialized = true;
}

bool BreitWheelerEngine::are_lookup_tables_initialized () const
{
    return lookup_tables_initialized;
}

//Private function which actually computes the lookup tables
void BreitWheelerEngine::computes_lookup_tables (
    WarpXBreitWheelerWrapperCtrl ctrl)
{
    //Lambda is not actually used if S.I. units are enabled
    WarpXBreitWheelerWrapper bw_engine(std::move(DummyStruct()), 1.0, ctrl);
    
    bw_engine.compute_dN_dt_lookup_table();
    //bw_engine.compute_cumulative_pair_table();

    auto bw_innards_picsar = bw_engine.export_innards();  

    //Copy data in a GPU-friendly data-structure
    innards.ctrl = bw_innards_picsar.bw_ctrl;
    innards.TTfunc_coords.assign(bw_innards_picsar.TTfunc_table_coords_ptr, 
        bw_innards_picsar.TTfunc_table_coords_ptr + 
        bw_innards_picsar.TTfunc_table_coords_how_many);
    innards.TTfunc_data.assign(bw_innards_picsar.TTfunc_table_data_ptr,
        bw_innards_picsar.TTfunc_table_data_ptr + 
        bw_innards_picsar.TTfunc_table_data_how_many);
    //____
}

//============================================