Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 93 additions & 25 deletions include/vantage.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,6 @@
using namespace NESO::Particles;
using namespace VANTAGE::Reactions;

struct Vantage : public Component {
Vantage(std::string name, Options& options, Solver* solver);

~Vantage(); // Destructor for VANTAGE related cleanup
void finally(const Options& state) override;
void transform_impl(GuardedOptions& state) override;
void outputVars(Options& state) override;

private:
PetscLib petsc_lib; // Ensures PETSc is initialized for the lifetime of this component
std::string name; // Component name
DM dm;
std::shared_ptr<PetscInterface::DMPlexInterface> neso_mesh;
std::shared_ptr<SYCLTarget> sycl_target;
std::shared_ptr<PetscInterface::BoundaryInteraction2D> b2d;

Field2D ion_density;
Field2D neutral_density;
BoutReal particle_time;
};

namespace {
RegisterComponent<Vantage> registercomponentvantage("vantage");
}

/// @brief Data struct to hold information about a reaction source.
/// @param reaction_name Name of the reaction, e.g. "ionistaion"
/// @param source_name Name of the source, e.g. Siz (ion density source due to
Expand Down Expand Up @@ -86,6 +61,99 @@ private:
Options& units;
};

// Need to declare empty struct because the Monitor needs it and it must be
// before component construction as it has the monitor as a member.
// See https://bout-dev.readthedocs.io/en/latest/user_docs/time_integration.html#monitoring-the-simulation-output
// for more information on monitors.
struct Vantage;

/// @brief Monitor to schedule kinetic iterations.
/// @param solver pointer to the solver.
/// @param time normalised sim time provided by BOUT++
/// @param iter current iteration number provided by BOUT++
/// @param nout number of outputs provided by BOUT++
class VantageMonitor : public Monitor {
public:
explicit VantageMonitor(Vantage* vantage) : vantage(vantage) {}
int call(Solver* solver, BoutReal time, int iter, int nout) override;

private:
Vantage* vantage;
};

struct Vantage : public Component {
Vantage(std::string name, Options& options, Solver* solver);

~Vantage(); // Destructor for VANTAGE related cleanup
void finally(const Options& state) override;
void transform_impl(GuardedOptions& state) override;
void outputVars(Options& state) override;

// Function with the kinetic loop.
// time is the normalised VANTAGE monitor frequency.
int advance_vantage(BoutReal time);

private:
bool test_mass_conservation;
BoutReal N_w;
REAL dt;
int nsteps;
int num_cells_owned; // Number of VANTAGE cells owned per rank

Options bout_output_data; // Options object to hold output data for VANTAGE diagnostics
std::unique_ptr<bout::OptionsIO>
vantage_dump_writer; // OptionsIO object to write VANTAGE diagnostics

int mpi_rank; // Current rank ID
Mesh* bout_mesh; // Pointer to the BOUT++ mesh object
Field2D ion_density, neutral_density, total_density;
Field2D initial_neutral_density; // Initial VANTAGE kinetic neutral density
BoutReal total_mass_initial, total_mass;
std::string dmplex_filepath, vantage_dump_filepath,
particle_data_filepath; // Path for output files

// Physics
BoutReal particle_time;
std::string neutral_species; // Neutral species to simulate with VANTAGE
std::string ion_species;
bool plasma_coupling; // Whether to read plasma fields from the state or not
PetscLib petsc_lib; // Ensures PETSc is initialized for the lifetime of this component
BoutReal background_ion_temperature, background_ion_density;
std::vector<BoutReal> V_background;

// DMPLex/VANTAGE stuff
DM dm;
std::shared_ptr<PetscInterface::DMPlexInterface> neso_mesh;
std::shared_ptr<SYCLTarget> sycl_target;
std::shared_ptr<PetscInterface::BoundaryInteraction2D>
b2d; // Boundary interaction object
std::shared_ptr<PetscInterface::DMPlexProjectEvaluateDG>
dg0; // DMPlex projection object
std::shared_ptr<H5Part> h5part; // HDF5 particle output object
std::vector<REAL>
h_project1; // Buffer for scalar projection/evaluation of NESO-Particles properties
std::shared_ptr<ParticleGroup> A_particle_group; // Particle group for main neutrals
std::shared_ptr<ParticleGroup> marker_group; // Particle group for rec markers
std::shared_ptr<CellDatConst<REAL>>
plasma_data; // Data structure for plasma in VANTAGE grid

// Needed for Vantage::apply_boundary_conditions
std::shared_ptr<BoundaryReflection> reflection; // Boundary reflection object
void apply_boundary_conditions(ParticleSubGroupSharedPtr aa);

// These classes don't have a default constructor so need to be initialised as a unique_ptr
std::unique_ptr<VantageSourceManager>
source_manager; // Manager for VANTAGE reaction sources
VantageMonitor monitor{this}; // Output monitor to schedule VANTAGE iterations

std::unique_ptr<ReactionController> reaction_controller;
std::unique_ptr<ReactionController> recombination_controller;
};

namespace {
RegisterComponent<Vantage> registercomponentvantage("vantage");
}

/**
* @brief Function to calculate cell volumes.
*
Expand Down
Loading