Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup hard coded 3D version of PositionFilter to dimensionless filter #189

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ struct CountParticles
template<uint32_t AREA, class PBuffer, class CellDesc, class Space>
static uint64_cu countOnDevice(PBuffer& buffer, CellDesc cellDescription, const Space& origin, const Space& size)
{
typedef bmpl::vector< PositionFilter3D<> > usedFilters;
typedef bmpl::vector< typename GetPositionFilter<Space::Dim>::type > usedFilters;
typedef typename FilterFactory<usedFilters>::FilterType MyParticleFilter;
MyParticleFilter filter;
filter.setStatus(true); /*activeate filter pipline*/
Expand Down
70 changes: 46 additions & 24 deletions src/libPMacc/include/particles/particleFilter/PositionFilter.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2013 Heiko Burau, Rene Widera
* Copyright 2013-2014 Heiko Burau, Rene Widera
*
* This file is part of libPMacc.
*
Expand All @@ -20,8 +20,7 @@
*/


#ifndef POSITIONFILTER_HPP
#define POSITIONFILTER_HPP
#pragma once

#include "types.h"
#include "particles/frame_types.hpp"
Expand All @@ -35,13 +34,15 @@ namespace PMacc
namespace privatePositionFilter
{

template<unsigned DIM, class Base = NullFrame>
template<unsigned T_dim, class Base = NullFrame>
class PositionFilter : public Base
{
public:
static const uint32_t dim = T_dim;
protected:
DataSpace<DIM> offset;
DataSpace<DIM> max;
DataSpace<DIM> superCellIdx;
DataSpace<dim> offset;
DataSpace<dim> max;
DataSpace<dim> superCellIdx;

public:

Expand All @@ -53,45 +54,66 @@ class PositionFilter : public Base
{
}

HDINLINE void setWindowPosition(DataSpace<DIM> offset, DataSpace<DIM> size)
HDINLINE void setWindowPosition(DataSpace<dim> offset, DataSpace<dim> size)
{
this->offset = offset;
this->max = offset + size;
}

HDINLINE void setSuperCellPosition(DataSpace<DIM> superCellIdx)
HDINLINE void setSuperCellPosition(DataSpace<dim> superCellIdx)
{
this->superCellIdx = superCellIdx;
}

HDINLINE DataSpace<DIM> getOffset()
HDINLINE DataSpace<dim> getOffset()
{
return offset;
}

template<class FRAME>
HDINLINE bool operator()(FRAME & frame, lcellId_t id)
{
DataSpace<dim> localCellIdx = DataSpaceOperations<dim>::template map<
typename FRAME::SuperCellSize
> ((uint32_t) (frame[id][localCellIdx_]));
DataSpace<dim> pos = this->superCellIdx + localCellIdx;
bool result = false;
for (uint32_t d = 0; d < dim; ++d)
result= result && (this->offset[d] <= pos[d]) && (pos[d]<this->max[d]);
return Base::operator() (frame, id) && result;
}

};

} //namespace privatePositionFilter

/** This wrapper class is needed because for filters we are only allowed to
* define one template parameter "base" (it is a constrain from FilterFactory)
*/
template<class Base = NullFrame>
class PositionFilter3D : public privatePositionFilter::PositionFilter<DIM3, Base>
{
public:
};

template<class FRAME>
HDINLINE bool operator()(FRAME & frame, lcellId_t id)
{
DataSpace<DIM3> localCellIdx3D = DataSpaceOperations<DIM3>::template map<
typename FRAME::SuperCellSize
> ((uint32_t) (frame[id][localCellIdx_]));
DataSpace<DIM3> pos = this->superCellIdx + localCellIdx3D;
return (this->offset.x() <= pos.x() && this->offset.y() <= pos.y() && this->offset.z() <= pos.z() &&
this->max.x() > pos.x() && this->max.y() > pos.y() && this->max.z() > pos.z()) &&
Base::operator() (frame, id);
}
template<class Base = NullFrame>
class PositionFilter2D : public privatePositionFilter::PositionFilter<DIM2, Base>
{
};

} //namespace Frame
template<unsigned dim>
struct GetPositionFilter;

template<>
struct GetPositionFilter<DIM3>
{
typedef PositionFilter3D<> type;
};

template<>
struct GetPositionFilter<DIM2>
{
typedef PositionFilter2D<> type;
};

#endif /* POSITIONFILTER_HPP */

} //namespace PMacc
4 changes: 2 additions & 2 deletions src/picongpu/include/plugins/adios/ADIOSWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ class ADIOSWriter : public ISimulationIO, public IPluginModule
public:

/* filter particles by global position*/
typedef bmpl::vector< PositionFilter3D<> > usedFilters;
typedef bmpl::vector< typename GetPositionFilter<simDim>::type > usedFilters;
typedef typename FilterFactory<usedFilters>::FilterType MyParticleFilter;

private:

/* fiter is a rule which describes which particles should be copyied to host*/
/* filter is a rule which describes which particles should be copied to host*/
MyParticleFilter filter;

template<typename UnitType>
Expand Down
2 changes: 1 addition & 1 deletion src/picongpu/include/plugins/adios/WriteSpecies.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ struct WriteSpecies
log<picLog::INPUT_OUTPUT > ("ADIOS: ( end ) get mapped memory device pointer: %1%") % AdiosFrameType::getName();

log<picLog::INPUT_OUTPUT > ("ADIOS: (begin) copy particle to host: %1%") % AdiosFrameType::getName();
typedef bmpl::vector< PositionFilter3D<> > usedFilters;
typedef bmpl::vector< typename GetPositionFilter<simDim>::type > usedFilters;
typedef typename FilterFactory<usedFilters>::FilterType MyParticleFilter;
MyParticleFilter filter;
/* activeate filter pipeline if moving window is activated */
Expand Down
4 changes: 2 additions & 2 deletions src/picongpu/include/plugins/hdf5/HDF5Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ class HDF5Writer : public ISimulationIO, public IPluginModule
public:

/* filter particles by global position*/
typedef bmpl::vector< PositionFilter3D<> > usedFilters;
typedef bmpl::vector< typename GetPositionFilter<simDim>::type > usedFilters;
typedef typename FilterFactory<usedFilters>::FilterType MyParticleFilter;

private:

/* fiter is a rule which describe which particles shuld copy to host*/
/* filter is a rule which describe which particles should copy to host*/
MyParticleFilter filter;

template<typename UnitType>
Expand Down
2 changes: 1 addition & 1 deletion src/picongpu/include/plugins/hdf5/WriteSpecies.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ struct WriteSpecies
log<picLog::INPUT_OUTPUT > ("HDF5: ( end ) get mapped memory device pointer: %1%") % Hdf5FrameType::getName();

log<picLog::INPUT_OUTPUT > ("HDF5: (begin) copy particle to host: %1%") % Hdf5FrameType::getName();
typedef bmpl::vector< PositionFilter3D<> > usedFilters;
typedef bmpl::vector< typename GetPositionFilter<simDim>::type > usedFilters;
typedef typename FilterFactory<usedFilters>::FilterType MyParticleFilter;
MyParticleFilter filter;
/* activate filter pipeline if moving window is activated */
Expand Down