Skip to content

Commit 46389dc

Browse files
Merge pull request ComputationalRadiationPhysics#888 from ax3l/topic-currentInterpolation
Current Interpolation: During add to EMF
2 parents e58cf82 + 1fdbc60 commit 46389dc

File tree

12 files changed

+440
-45
lines changed

12 files changed

+440
-45
lines changed

src/picongpu/include/fields/FieldJ.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2013-2014 Axel Huebl, Heiko Burau, Rene Widera, Richard Pausch
2+
* Copyright 2013-2015 Axel Huebl, Heiko Burau, Rene Widera, Richard Pausch
33
*
44
* This file is part of PIConGPU.
55
*
@@ -70,7 +70,7 @@ class FieldJ : public SimulationFieldHelper<MappingDesc>, public ISimulationData
7070

7171
virtual EventTask asyncCommunication(EventTask serialEvent);
7272

73-
void init(FieldE &fieldE);
73+
void init(FieldE &fieldE, FieldB &fieldB);
7474

7575
GridLayout<simDim> getGridLayout();
7676

@@ -87,8 +87,8 @@ class FieldJ : public SimulationFieldHelper<MappingDesc>, public ISimulationData
8787
template<uint32_t AREA, class ParticlesClass>
8888
void computeCurrent(ParticlesClass &parClass, uint32_t currentStep) throw (std::invalid_argument);
8989

90-
template<uint32_t AREA>
91-
void addCurrentToE();
90+
template<uint32_t AREA, class T_CurrentInterpolation>
91+
void addCurrentToEMF( T_CurrentInterpolation& myCurrentInterpolation );
9292

9393
SimulationDataId getUniqueId();
9494

@@ -124,8 +124,10 @@ class FieldJ : public SimulationFieldHelper<MappingDesc>, public ISimulationData
124124
private:
125125

126126
GridBuffer<ValueType, simDim> fieldJ;
127+
GridBuffer<ValueType, simDim>* fieldJrecv;
127128

128129
FieldE *fieldE;
130+
FieldB *fieldB;
129131
};
130132

131133
template<typename T_SpeciesName, typename T_Area>

src/picongpu/include/fields/FieldJ.kernel

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2013-2014 Axel Huebl, Heiko Burau, Rene Widera
2+
* Copyright 2013-2015 Axel Huebl, Heiko Burau, Rene Widera
33
*
44
* This file is part of PIConGPU.
55
*
@@ -160,24 +160,45 @@ private:
160160
const PMACC_ALIGN(deltaTime, float);
161161
};
162162

163-
template<class Mapping>
164-
__global__ void kernelAddCurrentToE(typename FieldE::DataBoxType fieldE,
165-
J_DataBox fieldJ,
166-
Mapping mapper)
163+
template<class T_CurrentInterpolation, class T_Mapping>
164+
__global__ void kernelAddCurrentToEMF(typename FieldE::DataBoxType fieldE,
165+
typename FieldB::DataBoxType fieldB,
166+
J_DataBox fieldJ,
167+
T_CurrentInterpolation currentInterpolation,
168+
T_Mapping mapper)
167169
{
170+
/* Caching of fieldJ */
171+
typedef SuperCellDescription<
172+
SuperCellSize,
173+
typename T_CurrentInterpolation::LowerMargin,
174+
typename T_CurrentInterpolation::UpperMargin
175+
> BlockArea;
168176

169-
const DataSpace<simDim> blockCell(
170-
mapper.getSuperCellIndex(DataSpace<simDim > (blockIdx))
171-
* Mapping::SuperCellSize::toRT()
172-
);
173-
const DataSpace<Mapping::Dim> cell(blockCell + DataSpace<simDim > (threadIdx));
177+
PMACC_AUTO(cachedJ, CachedBox::create < 0, typename J_DataBox::ValueType > (BlockArea()));
178+
179+
nvidia::functors::Assign assign;
180+
const DataSpace<simDim> block(mapper.getSuperCellIndex(DataSpace<simDim > (blockIdx)));
181+
const DataSpace<simDim> blockCell = block * MappingDesc::SuperCellSize::toRT();
182+
183+
const DataSpace<simDim > threadIndex(threadIdx);
184+
PMACC_AUTO(fieldJBlock, fieldJ.shift(blockCell));
185+
186+
ThreadCollective<BlockArea> collectiv(threadIndex);
187+
collectiv(
188+
assign,
189+
cachedJ,
190+
fieldJBlock
191+
);
192+
193+
__syncthreads();
194+
195+
const DataSpace<T_Mapping::Dim> cell(blockCell + threadIndex);
174196

175197
// Amperes Law:
176198
// Change of the dE = - j / EPS0 * dt
177199
// j = current density (= current per area)
178200
// = fieldJ
179-
const float_X deltaT = DELTA_T;
180-
fieldE(cell) -= fieldJ(cell) * (float_X(1.0) / EPS0) * deltaT;
201+
currentInterpolation( fieldE.shift(cell), fieldB.shift(cell), cachedJ.shift(threadIndex) );
181202
}
182203

183204
template<class Mapping>

src/picongpu/include/fields/FieldJ.tpp

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2013-2014 Axel Huebl, Heiko Burau, Rene Widera, Felix Schmitt,
2+
* Copyright 2013-2015 Axel Huebl, Heiko Burau, Rene Widera, Felix Schmitt,
33
* Richard Pausch
44
*
55
* This file is part of PIConGPU.
@@ -53,21 +53,35 @@ using namespace PMacc;
5353

5454
FieldJ::FieldJ( MappingDesc cellDescription ) :
5555
SimulationFieldHelper<MappingDesc>( cellDescription ),
56-
fieldJ( cellDescription.getGridLayout( ) ), fieldE( NULL )
56+
fieldJ( cellDescription.getGridLayout( ) ), fieldE( NULL ), fieldB( NULL ), fieldJrecv( NULL )
5757
{
5858
const DataSpace<simDim> coreBorderSize = cellDescription.getGridLayout( ).getDataSpaceWithoutGuarding( );
5959

60-
60+
/* cell margins the current might spread to due to particle shapes */
6161
typedef typename bmpl::accumulate<
6262
VectorAllSpecies,
6363
typename PMacc::math::CT::make_Int<simDim, 0>::type,
6464
PMacc::math::CT::max<bmpl::_1, GetLowerMargin< GetCurrentSolver<bmpl::_2> > >
65-
>::type LowerMargin;
65+
>::type LowerMarginShapes;
6666

6767
typedef typename bmpl::accumulate<
6868
VectorAllSpecies,
6969
typename PMacc::math::CT::make_Int<simDim, 0>::type,
7070
PMacc::math::CT::max<bmpl::_1, GetUpperMargin< GetCurrentSolver<bmpl::_2> > >
71+
>::type UpperMarginShapes;
72+
73+
/* margins are always positive, also for lower margins
74+
* additional current interpolations and current filters on FieldJ might
75+
* spread the dependencies on neighboring cells
76+
* -> use max(shape,filter) */
77+
typedef typename PMacc::math::CT::max<
78+
LowerMarginShapes,
79+
GetMargin<fieldSolver::CurrentInterpolation>::LowerMargin
80+
>::type LowerMargin;
81+
82+
typedef typename PMacc::math::CT::max<
83+
UpperMarginShapes,
84+
GetMargin<fieldSolver::CurrentInterpolation>::UpperMargin
7185
>::type UpperMargin;
7286

7387
const DataSpace<simDim> originGuard( LowerMargin( ).toRT( ) );
@@ -101,10 +115,34 @@ fieldJ( cellDescription.getGridLayout( ) ), fieldE( NULL )
101115
// std::cout << "ex " << i << " x=" << guardingCells[0] << " y=" << guardingCells[1] << " z=" << guardingCells[2] << std::endl;
102116
fieldJ.addExchangeBuffer( i, guardingCells, FIELD_J );
103117
}
118+
119+
/* Receive border values in own guard for "receive" communication pattern - necessary for current interpolation/filter */
120+
const DataSpace<simDim> originRecvGuard( GetMargin<fieldSolver::CurrentInterpolation>::LowerMargin( ).toRT( ) );
121+
const DataSpace<simDim> endRecvGuard( GetMargin<fieldSolver::CurrentInterpolation>::UpperMargin( ).toRT( ) );
122+
if( originRecvGuard != DataSpace<simDim>::create(0) ||
123+
endRecvGuard != DataSpace<simDim>::create(0) )
124+
{
125+
fieldJrecv = new GridBuffer<ValueType, simDim > ( fieldJ.getDeviceBuffer(), cellDescription.getGridLayout( ) );
126+
127+
/*go over all directions*/
128+
for ( uint32_t i = 1; i < NumberOfExchanges<simDim>::value; ++i )
129+
{
130+
DataSpace<simDim> relativMask = Mask::getRelativeDirections<simDim > ( i );
131+
/* guarding cells depend on direction
132+
* for negative direction use originGuard else endGuard (relative direction ZERO is ignored)
133+
* don't switch end and origin because this is a read buffer and no send buffer
134+
*/
135+
DataSpace<simDim> guardingCells;
136+
for ( uint32_t d = 0; d < simDim; ++d )
137+
guardingCells[d] = ( relativMask[d] == -1 ? originRecvGuard[d] : endRecvGuard[d] );
138+
fieldJrecv->addExchange( GUARD, i, guardingCells, FIELD_JRECV );
139+
}
140+
}
104141
}
105142

106143
FieldJ::~FieldJ( )
107144
{
145+
__delete(fieldJrecv);
108146
}
109147

110148
SimulationDataId FieldJ::getUniqueId( )
@@ -132,7 +170,14 @@ EventTask FieldJ::asyncCommunication( EventTask serialEvent )
132170
__startTransaction( serialEvent );
133171
FieldFactory::getInstance( ).createTaskFieldSend( *this );
134172
ret += __endTransaction( );
135-
return ret;
173+
174+
if( fieldJrecv != NULL )
175+
{
176+
EventTask eJ = fieldJrecv->asyncCommunication( ret );
177+
return eJ;
178+
}
179+
else
180+
return ret;
136181
}
137182

138183
void FieldJ::bashField( uint32_t exchangeType )
@@ -166,9 +211,10 @@ void FieldJ::insertField( uint32_t exchangeType )
166211
direction, mapper );
167212
}
168213

169-
void FieldJ::init( FieldE &fieldE )
214+
void FieldJ::init( FieldE &fieldE, FieldB &fieldB )
170215
{
171216
this->fieldE = &fieldE;
217+
this->fieldB = &fieldB;
172218

173219
Environment<>::get( ).DataConnector( ).registerData( *this );
174220
}
@@ -250,15 +296,17 @@ void FieldJ::computeCurrent( ParticlesClass &parClass, uint32_t ) throw (std::in
250296
__setTransactionEvent( __endTransaction( ) );
251297
}
252298

253-
template<uint32_t AREA>
254-
void FieldJ::addCurrentToE( )
299+
template<uint32_t AREA, class T_CurrentInterpolation>
300+
void FieldJ::addCurrentToEMF( T_CurrentInterpolation& myCurrentInterpolation )
255301
{
256-
__picKernelArea( ( kernelAddCurrentToE ),
302+
__picKernelArea( ( kernelAddCurrentToEMF ),
257303
cellDescription,
258304
AREA )
259305
( MappingDesc::SuperCellSize::toRT( ).toDim3( ) )
260306
( this->fieldE->getDeviceDataBox( ),
261-
this->fieldJ.getDeviceBuffer( ).getDataBox( ) );
307+
this->fieldB->getDeviceDataBox( ),
308+
this->fieldJ.getDeviceBuffer( ).getDataBox( ),
309+
myCurrentInterpolation );
262310
}
263311

264312
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Copyright 2015 Axel Huebl
3+
*
4+
* This file is part of PIConGPU.
5+
*
6+
* PIConGPU is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* PIConGPU is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with PIConGPU.
18+
* If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
#pragma once
22+
23+
namespace picongpu
24+
{
25+
namespace currentInterpolation
26+
{
27+
28+
/* 2nd order Binomial filter */
29+
template<uint32_t T_dim>
30+
struct Binomial;
31+
32+
} /* namespace currentInterpolation */
33+
34+
namespace traits
35+
{
36+
37+
/* Get margin of the current interpolation
38+
*
39+
* This class defines a LowerMargin and an UpperMargin.
40+
*/
41+
template<uint32_t T_dim>
42+
struct GetMargin<picongpu::currentInterpolation::Binomial<T_dim > >
43+
{
44+
private:
45+
typedef picongpu::currentInterpolation::Binomial<T_dim> MyInterpolation;
46+
47+
public:
48+
typedef typename MyInterpolation::LowerMargin LowerMargin;
49+
typedef typename MyInterpolation::UpperMargin UpperMargin;
50+
};
51+
52+
} /* namespace traits */
53+
54+
} /* namespace picongpu */
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* Copyright 2015 Axel Huebl
3+
*
4+
* This file is part of PIConGPU.
5+
*
6+
* PIConGPU is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* PIConGPU is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with PIConGPU.
18+
* If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
#pragma once
22+
23+
#include "simulation_defines.hpp"
24+
#include "types.h"
25+
#include "basicOperations.hpp"
26+
27+
#include "fields/currentInterpolation/None/None.def"
28+
29+
namespace picongpu
30+
{
31+
namespace currentInterpolation
32+
{
33+
using namespace PMacc;
34+
35+
template<uint32_t T_dim>
36+
struct Binomial
37+
{
38+
static const uint32_t dim = T_dim;
39+
40+
typedef typename PMacc::math::CT::make_Int<dim, 1>::type LowerMargin;
41+
typedef typename PMacc::math::CT::make_Int<dim, 1>::type UpperMargin;
42+
43+
template<typename DataBoxE, typename DataBoxB, typename DataBoxJ>
44+
HDINLINE void operator()(DataBoxE fieldE,
45+
DataBoxB,
46+
DataBoxJ fieldJ )
47+
{
48+
const DataSpace<dim> self;
49+
typedef typename DataBoxJ::ValueType TypeJ;
50+
51+
/* 1 2 1 weighting for "left"(1x) "center"(2x) "right"(1x),
52+
* see Pascal's triangle level N=2 */
53+
TypeJ dirSum( TypeJ::create(0.0) );
54+
for( uint32_t d = 0; d < dim; ++d )
55+
{
56+
DataSpace<dim> dw;
57+
dw[d] = -1;
58+
DataSpace<dim> up;
59+
up[d] = 1;
60+
const TypeJ dirDw = fieldJ(dw) + fieldJ(self);
61+
const TypeJ dirUp = fieldJ(up) + fieldJ(self);
62+
63+
/* each fieldJ component is added individually */
64+
dirSum += dirDw + dirUp;
65+
}
66+
67+
/* component-wise division by sum of all weightings,
68+
* in the second order binomial filter these are 4 values per direction
69+
* (1D: 4 values; 2D: 8 values; 3D: 12 values) */
70+
const TypeJ filteredJ = dirSum / TypeJ::create(4.0 * dim);
71+
72+
const float_X deltaT = DELTA_T;
73+
fieldE(self) -= filteredJ * (float_X(1.0) / EPS0) * deltaT;
74+
}
75+
};
76+
77+
} /* namespace currentInterpolation */
78+
79+
} /* namespace picongpu */
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright 2015 Axel Huebl
3+
*
4+
* This file is part of PIConGPU.
5+
*
6+
* PIConGPU is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* PIConGPU is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with PIConGPU.
18+
* If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
22+
#include "fields/currentInterpolation/None/None.def"
23+
#include "fields/currentInterpolation/Binomial/Binomial.def"

0 commit comments

Comments
 (0)