aboutsummaryrefslogtreecommitdiff
path: root/Source/Diagnostics/FlushFormats/FlushFormatSensei.cpp
blob: 060c0e4a5e9c974086a24e9e58c3e5a6397dc1dd (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
#include "Utils/WarpXProfilerWrapper.H"
#include "FlushFormatSensei.H"

#include "WarpX.H"

#ifdef AMREX_USE_SENSEI_INSITU
# include <AMReX_AmrMeshParticleInSituBridge.H>
#endif

FlushFormatSensei::FlushFormatSensei () :
    m_insitu_pin_mesh(0), m_insitu_bridge(nullptr),
    m_amr_mesh(nullptr)
{}

FlushFormatSensei::FlushFormatSensei (amrex::AmrMesh *amr_mesh,
    std::string diag_name) :
    m_insitu_pin_mesh(0), m_insitu_bridge(nullptr),
    m_amr_mesh(amr_mesh)
{
#ifndef AMREX_USE_SENSEI_INSITU
    amrex::ignore_unused(m_insitu_pin_mesh, m_insitu_bridge, m_amr_mesh, diag_name);
#else
    amrex::ParmParse pp_diag_name(diag_name);

    pp_diag_name.query("sensei_config", m_insitu_config);
    pp_diag_name.query("sensei_pin_mesh", m_insitu_pin_mesh);

    m_insitu_bridge = new amrex::AmrMeshParticleInSituBridge;
    m_insitu_bridge->setEnabled(true);
    m_insitu_bridge->setConfig(m_insitu_config);
    m_insitu_bridge->setPinMesh(m_insitu_pin_mesh);

    WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
        m_amr_mesh && !m_insitu_bridge->initialize(),
        "FlushFormtSensei::FlushFormatSensei : "
        "Failed to initialize the in situ bridge."
    );
    m_insitu_bridge->setFrequency(1);
#endif
}

#ifdef AMREX_USE_SENSEI_INSITU
FlushFormatSensei::~FlushFormatSensei ()
{
    delete m_insitu_bridge;
}
#else
FlushFormatSensei::~FlushFormatSensei () = default;
#endif

void
FlushFormatSensei::WriteToFile (
    const amrex::Vector<std::string> varnames,
    const amrex::Vector<amrex::MultiFab>& mf,
    amrex::Vector<amrex::Geometry>& geom,
    const amrex::Vector<int> iteration, const double time,
    const amrex::Vector<ParticleDiag>& particle_diags,
    int nlev, const std::string prefix, int file_min_digits,
    bool plot_raw_fields, bool plot_raw_fields_guards,
    const bool use_pinned_pc,
    bool isBTD, int /*snapshotID*/, int /*bufferID*/, int /*numBuffers*/,
    const amrex::Geometry& /*full_BTD_snapshot*/, bool /*isLastBTDFlush*/,
    const amrex::Vector<int>& totalParticlesFlushedAlready) const
{
    amrex::ignore_unused(
        geom, nlev, prefix, file_min_digits,
        plot_raw_fields, plot_raw_fields_guards,
        use_pinned_pc,
        totalParticlesFlushedAlready);

#ifndef AMREX_USE_SENSEI_INSITU
    amrex::ignore_unused(varnames, mf, iteration, time, particle_diags,
                         isBTD);
#else
    WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
        !isBTD,
        "In-situ visualization is not currently supported for back-transformed diagnostics.");

    WARPX_PROFILE("FlushFormatSensei::WriteToFile()");
    const std::string& filename = amrex::Concatenate(prefix, iteration[0], file_min_digits);
    amrex::Print() << Utils::TextMsg::Info("Writing Sensei file " + filename);

    amrex::Vector<amrex::MultiFab> *mf_ptr =
        const_cast<amrex::Vector<amrex::MultiFab>*>(&mf);

    auto particles = particle_diags[0].getParticleContainer();
    bool didUpdate = m_insitu_bridge->update(
        iteration[0], time, m_amr_mesh,{mf_ptr}, {varnames},
        particles, {}, {}, {{"u",{0,1,2}}}, {});

    WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
        !didUpdate,
        "FlushFormatSensei::WriteToFile : "
        "Failed to update the in situ bridge."
    );
#endif
}

void
FlushFormatSensei::WriteParticles (
    const amrex::Vector<ParticleDiag>& particle_diags) const
{
    amrex::ignore_unused(particle_diags);
#ifdef AMREX_USE_SENSEI_INSITU
    WARPX_ABORT_WITH_MESSAGE(
        "FlushFormatSensei::WriteParticles : "
        "Not yet implemented."
    );
#endif
}