Skip to content

Commit e44bd3a

Browse files
committed
Merge pull request #189 from psychocoderHPC/topic-cleanUpPositionFilter
cleanup hard coded 3D version of PositionFilter to dimensionless filter
2 parents 2792645 + 93ee946 commit e44bd3a

6 files changed

Lines changed: 53 additions & 31 deletions

File tree

src/libPMacc/include/particles/operations/CountParticles.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ struct CountParticles
149149
template<uint32_t AREA, class PBuffer, class CellDesc, class Space>
150150
static uint64_cu countOnDevice(PBuffer& buffer, CellDesc cellDescription, const Space& origin, const Space& size)
151151
{
152-
typedef bmpl::vector< PositionFilter3D<> > usedFilters;
152+
typedef bmpl::vector< typename GetPositionFilter<Space::Dim>::type > usedFilters;
153153
typedef typename FilterFactory<usedFilters>::FilterType MyParticleFilter;
154154
MyParticleFilter filter;
155155
filter.setStatus(true); /*activeate filter pipline*/
Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2013 Heiko Burau, Rene Widera
2+
* Copyright 2013-2014 Heiko Burau, Rene Widera
33
*
44
* This file is part of libPMacc.
55
*
@@ -20,8 +20,7 @@
2020
*/
2121

2222

23-
#ifndef POSITIONFILTER_HPP
24-
#define POSITIONFILTER_HPP
23+
#pragma once
2524

2625
#include "types.h"
2726
#include "particles/frame_types.hpp"
@@ -35,13 +34,15 @@ namespace PMacc
3534
namespace privatePositionFilter
3635
{
3736

38-
template<unsigned DIM, class Base = NullFrame>
37+
template<unsigned T_dim, class Base = NullFrame>
3938
class PositionFilter : public Base
4039
{
40+
public:
41+
static const uint32_t dim = T_dim;
4142
protected:
42-
DataSpace<DIM> offset;
43-
DataSpace<DIM> max;
44-
DataSpace<DIM> superCellIdx;
43+
DataSpace<dim> offset;
44+
DataSpace<dim> max;
45+
DataSpace<dim> superCellIdx;
4546

4647
public:
4748

@@ -53,45 +54,66 @@ class PositionFilter : public Base
5354
{
5455
}
5556

56-
HDINLINE void setWindowPosition(DataSpace<DIM> offset, DataSpace<DIM> size)
57+
HDINLINE void setWindowPosition(DataSpace<dim> offset, DataSpace<dim> size)
5758
{
5859
this->offset = offset;
5960
this->max = offset + size;
6061
}
6162

62-
HDINLINE void setSuperCellPosition(DataSpace<DIM> superCellIdx)
63+
HDINLINE void setSuperCellPosition(DataSpace<dim> superCellIdx)
6364
{
6465
this->superCellIdx = superCellIdx;
6566
}
6667

67-
HDINLINE DataSpace<DIM> getOffset()
68+
HDINLINE DataSpace<dim> getOffset()
6869
{
6970
return offset;
7071
}
7172

73+
template<class FRAME>
74+
HDINLINE bool operator()(FRAME & frame, lcellId_t id)
75+
{
76+
DataSpace<dim> localCellIdx = DataSpaceOperations<dim>::template map<
77+
typename FRAME::SuperCellSize
78+
> ((uint32_t) (frame[id][localCellIdx_]));
79+
DataSpace<dim> pos = this->superCellIdx + localCellIdx;
80+
bool result = false;
81+
for (uint32_t d = 0; d < dim; ++d)
82+
result= result && (this->offset[d] <= pos[d]) && (pos[d]<this->max[d]);
83+
return Base::operator() (frame, id) && result;
84+
}
85+
7286
};
7387

7488
} //namespace privatePositionFilter
7589

90+
/** This wrapper class is needed because for filters we are only allowed to
91+
* define one template parameter "base" (it is a constrain from FilterFactory)
92+
*/
7693
template<class Base = NullFrame>
7794
class PositionFilter3D : public privatePositionFilter::PositionFilter<DIM3, Base>
7895
{
79-
public:
96+
};
8097

81-
template<class FRAME>
82-
HDINLINE bool operator()(FRAME & frame, lcellId_t id)
83-
{
84-
DataSpace<DIM3> localCellIdx3D = DataSpaceOperations<DIM3>::template map<
85-
typename FRAME::SuperCellSize
86-
> ((uint32_t) (frame[id][localCellIdx_]));
87-
DataSpace<DIM3> pos = this->superCellIdx + localCellIdx3D;
88-
return (this->offset.x() <= pos.x() && this->offset.y() <= pos.y() && this->offset.z() <= pos.z() &&
89-
this->max.x() > pos.x() && this->max.y() > pos.y() && this->max.z() > pos.z()) &&
90-
Base::operator() (frame, id);
91-
}
98+
template<class Base = NullFrame>
99+
class PositionFilter2D : public privatePositionFilter::PositionFilter<DIM2, Base>
100+
{
92101
};
93102

94-
} //namespace Frame
103+
template<unsigned dim>
104+
struct GetPositionFilter;
105+
106+
template<>
107+
struct GetPositionFilter<DIM3>
108+
{
109+
typedef PositionFilter3D<> type;
110+
};
111+
112+
template<>
113+
struct GetPositionFilter<DIM2>
114+
{
115+
typedef PositionFilter2D<> type;
116+
};
95117

96-
#endif /* POSITIONFILTER_HPP */
97118

119+
} //namespace PMacc

src/picongpu/include/plugins/adios/ADIOSWriter.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ class ADIOSWriter : public ISimulationIO, public IPluginModule
9494
public:
9595

9696
/* filter particles by global position*/
97-
typedef bmpl::vector< PositionFilter3D<> > usedFilters;
97+
typedef bmpl::vector< typename GetPositionFilter<simDim>::type > usedFilters;
9898
typedef typename FilterFactory<usedFilters>::FilterType MyParticleFilter;
9999

100100
private:
101101

102-
/* fiter is a rule which describes which particles should be copyied to host*/
102+
/* filter is a rule which describes which particles should be copied to host*/
103103
MyParticleFilter filter;
104104

105105
template<typename UnitType>

src/picongpu/include/plugins/adios/WriteSpecies.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ struct WriteSpecies
118118
log<picLog::INPUT_OUTPUT > ("ADIOS: ( end ) get mapped memory device pointer: %1%") % AdiosFrameType::getName();
119119

120120
log<picLog::INPUT_OUTPUT > ("ADIOS: (begin) copy particle to host: %1%") % AdiosFrameType::getName();
121-
typedef bmpl::vector< PositionFilter3D<> > usedFilters;
121+
typedef bmpl::vector< typename GetPositionFilter<simDim>::type > usedFilters;
122122
typedef typename FilterFactory<usedFilters>::FilterType MyParticleFilter;
123123
MyParticleFilter filter;
124124
/* activeate filter pipeline if moving window is activated */

src/picongpu/include/plugins/hdf5/HDF5Writer.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ class HDF5Writer : public ISimulationIO, public IPluginModule
9696
public:
9797

9898
/* filter particles by global position*/
99-
typedef bmpl::vector< PositionFilter3D<> > usedFilters;
99+
typedef bmpl::vector< typename GetPositionFilter<simDim>::type > usedFilters;
100100
typedef typename FilterFactory<usedFilters>::FilterType MyParticleFilter;
101101

102102
private:
103103

104-
/* fiter is a rule which describe which particles shuld copy to host*/
104+
/* filter is a rule which describe which particles should copy to host*/
105105
MyParticleFilter filter;
106106

107107
template<typename UnitType>

src/picongpu/include/plugins/hdf5/WriteSpecies.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ struct WriteSpecies
130130
log<picLog::INPUT_OUTPUT > ("HDF5: ( end ) get mapped memory device pointer: %1%") % Hdf5FrameType::getName();
131131

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

0 commit comments

Comments
 (0)