Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
12 changes: 9 additions & 3 deletions src/include/DiagEnergies.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,29 @@

#include "DiagEnergiesField.h"
#include "DiagEnergiesParticle.h"
#include "diagnostic_base.hxx"

#include "psc.h"

class DiagEnergies
template <typename Mparticles, typename MfieldsState>
class DiagEnergies : public DiagnosticBase<Mparticles, MfieldsState>
{
public:
DiagEnergies();
DiagEnergies(MPI_Comm comm, int interval);

template <typename Mparticles, typename MfieldsState>
void perform_diagnostic(Mparticles& mprts, MfieldsState& mflds)
{
(*this)(mprts, mflds);
}

void operator()(Mparticles& mprts, MfieldsState& mflds);

private:
template <typename Item>
static std::string legend(const Item& item);

template <typename Item, typename Mparticles, typename MfieldsState>
template <typename Item>
void write_one(const Item& item, Mparticles& mprts, MfieldsState& mflds);

private:
Expand Down
28 changes: 17 additions & 11 deletions src/include/DiagEnergies.inl
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
namespace
{

void fclose_helper(FILE* fp)
{
::fclose(fp);
}
void fclose_helper(FILE* fp) { ::fclose(fp); }

} // namespace

// ----------------------------------------------------------------------
// DiagEnergies ctors

inline DiagEnergies::DiagEnergies() : file_{nullptr, fclose_helper} {}
template <typename Mparticles, typename MfieldsState>
inline DiagEnergies<Mparticles, MfieldsState>::DiagEnergies()
: file_{nullptr, fclose_helper}
{}

inline DiagEnergies::DiagEnergies(MPI_Comm comm, int interval)
template <typename Mparticles, typename MfieldsState>
inline DiagEnergies<Mparticles, MfieldsState>::DiagEnergies(MPI_Comm comm,
int interval)
: comm_{comm}, interval_{interval}, file_{nullptr, fclose_helper}
{
MPI_Comm_rank(comm_, &rank_);
Expand All @@ -32,7 +34,8 @@ inline DiagEnergies::DiagEnergies(MPI_Comm comm, int interval)
// DiagEnergies::operator()

template <typename Mparticles, typename MfieldsState>
inline void DiagEnergies::operator()(Mparticles& mprts, MfieldsState& mflds)
inline void DiagEnergies<Mparticles, MfieldsState>::operator()(
Mparticles& mprts, MfieldsState& mflds)
{
const auto& grid = mprts.grid();

Expand All @@ -56,8 +59,10 @@ inline void DiagEnergies::operator()(Mparticles& mprts, MfieldsState& mflds)
// ----------------------------------------------------------------------
// legend

template <typename Mparticles, typename MfieldsState>
template <typename Item>
inline std::string DiagEnergies::legend(const Item& item)
inline std::string DiagEnergies<Mparticles, MfieldsState>::legend(
const Item& item)
{
std::string s;
for (auto& name : item.names()) {
Expand All @@ -69,9 +74,10 @@ inline std::string DiagEnergies::legend(const Item& item)
// ----------------------------------------------------------------------
// write_one

template <typename Item, typename Mparticles, typename MfieldsState>
inline void DiagEnergies::write_one(const Item& item, Mparticles& mprts,
MfieldsState& mflds)
template <typename Mparticles, typename MfieldsState>
template <typename Item>
inline void DiagEnergies<Mparticles, MfieldsState>::write_one(
const Item& item, Mparticles& mprts, MfieldsState& mflds)
{
auto vals = item(mprts, mflds);

Expand Down
49 changes: 0 additions & 49 deletions src/include/DiagnosticsDefault.h

This file was deleted.

8 changes: 7 additions & 1 deletion src/include/OutputFieldsDefault.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#pragma once

#include "diagnostic_base.hxx"
#include "../libpsc/psc_output_fields/fields_item_fields.hxx"
#include "../libpsc/psc_output_fields/fields_item_moments_1st.hxx"
#ifdef USE_CUDA
Expand Down Expand Up @@ -242,7 +243,7 @@ struct OutputFieldsParams

template <typename MfieldsState, typename Mparticles, typename Dim,
typename Writer = WriterDefault>
class OutputFields
class OutputFields : public DiagnosticBase<Mparticles, MfieldsState>
{
public:
// ----------------------------------------------------------------------
Expand All @@ -252,6 +253,11 @@ class OutputFields
: fields{grid, prm.fields, ""}, moments{grid, prm.moments, "_moments"}
{}

void perform_diagnostic(Mparticles& mprts, MfieldsState& mflds) override
{
(*this)(mflds, mprts);
}

// ----------------------------------------------------------------------
// operator()

Expand Down
7 changes: 5 additions & 2 deletions src/include/boundary_injector.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "setup_particles.hxx"
#include "kg/VecRange.hxx"
#include "../libpsc/psc_push_particles/inc_push.cxx"
#include "injector_base.hxx"

/// @brief A particle generator for use with @ref BoundaryInjector. Samples
/// particles from a (possibly shifted) Maxwellian distribution.
Expand Down Expand Up @@ -54,14 +55,16 @@ private:

/// @brief Injects particles on a given boundary, sampling from a given particle
/// generator. For precise control over multiple particle species, use one
/// BoundaryInjector per species, combined with @ref CompositeInjector.
/// BoundaryInjector per species.
/// @tparam PARTICLE_GENERATOR a type that defines `get(min_pos, pos_range)` and
/// returns an injectable particle within that range of positions (usually a
/// grid cell); see @ref ParticleGeneratorMaxwellian
/// @tparam PUSH_PARTICLES type that provides the types `Mparticles`,
/// `MfieldsState`, `Current`, `real_t`, etc.
template <typename PARTICLE_GENERATOR, typename PUSH_PARTICLES>
class BoundaryInjector
: public InjectorBase<typename PUSH_PARTICLES::Mparticles,
typename PUSH_PARTICLES::MfieldsState>
{
static const int INJECT_DIM_IDX_ = 1;

Expand All @@ -88,7 +91,7 @@ public:
/// the given ParticleGenerator.
///
/// Some of these limitations may be removed in the future.
void operator()(Mparticles& mprts, MfieldsState& mflds)
void inject(Mparticles& mprts, MfieldsState& mflds) override
{
static_assert(INJECT_DIM_IDX_ == 1,
"only injection at lower bound of y is supported");
Expand Down
48 changes: 0 additions & 48 deletions src/include/composite_injector.hxx

This file was deleted.

29 changes: 29 additions & 0 deletions src/include/diagnostic_base.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

template <typename Mparticles, typename MfieldsState>
struct DiagnosticBase
{
virtual void perform_diagnostic(Mparticles& mprts, MfieldsState& mflds) = 0;
};

template <typename Mparticles>
struct ParticleDiagnosticBase
{
virtual void perform_diagnostic(Mparticles& mprts) = 0;
};

template <typename Mparticles, typename MfieldsState>
struct DiagnosticFromLambda : public DiagnosticBase<Mparticles, MfieldsState>
{
DiagnosticFromLambda(std::function<void(Mparticles&, MfieldsState&)> lambda)
: lambda{lambda}
{}

void perform_diagnostic(Mparticles& mprts, MfieldsState& mflds) override
{
return lambda(mprts, mflds);
}

private:
std::function<void(Mparticles&, MfieldsState&)> lambda;
};
24 changes: 24 additions & 0 deletions src/include/external_current_base.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

template <typename MFIELDS_STATE>
struct ExternalCurrentBase
{
using MfieldsState = MFIELDS_STATE;

virtual void inject_current(MfieldsState& mflds) = 0;
};

template <typename MFIELDS_STATE>
struct ExternalCurrentFromLambda : ExternalCurrentBase<MFIELDS_STATE>
{
using MfieldsState = MFIELDS_STATE;

ExternalCurrentFromLambda(std::function<void(MfieldsState&)> lambda)
: lambda{lambda}
{}

void inject_current(MfieldsState& mflds) override { return lambda(mflds); }

private:
std::function<void(MfieldsState&)> lambda;
};
29 changes: 29 additions & 0 deletions src/include/injector_base.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

template <typename MPARTICLES, typename MFIELDS_STATE>
struct InjectorBase
{
using Mparticles = MPARTICLES;
using MfieldsState = MFIELDS_STATE;

virtual void inject(Mparticles& mprts, MfieldsState& mflds) = 0;
};

template <typename MPARTICLES, typename MFIELDS_STATE>
struct InjectFromLambda : InjectorBase<MPARTICLES, MFIELDS_STATE>
{
using Mparticles = MPARTICLES;
using MfieldsState = MFIELDS_STATE;

InjectFromLambda(std::function<void(Mparticles&, MfieldsState&)> lambda)
: lambda{lambda}
{}

void inject(Mparticles& mprts, MfieldsState& mflds) override
{
return lambda(mprts, mflds);
}

private:
std::function<void(Mparticles&, MfieldsState&)> lambda;
};
Loading