Skip to content

Commit 52813be

Browse files
Merge pull request ComputationalRadiationPhysics#1319 from ax3l/topic-refactorFieldPosition
Trait: FieldPosition
2 parents 9a6db62 + 904a2e9 commit 52813be

11 files changed

Lines changed: 279 additions & 248 deletions

File tree

src/picongpu/include/fields/background/templates/TWTS/BField.tpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,11 @@ namespace twts
272272
const uint32_t currentStep ) const
273273
{
274274
const float_64 time_SI = float_64(currentStep) * dt - tdelay;
275+
const fieldSolver::numericalCellType::traits::FieldPosition<FieldB> fieldPosB;
275276

276277
const PMacc::math::Vector<floatD_64,detail::numComponents> bFieldPositions_SI =
277-
detail::getFieldPositions_SI(cellIdx,halfSimSize,
278-
fieldSolver::NumericalCellType::getBFieldPosition(),unit_length,focus_y_SI,phi);
278+
detail::getFieldPositions_SI(cellIdx, halfSimSize,
279+
fieldPosB(), unit_length, focus_y_SI, phi);
279280
/* Single TWTS-Pulse */
280281
switch (pol)
281282
{

src/picongpu/include/fields/background/templates/TWTS/EField.tpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,11 @@ namespace twts
177177
const uint32_t currentStep ) const
178178
{
179179
const float_64 time_SI = float_64(currentStep) * dt - tdelay;
180+
const fieldSolver::numericalCellType::traits::FieldPosition<FieldE> fieldPosE;
180181

181182
const PMacc::math::Vector<floatD_64,detail::numComponents> eFieldPositions_SI =
182-
detail::getFieldPositions_SI(cellIdx,halfSimSize,
183-
fieldSolver::NumericalCellType::getEFieldPosition(),unit_length,focus_y_SI,phi);
183+
detail::getFieldPositions_SI(cellIdx, halfSimSize,
184+
fieldPosE(), unit_length, focus_y_SI, phi);
184185

185186
/* Single TWTS-Pulse */
186187
switch (pol)

src/picongpu/include/fields/background/templates/TWTS/getFieldPositions_SI.tpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,32 @@ namespace detail
5050
or casting on floatD_ does work. */
5151
const floatD_64 cellDim(picongpu::cellSize);
5252
const floatD_64 cellDimensions = cellDim * unit_length;
53-
53+
5454
/* TWTS laser coordinate origin is centered transversally and defined longitudinally by
5555
the laser center in y (usually maximum of intensity). */
5656
floatD_X laserOrigin = precisionCast<float_X>(halfSimSize);
5757
laserOrigin.y() = float_X( focus_y_SI/cellDimensions.y() );
58-
58+
5959
/* For staggered fields (e.g. Yee-grid), obtain the fractional cell index components and add
6060
* that to the total cell indices. The physical field coordinate origin is transversally
6161
* centered with respect to the global simulation volume.
6262
* PMacc::math::Vector<floatD_X, numComponents> fieldPositions =
63-
* fieldSolver::NumericalCellType::getEFieldPosition(); */
63+
* fieldSolver::numericalCellType::traits::FieldPosition<FieldE>(); */
6464
PMacc::math::Vector<floatD_X, numComponents> fieldPositions = fieldOnGridPositions;
65-
65+
6666
PMacc::math::Vector<floatD_64,numComponents> fieldPositions_SI;
67-
67+
6868
for( uint32_t i = 0; i < numComponents; ++i ) /* cellIdx Ex, Ey and Ez */
6969
{
7070
fieldPositions[i] += ( precisionCast<float_X>(cellIdx) - laserOrigin );
7171
fieldPositions_SI[i] = precisionCast<float_64>(fieldPositions[i]) * cellDimensions;
7272

7373
fieldPositions_SI[i] = rotateField(fieldPositions_SI[i],phi);
7474
}
75-
75+
7676
return fieldPositions_SI;
7777
}
78-
78+
7979
} /* namespace detail */
8080
} /* namespace twts */
8181
} /* namespace templates */

src/picongpu/include/fields/currentDeposition/ZigZag/ZigZag.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ struct ZigZag
198198
* - run calculations in a shape optimized coordinate system
199199
* with fixed interpolation points
200200
*/
201-
ShiftCoordinateSystem<Supports_direction>()(cursor, pos, fieldSolver::NumericalCellType::getJFieldPosition()[dir]);
201+
const fieldSolver::numericalCellType::traits::FieldPosition<FieldJ> fieldPosJ;
202+
ShiftCoordinateSystem<Supports_direction>()(cursor, pos, fieldPosJ()[dir]);
202203

203204
/* define grid points where we evaluate the shape function*/
204205
typedef typename PMacc::math::CT::make_Vector<

src/picongpu/include/fields/numericalCellTypes/EMFCenteredCell.hpp

Lines changed: 111 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -23,122 +23,127 @@
2323
#pragma once
2424

2525
#include "simulation_defines.hpp"
26+
#include "fields/Fields.def"
2627
#include "math/Vector.hpp"
2728

2829
namespace picongpu
2930
{
30-
using namespace PMacc;
3131
namespace emfCenteredCell
3232
{
33-
34-
// ___________posE____________
35-
const float_X posE_x_x = 0.5;
36-
const float_X posE_x_y = 0.5;
37-
const float_X posE_x_z = 0.5;
38-
39-
const float_X posE_y_x = 0.5;
40-
const float_X posE_y_y = 0.5;
41-
const float_X posE_y_z = 0.5;
42-
43-
const float_X posE_z_x = 0.5;
44-
const float_X posE_z_y = 0.5;
45-
const float_X posE_z_z = 0.5;
46-
47-
// ___________posB____________
48-
const float_X posB_x_x = 0.5;
49-
const float_X posB_x_y = 0.5;
50-
const float_X posB_x_z = 0.5;
51-
52-
const float_X posB_y_x = 0.5;
53-
const float_X posB_y_y = 0.5;
54-
const float_X posB_y_z = 0.5;
55-
56-
const float_X posB_z_x = 0.5;
57-
const float_X posB_z_y = 0.5;
58-
const float_X posB_z_z = 0.5;
59-
60-
// ___________posJ____________
61-
const float_X posJ_x_x = 0.5;
62-
const float_X posJ_x_y = 0.0;
63-
const float_X posJ_x_z = 0.0;
64-
65-
const float_X posJ_y_x = 0.0;
66-
const float_X posJ_y_y = 0.5;
67-
const float_X posJ_y_z = 0.0;
68-
69-
const float_X posJ_z_x = 0.0;
70-
const float_X posJ_z_y = 0.0;
71-
const float_X posJ_z_z = 0.5;
72-
73-
/** \todo posRho for FieldTmp depositions
74-
const float_X posRho_x_x = 0.0; ? or at center pos ?
75-
const float_X posRho_x_y = 0.0; ?
76-
const float_X posRho_x_z = 0.0; ?
77-
78-
const float_X posRho_y_x = 0.0; ?
79-
const float_X posRho_y_y = 0.0; ?
80-
const float_X posRho_y_z = 0.0; ?
81-
82-
const float_X posRho_z_x = 0.0; ?
83-
const float_X posRho_z_y = 0.0; ?
84-
const float_X posRho_z_z = 0.0; ?
85-
*/
86-
87-
struct EMFCenteredCell
33+
namespace traits
8834
{
8935
/** \tparam floatD_X position of the component in the cell
90-
* \tparam DIM3 Fields (E/B) have 3 components, even in 1 or 2D ! */
91-
typedef ::PMacc::math::Vector<floatD_X,DIM3> VectorVector;
92-
93-
static HDINLINE VectorVector getEFieldPosition()
36+
* \tparam DIM3 Fields (E/B/J) have 3 components, even in 1 or 2D !
37+
*/
38+
typedef const ::PMacc::math::Vector<float2_X,DIM3> VectorVector2D3V;
39+
typedef const ::PMacc::math::Vector<float3_X,DIM3> VectorVector3D3V;
40+
41+
template<typename T_Field, uint32_t T_simDim = simDim>
42+
struct FieldPosition;
43+
44+
/** position (floatD_X in case of T_simDim == simDim) in cell for
45+
* E_x, E_y, E_z
46+
*/
47+
template<uint32_t T_simDim>
48+
struct FieldPosition<FieldE, T_simDim>
9449
{
95-
#if( SIMDIM == DIM3 )
96-
const float3_X posE_x(posE_x_x, posE_x_y, posE_x_z);
97-
const float3_X posE_y(posE_y_x, posE_y_y, posE_y_z);
98-
const float3_X posE_z(posE_z_x, posE_z_y, posE_z_z);
99-
#elif( SIMDIM == DIM2 )
100-
const float2_X posE_x(posE_x_x, posE_x_y);
101-
const float2_X posE_y(posE_y_x, posE_y_y);
102-
const float2_X posE_z(posE_z_x, posE_z_y);
103-
#endif
104-
105-
/** position (floatD_x) in cell for E_x, E_y, E_z */
106-
return VectorVector(posE_x, posE_y, posE_z);
107-
}
108-
109-
static HDINLINE VectorVector getBFieldPosition()
50+
typedef PMacc::math::Vector<float_X, T_simDim> PosType;
51+
typedef const PMacc::math::Vector<PosType, DIM3> ReturnType;
52+
53+
/// boost::result_of hints
54+
template<class> struct result;
55+
56+
template<class F>
57+
struct result<F()> {
58+
typedef ReturnType type;
59+
};
60+
61+
HDINLINE ReturnType operator()() const
62+
{
63+
const PMACC_AUTO(center, PosType::create( 0.5 ));
64+
65+
return ReturnType::create( center );
66+
}
67+
};
68+
69+
/** position (floatD_X in case of T_simDim == simDim) in cell for
70+
* B_x, B_y, B_z
71+
*/
72+
template<uint32_t T_simDim>
73+
struct FieldPosition<FieldB, T_simDim> :
74+
public FieldPosition<FieldE, T_simDim>
11075
{
111-
#if( SIMDIM == DIM3 )
112-
const float3_X posB_x(posB_x_x, posB_x_y, posB_x_z);
113-
const float3_X posB_y(posB_y_x, posB_y_y, posB_y_z);
114-
const float3_X posB_z(posB_z_x, posB_z_y, posB_z_z);
115-
#elif( SIMDIM == DIM2 )
116-
const float2_X posB_x(posB_x_x, posB_x_y);
117-
const float2_X posB_y(posB_y_x, posB_y_y);
118-
const float2_X posB_z(posB_z_x, posB_z_y);
119-
#endif
120-
121-
/** position (floatD_x) in cell for B_x, B_y, B_z */
122-
return VectorVector(posB_x, posB_y, posB_z);
123-
}
124-
125-
static HDINLINE VectorVector getJFieldPosition()
76+
HDINLINE FieldPosition()
77+
{
78+
}
79+
};
80+
81+
/** position (float2_X) in cell for J_x, J_y, J_z */
82+
template<>
83+
struct FieldPosition<FieldJ, DIM2>
12684
{
127-
#if( SIMDIM == DIM3 )
128-
const float3_X posJ_x(posJ_x_x, posJ_x_y, posJ_x_z);
129-
const float3_X posJ_y(posJ_y_x, posJ_y_y, posJ_y_z);
130-
const float3_X posJ_z(posJ_z_x, posJ_z_y, posJ_z_z);
131-
#elif( SIMDIM == DIM2 )
132-
const float2_X posJ_x(posJ_x_x, posJ_x_y);
133-
const float2_X posJ_y(posJ_y_x, posJ_y_y);
134-
const float2_X posJ_z(posJ_z_x, posJ_z_y);
135-
#endif
136-
137-
/** position (floatD_x) in cell for J_x, J_y, J_z */
138-
return VectorVector(posJ_x, posJ_y, posJ_z);
139-
}
140-
141-
};
142-
85+
/// boost::result_of hints
86+
template<class> struct result;
87+
88+
template<class F>
89+
struct result<F()> {
90+
typedef VectorVector2D3V type;
91+
};
92+
93+
HDINLINE VectorVector2D3V operator()() const
94+
{
95+
const float2_X posJ_x( 0.5, 0.0 );
96+
const float2_X posJ_y( 0.0, 0.5 );
97+
const float2_X posJ_z( 0.0, 0.0 );
98+
99+
return VectorVector2D3V( posJ_x, posJ_y, posJ_z );
100+
}
101+
};
102+
103+
/** position (float3_X) in cell for J_x, J_y, J_z
104+
*/
105+
template<>
106+
struct FieldPosition<FieldJ, DIM3>
107+
{
108+
/// boost::result_of hints
109+
template<class> struct result;
110+
111+
template<class F>
112+
struct result<F()> {
113+
typedef VectorVector3D3V type;
114+
};
115+
116+
HDINLINE VectorVector3D3V operator()() const
117+
{
118+
const float3_X posJ_x( 0.5, 0.0, 0.0 );
119+
const float3_X posJ_y( 0.0, 0.5, 0.0 );
120+
const float3_X posJ_z( 0.0, 0.0, 0.5 );
121+
122+
return VectorVector3D3V( posJ_x, posJ_y, posJ_z );
123+
}
124+
};
125+
126+
/** position (floatD_X in case of T_simDim == simDim) in cell for the
127+
* scalar field FieldTmp
128+
*/
129+
template<uint32_t T_simDim>
130+
struct FieldPosition<FieldTmp, T_simDim>
131+
{
132+
typedef PMacc::math::Vector<float_X, T_simDim> ReturnType;
133+
134+
/// boost::result_of hints
135+
template<class> struct result;
136+
137+
template<class F>
138+
struct result<F()> {
139+
typedef ReturnType type;
140+
};
141+
142+
HDINLINE ReturnType operator()() const
143+
{
144+
return ReturnType::create( 0.0 );
145+
}
146+
};
147+
} // traits
143148
} // emfCenteredCell
144149
} // picongpu

0 commit comments

Comments
 (0)