Skip to content

Commit c270936

Browse files
committed
Current Interpolation: During add to EMF
This commit adds the general infrastructure to call functors before adding `FieldJ` to the electro-magnetic fields (in Yee: before manipulating the `E` field). The previous method `None` without interpolation is added as a default in `fieldSolver.param`. Additionally, a simple second order Binomial filter for 2D and 3D is added to test the new functionality.
1 parent d49c404 commit c270936

File tree

11 files changed

+326
-36
lines changed

11 files changed

+326
-36
lines changed

src/picongpu/include/fields/FieldJ.hpp

Lines changed: 5 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

@@ -126,6 +126,7 @@ class FieldJ : public SimulationFieldHelper<MappingDesc>, public ISimulationData
126126
GridBuffer<ValueType, simDim> fieldJ;
127127

128128
FieldE *fieldE;
129+
FieldB *fieldB;
129130
};
130131

131132
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: 10 additions & 7 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,7 +53,7 @@ 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 )
5757
{
5858
const DataSpace<simDim> coreBorderSize = cellDescription.getGridLayout( ).getDataSpaceWithoutGuarding( );
5959

@@ -166,9 +166,10 @@ void FieldJ::insertField( uint32_t exchangeType )
166166
direction, mapper );
167167
}
168168

169-
void FieldJ::init( FieldE &fieldE )
169+
void FieldJ::init( FieldE &fieldE, FieldB &fieldB )
170170
{
171171
this->fieldE = &fieldE;
172+
this->fieldB = &fieldB;
172173

173174
Environment<>::get( ).DataConnector( ).registerData( *this );
174175
}
@@ -250,15 +251,17 @@ void FieldJ::computeCurrent( ParticlesClass &parClass, uint32_t ) throw (std::in
250251
__setTransactionEvent( __endTransaction( ) );
251252
}
252253

253-
template<uint32_t AREA>
254-
void FieldJ::addCurrentToE( )
254+
template<uint32_t AREA, class T_CurrentInterpolation>
255+
void FieldJ::addCurrentToEMF( T_CurrentInterpolation& myCurrentInterpolation )
255256
{
256-
__picKernelArea( ( kernelAddCurrentToE ),
257+
__picKernelArea( ( kernelAddCurrentToEMF ),
257258
cellDescription,
258259
AREA )
259260
( MappingDesc::SuperCellSize::toRT( ).toDim3( ) )
260261
( this->fieldE->getDeviceDataBox( ),
261-
this->fieldJ.getDeviceBuffer( ).getDataBox( ) );
262+
this->fieldB->getDeviceDataBox( ),
263+
this->fieldJ.getDeviceBuffer( ).getDataBox( ),
264+
myCurrentInterpolation );
262265
}
263266

264267
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 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"
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.hpp"
23+
#include "fields/currentInterpolation/Binomial/Binomial.hpp"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
template<uint32_t T_dim>
29+
struct None;
30+
31+
} /* namespace currentInterpolation */
32+
33+
} /* namespace picongpu */

0 commit comments

Comments
 (0)