Skip to content

Commit

Permalink
Merge branch '142-remove-hard-coded-types' into 'master'
Browse files Browse the repository at this point in the history
Resolve "Remove hard-coded types"

Closes #142

See merge request OPAL/Libraries/ippl!158
  • Loading branch information
matt-frey committed Mar 21, 2023
2 parents dbfaf74 + 94bd21e commit 310d6fe
Show file tree
Hide file tree
Showing 47 changed files with 544 additions and 495 deletions.
7 changes: 4 additions & 3 deletions alpine/ChargedParticles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,25 @@ constexpr unsigned Dim = 3;
// some typedefs
typedef ippl::ParticleSpatialLayout<double, Dim> PLayout_t;
typedef ippl::UniformCartesian<double, Dim> Mesh_t;
typedef Mesh_t::DefaultCentering Centering_t;
typedef ippl::FieldLayout<Dim> FieldLayout_t;
typedef ippl::OrthogonalRecursiveBisection<double, Dim, Mesh_t> ORB;
typedef ippl::OrthogonalRecursiveBisection<double, Dim, Mesh_t, Centering_t> ORB;

using size_type = ippl::detail::size_type;

template <typename T, unsigned Dim>
using Vector = ippl::Vector<T, Dim>;

template <typename T, unsigned Dim>
using Field = ippl::Field<T, Dim>;
using Field = ippl::Field<T, Dim, Mesh_t, Centering_t>;

template <typename T>
using ParticleAttrib = ippl::ParticleAttrib<T>;

typedef Vector<double, Dim> Vector_t;
typedef Field<double, Dim> Field_t;
typedef Field<Vector_t, Dim> VField_t;
typedef ippl::FFTPeriodicPoissonSolver<Vector_t, double, Dim> Solver_t;
typedef ippl::FFTPeriodicPoissonSolver<Vector_t, double, Dim, Mesh_t, Centering_t> Solver_t;

const double pi = std::acos(-1.0);

Expand Down
6 changes: 3 additions & 3 deletions src/Decomposition/OrthogonalRecursiveBisection.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ namespace ippl {
* @tparam Dim dimension
* @tparam M mesh
*/
template <class T, unsigned Dim, class M>
template <class T, unsigned Dim, class Mesh, class Centering>
class OrthogonalRecursiveBisection {
public:
using view_type = typename detail::ViewType<T, Dim>::view_type;

// Weight for reduction
Field<T, Dim> bf_m;
Field<T, Dim, Mesh, Centering> bf_m;

/*!
* Initialize member field with mesh and field layout
Expand All @@ -52,7 +52,7 @@ namespace ippl {
* @param rho Density field
*/
void initialize(FieldLayout<Dim>& fl, UniformCartesian<T, Dim>& mesh,
const Field<T, Dim>& rho);
const Field<T, Dim, Mesh, Centering>& rho);

/*!
* Performs scatter operation of particle positions in field (weights) and
Expand Down
48 changes: 24 additions & 24 deletions src/Decomposition/OrthogonalRecursiveBisection.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include "Utility/IpplTimings.h"
namespace ippl {

template <class T, unsigned Dim, class M>
void OrthogonalRecursiveBisection<T, Dim, M>::initialize(FieldLayout<Dim>& fl,
UniformCartesian<T, Dim>& mesh,
const Field<T, Dim>& rho) {
template <class T, unsigned Dim, class Mesh, class Centering>
void OrthogonalRecursiveBisection<T, Dim, Mesh, Centering>::initialize(FieldLayout<Dim>& fl,
UniformCartesian<T, Dim>& mesh,
const Field<T, Dim, Mesh, Centering>& rho) {
bf_m.initialize(mesh, fl);
bf_m = rho;
}

template <class T, unsigned Dim, class M>
bool OrthogonalRecursiveBisection<T, Dim, M>::binaryRepartition(
template <class T, unsigned Dim, class Mesh, class Centering>
bool OrthogonalRecursiveBisection<T, Dim, Mesh, Centering>::binaryRepartition(
const ParticleAttrib<Vector<T, Dim>>& R, FieldLayout<Dim>& fl,
const bool& isFirstRepartition) {
// Timings
Expand Down Expand Up @@ -119,8 +119,8 @@ namespace ippl {
return true;
}

template <class T, unsigned Dim, class M>
int OrthogonalRecursiveBisection<T, Dim, M>::findCutAxis(NDIndex<Dim>& dom) {
template <class T, unsigned Dim, class Mesh, class Centering>
int OrthogonalRecursiveBisection<T, Dim, Mesh, Centering>::findCutAxis(NDIndex<Dim>& dom) {
int cutAxis = 0;
unsigned int maxLength = 0;

Expand All @@ -136,8 +136,8 @@ namespace ippl {
return cutAxis;
}

template <class T, unsigned Dim, class M>
void OrthogonalRecursiveBisection<T, Dim, M>::perpendicularReduction(
template <class T, unsigned Dim, class Mesh, class Centering>
void OrthogonalRecursiveBisection<T, Dim, Mesh, Centering>::perpendicularReduction(
std::vector<T>& rankWeights, unsigned int cutAxis, NDIndex<Dim>& dom) {
// Check if domains overlap, if not no need for reduction
NDIndex<Dim> lDom = bf_m.getOwned();
Expand Down Expand Up @@ -214,8 +214,8 @@ namespace ippl {
}
}

template <class T, unsigned Dim, class M>
int OrthogonalRecursiveBisection<T, Dim, M>::findMedian(std::vector<T>& w) {
template <class T, unsigned Dim, class Mesh, class Centering>
int OrthogonalRecursiveBisection<T, Dim, Mesh, Centering>::findMedian(std::vector<T>& w) {
// Special case when array must be cut in half in order to not have planes
if (w.size() == 4)
return 1;
Expand Down Expand Up @@ -250,10 +250,10 @@ namespace ippl {
return w.size() - 3;
}

template <class T, unsigned Dim, class M>
void OrthogonalRecursiveBisection<T, Dim, M>::cutDomain(std::vector<NDIndex<Dim>>& domains,
std::vector<int>& procs, int it,
int cutAxis, int median) {
template <class T, unsigned Dim, class Mesh, class Centering>
void OrthogonalRecursiveBisection<T, Dim, Mesh, Centering>::cutDomain(std::vector<NDIndex<Dim>>& domains,
std::vector<int>& procs, int it,
int cutAxis, int median) {
// Cut domains[it] in half at median along cutAxis
NDIndex<Dim> leftDom, rightDom;
domains[it].split(leftDom, rightDom, cutAxis, median + domains[it][cutAxis].first());
Expand All @@ -266,19 +266,19 @@ namespace ippl {
procs.insert(procs.begin() + it + 1, 1, temp - procs[it]);
}

template <class T, unsigned Dim, class M>
void OrthogonalRecursiveBisection<T, Dim, M>::scatterR(
template <class T, unsigned Dim, class Mesh, class Centering>
void OrthogonalRecursiveBisection<T, Dim, Mesh, Centering>::scatterR(
const ParticleAttrib<Vector<T, Dim>>& r) {
using vector_type = typename M::vector_type;
using vector_type = typename Mesh::vector_type;

// Reset local field
bf_m = 0.0;
// Get local data
typename Field<T, Dim, M>::view_type view = bf_m.getView();
const M& mesh = bf_m.get_mesh();
const FieldLayout<Dim>& layout = bf_m.getLayout();
const NDIndex<Dim>& lDom = layout.getLocalNDIndex();
const int nghost = bf_m.getNghost();
typename Field<T, Dim, Mesh, Centering>::view_type view = bf_m.getView();
const Mesh& mesh = bf_m.get_mesh();
const FieldLayout<Dim>& layout = bf_m.getLayout();
const NDIndex<Dim>& lDom = layout.getLocalNDIndex();
const int nghost = bf_m.getNghost();

// Get spacings
const vector_type& dx = mesh.getMeshSpacing();
Expand Down
28 changes: 14 additions & 14 deletions src/FFT/FFT.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,18 @@ namespace ippl {
/**
Non-specialized FFT class. We specialize based on Transform tag class
*/
template <class Transform, size_t Dim, class T, class M = UniformCartesian<double, Dim>>
template <class Transform, size_t Dim, class T, class Mesh, class Centering>
class FFT {};

/**
complex-to-complex FFT class
*/
template <size_t Dim, class T, class M>
class FFT<CCTransform, Dim, T, M> {
template <size_t Dim, class T, class Mesh, class Centering>
class FFT<CCTransform, Dim, T, Mesh, Centering> {
public:
typedef FieldLayout<Dim> Layout_t;
typedef Kokkos::complex<T> Complex_t;
typedef Field<Complex_t, Dim, M> ComplexField_t;
typedef Field<Complex_t, Dim, Mesh, Centering> ComplexField_t;

using heffteBackend = typename detail::HeffteBackendType::backend;
using workspace_t =
Expand Down Expand Up @@ -166,18 +166,18 @@ namespace ippl {
/**
real-to-complex FFT class
*/
template <size_t Dim, class T, class M>
class FFT<RCTransform, Dim, T, M> {
template <size_t Dim, class T, class Mesh, class Centering>
class FFT<RCTransform, Dim, T, Mesh, Centering> {
public:
typedef FieldLayout<Dim> Layout_t;
typedef Field<T, Dim, M> RealField_t;
typedef Field<T, Dim, Mesh, Centering> RealField_t;

using heffteBackend = typename detail::HeffteBackendType::backend;
typedef Kokkos::complex<T> Complex_t;
using workspace_t =
typename heffte::fft3d_r2c<heffteBackend>::template buffer_container<Complex_t>;

typedef Field<Complex_t, Dim, M> ComplexField_t;
typedef Field<Complex_t, Dim, Mesh, Centering> ComplexField_t;

/** Create a new FFT object with the layout for the input and output Fields
* and parameters for heffte.
Expand Down Expand Up @@ -210,11 +210,11 @@ namespace ippl {
/**
Sine transform class
*/
template <size_t Dim, class T, class M>
class FFT<SineTransform, Dim, T, M> {
template <size_t Dim, class T, class Mesh, class Centering>
class FFT<SineTransform, Dim, T, Mesh, Centering> {
public:
typedef FieldLayout<Dim> Layout_t;
typedef Field<T, Dim, M> Field_t;
typedef Field<T, Dim, Mesh, Centering> Field_t;

using heffteBackend = typename detail::HeffteBackendType::backendSine;
using workspace_t = typename heffte::fft3d<heffteBackend>::template buffer_container<T>;
Expand Down Expand Up @@ -245,11 +245,11 @@ namespace ippl {
/**
Cosine transform class
*/
template <size_t Dim, class T, class M>
class FFT<CosTransform, Dim, T, M> {
template <size_t Dim, class T, class Mesh, class Centering>
class FFT<CosTransform, Dim, T, Mesh, Centering> {
public:
typedef FieldLayout<Dim> Layout_t;
typedef Field<T, Dim, M> Field_t;
typedef Field<T, Dim, Mesh, Centering> Field_t;

using heffteBackend = typename detail::HeffteBackendType::backendCos;
using workspace_t = typename heffte::fft3d<heffteBackend>::template buffer_container<T>;
Expand Down
77 changes: 39 additions & 38 deletions src/FFT/FFT.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ namespace ippl {
given layout and heffte parameters.
*/

template <size_t Dim, class T, class M>
FFT<CCTransform, Dim, T, M>::FFT(const Layout_t& layout, const ParameterList& params) {
template <size_t Dim, class T, class Mesh, class Centering>
FFT<CCTransform, Dim, T, Mesh, Centering>::FFT(const Layout_t& layout, const ParameterList& params) {
/**
* Heffte requires to pass a 3D array even for 2D and
* 1D FFTs we just have to make the length in other
Expand Down Expand Up @@ -76,10 +76,10 @@ namespace ippl {
/**
setup performs the initialization necessary.
*/
template <size_t Dim, class T, class M>
void FFT<CCTransform, Dim, T, M>::setup(const std::array<long long, Dim>& low,
const std::array<long long, Dim>& high,
const ParameterList& params) {
template <size_t Dim, class T, class Mesh, class Centering>
void FFT<CCTransform, Dim, T, Mesh, Centering>::setup(const std::array<long long, Dim>& low,
const std::array<long long, Dim>& high,
const ParameterList& params) {
heffte::box3d<long long> inbox = {low, high};
heffte::box3d<long long> outbox = {low, high};

Expand Down Expand Up @@ -118,9 +118,9 @@ namespace ippl {
workspace_m = workspace_t(heffte_m->size_workspace());
}

template <size_t Dim, class T, class M>
void FFT<CCTransform, Dim, T, M>::transform(
int direction, typename FFT<CCTransform, Dim, T, M>::ComplexField_t& f) {
template <size_t Dim, class T, class Mesh, class Centering>
void FFT<CCTransform, Dim, T, Mesh, Centering>::transform(
int direction, typename FFT<CCTransform, Dim, T, Mesh, Centering>::ComplexField_t& f) {
auto fview = f.getView();
const int nghost = f.getNghost();

Expand Down Expand Up @@ -177,9 +177,10 @@ namespace ippl {
*layouts and heffte parameters.
*/

template <size_t Dim, class T, class M>
FFT<RCTransform, Dim, T, M>::FFT(const Layout_t& layoutInput, const Layout_t& layoutOutput,
const ParameterList& params) {
template <size_t Dim, class T, class Mesh, class Centering>
FFT<RCTransform, Dim, T, Mesh, Centering>::FFT(const Layout_t& layoutInput,
const Layout_t& layoutOutput,
const ParameterList& params) {
/**
* Heffte requires to pass a 3D array even for 2D and
* 1D FFTs we just have to make the length in other
Expand Down Expand Up @@ -217,12 +218,12 @@ namespace ippl {
/**
setup performs the initialization.
*/
template <size_t Dim, class T, class M>
void FFT<RCTransform, Dim, T, M>::setup(const std::array<long long, Dim>& lowInput,
const std::array<long long, Dim>& highInput,
const std::array<long long, Dim>& lowOutput,
const std::array<long long, Dim>& highOutput,
const ParameterList& params) {
template <size_t Dim, class T, class Mesh, class Centering>
void FFT<RCTransform, Dim, T, Mesh, Centering>::setup(const std::array<long long, Dim>& lowInput,
const std::array<long long, Dim>& highInput,
const std::array<long long, Dim>& lowOutput,
const std::array<long long, Dim>& highOutput,
const ParameterList& params) {
heffte::box3d<long long> inbox = {lowInput, highInput};
heffte::box3d<long long> outbox = {lowOutput, highOutput};

Expand Down Expand Up @@ -261,10 +262,10 @@ namespace ippl {
workspace_m = workspace_t(heffte_m->size_workspace());
}

template <size_t Dim, class T, class M>
void FFT<RCTransform, Dim, T, M>::transform(
int direction, typename FFT<RCTransform, Dim, T, M>::RealField_t& f,
typename FFT<RCTransform, Dim, T, M>::ComplexField_t& g) {
template <size_t Dim, class T, class Mesh, class Centering>
void FFT<RCTransform, Dim, T, Mesh, Centering>::transform(
int direction, typename FFT<RCTransform, Dim, T, Mesh, Centering>::RealField_t& f,
typename FFT<RCTransform, Dim, T, Mesh, Centering>::ComplexField_t& g) {
auto fview = f.getView();
auto gview = g.getView();
const int nghostf = f.getNghost();
Expand Down Expand Up @@ -344,8 +345,8 @@ namespace ippl {
given layout and heffte parameters.
*/

template <size_t Dim, class T, class M>
FFT<SineTransform, Dim, T, M>::FFT(const Layout_t& layout, const ParameterList& params) {
template <size_t Dim, class T, class Mesh, class Centering>
FFT<SineTransform, Dim, T, Mesh, Centering>::FFT(const Layout_t& layout, const ParameterList& params) {
/**
* Heffte requires to pass a 3D array even for 2D and
* 1D FFTs we just have to make the length in other
Expand Down Expand Up @@ -374,8 +375,8 @@ namespace ippl {
/**
setup performs the initialization necessary.
*/
template <size_t Dim, class T, class M>
void FFT<SineTransform, Dim, T, M>::setup(const std::array<long long, Dim>& low,
template <size_t Dim, class T, class Mesh, class Centering>
void FFT<SineTransform, Dim, T, Mesh, Centering>::setup(const std::array<long long, Dim>& low,
const std::array<long long, Dim>& high,
const ParameterList& params) {
heffte::box3d<long long> inbox = {low, high};
Expand Down Expand Up @@ -415,9 +416,9 @@ namespace ippl {
workspace_m = workspace_t(heffte_m->size_workspace());
}

template <size_t Dim, class T, class M>
void FFT<SineTransform, Dim, T, M>::transform(
int direction, typename FFT<SineTransform, Dim, T, M>::Field_t& f) {
template <size_t Dim, class T, class Mesh, class Centering>
void FFT<SineTransform, Dim, T, Mesh, Centering>::transform(
int direction, typename FFT<SineTransform, Dim, T, Mesh, Centering>::Field_t& f) {
auto fview = f.getView();
const int nghost = f.getNghost();

Expand Down Expand Up @@ -472,8 +473,8 @@ namespace ippl {
given layout and heffte parameters.
*/

template <size_t Dim, class T, class M>
FFT<CosTransform, Dim, T, M>::FFT(const Layout_t& layout, const ParameterList& params) {
template <size_t Dim, class T, class Mesh, class Centering>
FFT<CosTransform, Dim, T, Mesh, Centering>::FFT(const Layout_t& layout, const ParameterList& params) {
/**
* Heffte requires to pass a 3D array even for 2D and
* 1D FFTs we just have to make the length in other
Expand Down Expand Up @@ -502,10 +503,10 @@ namespace ippl {
/**
setup performs the initialization necessary.
*/
template <size_t Dim, class T, class M>
void FFT<CosTransform, Dim, T, M>::setup(const std::array<long long, Dim>& low,
const std::array<long long, Dim>& high,
const ParameterList& params) {
template <size_t Dim, class T, class Mesh, class Centering>
void FFT<CosTransform, Dim, T, Mesh, Centering>::setup(const std::array<long long, Dim>& low,
const std::array<long long, Dim>& high,
const ParameterList& params) {
heffte::box3d<long long> inbox = {low, high};
heffte::box3d<long long> outbox = {low, high};

Expand Down Expand Up @@ -543,9 +544,9 @@ namespace ippl {
workspace_m = workspace_t(heffte_m->size_workspace());
}

template <size_t Dim, class T, class M>
void FFT<CosTransform, Dim, T, M>::transform(
int direction, typename FFT<CosTransform, Dim, T, M>::Field_t& f) {
template <size_t Dim, class T, class Mesh, class Centering>
void FFT<CosTransform, Dim, T, Mesh, Centering>::transform(
int direction, typename FFT<CosTransform, Dim, T, Mesh, Centering>::Field_t& f) {
auto fview = f.getView();
const int nghost = f.getNghost();

Expand Down
Loading

0 comments on commit 310d6fe

Please sign in to comment.