Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
930ba25
Add TWTS Template for BG Field
BeyondEspresso Dec 9, 2014
0c25239
Redraft TWTS BG and Refactor FieldE Operator
ax3l Dec 11, 2014
e3a13e8
Reimplement and refactor TWTS core functions in TWTSFieldE and TWTSFi…
BeyondEspresso Feb 5, 2015
2f5545d
Switched to new Complex-class in libPMacc.
BeyondEspresso Feb 13, 2015
95ceb05
Removed 'using namespace' decleration.
BeyondEspresso Feb 13, 2015
af4a59c
Updated repository fieldBackground.param .
BeyondEspresso Feb 13, 2015
700c164
Fix compiling for 2D without pre-compiler directives.
BeyondEspresso Feb 13, 2015
7ac7597
Shorten code lines to 100 chars per line.
BeyondEspresso Feb 23, 2015
c1d72e1
Bugfix: Implement getTime_SI for 2D.
BeyondEspresso Feb 23, 2015
d8dd0e8
Moved fieldBackground.param to example/Bunch. Added cMake test.
BeyondEspresso Feb 27, 2015
8c8a8dc
Remove unitField from TWTS template. Fix function naming.
BeyondEspresso Mar 2, 2015
85610ae
Make field calculations type-independent by float_T.
BeyondEspresso Mar 2, 2015
0dada63
Remove unnecessary precisionCast() calls.
BeyondEspresso Mar 2, 2015
92d18e6
In field functions change to normalized coordinates.
BeyondEspresso Mar 2, 2015
57c8188
Add detail namespace for dummyCasts and cosmetic code cleanup.
BeyondEspresso Mar 4, 2015
ca2315f
Refactor code to eliminate dummyCast-funtions.
BeyondEspresso Mar 11, 2015
f5066b6
Distribute code to seperate files.
BeyondEspresso Mar 16, 2015
1e03788
Get rid of duplicate code.
BeyondEspresso Mar 16, 2015
e25268e
Added twts-namespace.
BeyondEspresso Mar 16, 2015
bafe7f2
Include @psychocoderHPC review suggestions.
BeyondEspresso Mar 17, 2015
7477e0b
Apply more code styling. Lather, rinse, repeat!
BeyondEspresso Mar 20, 2015
954e61e
Bugfix in 2D and comments.
BeyondEspresso Mar 25, 2015
2aa5941
Improve comments.
BeyondEspresso Mar 25, 2015
f22f343
Fixed bug in 2D B-field.
BeyondEspresso Mar 25, 2015
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
3 changes: 2 additions & 1 deletion examples/Bunch/cmakeFlags
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
# - increase by 1, no gaps

flags[0]="-DCUDA_ARCH=sm_35"

flags[1]="-DCUDA_ARCH=sm_35 -DPARAM_OVERWRITES:LIST=-DPARAM_INCLUDE_FIELDBACKGROUND=true"
flags[2]="-DCUDA_ARCH=sm_35 -DPARAM_OVERWRITES:LIST=-DPARAM_INCLUDE_FIELDBACKGROUND=true;-DPARAM_DIMENSION=DIM2"

################################################################################
# execution
Expand Down
225 changes: 225 additions & 0 deletions examples/Bunch/include/simulation_defines/param/fieldBackground.param
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
/**
* Copyright 2014-2015 Axel Huebl, Alexander Debus
*
* This file is part of PIConGPU.
*
* PIConGPU is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PIConGPU is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PIConGPU.
* If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

/** Load pre-defined templates */
#include "fields/background/templates/TWTS/TWTS.hpp"

#ifndef PARAM_INCLUDE_FIELDBACKGROUND
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BeyondEspresso you have become a very gentle developer in a steep curve, I like that! Nice and clean. 👍

#define PARAM_INCLUDE_FIELDBACKGROUND false
#endif

/** Load external background fields
*
*/
namespace picongpu
{
class FieldBackgroundE
{
public:

/* Add this additional field for pushing particles */
static const bool InfluenceParticlePusher = PARAM_INCLUDE_FIELDBACKGROUND;

/* We use this to calculate your SI input back to our unit system */
const float3_64 unitField;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use PMACC_ALIGN to avoid side effects.

PMACC_ALIGN(unitField,const float3_64);

or

const PMACC_ALIGN(unitField,float3_64);


/* TWTS E-fields need to be initialized on host,
* so they can look up global grid dimensions. */
const templates::twts::EField twtsFieldE;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use PMACC_ALIGN


/* Constructor is host-only, because of subGrid and halfSimSize initialization */
HINLINE FieldBackgroundE( const float3_64 unitField ) : unitField(unitField),

twtsFieldE(
/* focus_y [m], the distance to the laser focus in y-direction */
30.0e-6,
/* wavelength [m] */
0.8e-6,
/* pulselength [s], sigma of std. gauss for intensity (E^2) */
10.0e-15 / 2.3548200450309493820231386529194,
/* w_x [m], cylindrically focused spot size */
5.0e-6,
/* w_y [m] */
0.01,
/* interaction angle between TWTS laser propagation vector and the y-axis [rad] */
60. * (PI/180.),
/* propagation speed of overlap [speed of light]. */
1.0,
/* manual time delay [s] if auto_tdelay is false */
39.3e-6 / SI::SPEED_OF_LIGHT_SI,
/* Should PIConGPU automatically choose a suitable time delay? [true/false] */
false )
{}

/** Specify your background field E(r,t) here
*
* \param cellIdx The total cell id counted from the start at t=0
* \param currentStep The current time step */
HDINLINE float3_X
operator()( const DataSpace<simDim>& cellIdx,
const uint32_t currentStep ) const
{
/* example 1: TWTS background pulse */
/** unit: meter */
const double WAVE_LENGTH_SI = 0.8e-6;

/** UNITCONV */
/* const double UNITCONV_Intens_to_A0 = SI::ELECTRON_CHARGE_SI
* SI::ELECTRON_CHARGE_SI * 2.0 * WAVE_LENGTH_SI * WAVE_LENGTH_SI / (4.0 * PI * PI
* SI::ELECTRON_MASS_SI * SI::ELECTRON_MASS_SI * SI::SPEED_OF_LIGHT_SI
* SI::SPEED_OF_LIGHT_SI * SI::SPEED_OF_LIGHT_SI * SI::SPEED_OF_LIGHT_SI
* SI::SPEED_OF_LIGHT_SI * SI::EPS0_SI); */
const double UNITCONV_A0_to_Amplitude_SI = -2.0 * PI / WAVE_LENGTH_SI
* SI::ELECTRON_MASS_SI * SI::SPEED_OF_LIGHT_SI
* SI::SPEED_OF_LIGHT_SI / SI::ELECTRON_CHARGE_SI;

/** unit: W / m^2 */
/* const double _PEAK_INTENSITY_SI = 3.4e19 * 1.0e4; */
/** unit: none */
/* const double _A0 = _PEAK_INTENSITY_SI * UNITCONV_Intens_to_A0; */

/** unit: none */
const double _A0 = 1.0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do not begin variables with _. The _ is reserved in C++ for identifier.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also consistent with laserConfig.param -> I would not change it now but change it consistently in both later on.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

offline discussion -> post-poned to #739


/** unit: Volt /meter */
/*\todo #738 implement math::vector, native type operations */
const float3_64 invUnitField = float3_64(1.0/unitField[0],
1.0/unitField[1],
1.0/unitField[2] );

/* laser amplitude in picongpu units [ unit: (Volt /meter) / unitField-factor ]
* Note: the laser amplitude is included in all field components
* polarization and other properties are established by the peak amplitude
* normalized twtsFieldE(...) */
const float3_X amplitude = precisionCast<float_X>(
float_64(_A0 * UNITCONV_A0_to_Amplitude_SI) * invUnitField );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the point-wise operation / unitField not defined? you could use that instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should do it (the second cast is not necessary):

const float3_X AMPLITUDE_SI = precisionCast<float_X>(
      _A0 * UNITCONV_A0_to_Amplitude_SI / unitField );

you might have to define _A0 and UNITCONV_A0_to_Amplitude_SI as float_64 for that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I tried first. Maybe the point-wise /unitField does not go well with double variables.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@psychocoderHPC interesting. is that a problem specific to 64bit vectors or did we intentionally not implement that?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

side note: something is wrong. either the name AMPLITUDE_SI or the float3_X (occurs multiple times in the code).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked to the code and see that not all vector/native type operations are implemented.
I opend the issue #738

@BeyondEspresso: Please open a issue if you found such things were you need a workarounds to solve a problem. After the issue is opened implement your work around and mark the code part with /*\todo #ISSUENUMBER*/

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name was wrong.


/* Note: twtsFieldE(...) is normalized, such that peak amplitude equals unity. */
return amplitude * twtsFieldE( cellIdx, currentStep );
}
};

class FieldBackgroundB
{
public:
/* Add this additional field for pushing particles */
static const bool InfluenceParticlePusher = PARAM_INCLUDE_FIELDBACKGROUND;

/* TWTS B-fields need to be initialized on host,
* so they can look up global grid dimensions. */
templates::twts::BField twtsFieldB;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use PMACC_ALIGN


/* We use this to calculate your SI input back to our unit system */
const float3_64 unitField;
HINLINE FieldBackgroundB( const float3_64 unitField ) : unitField(unitField),

twtsFieldB(
/* focus_y [m], the distance to the laser focus in y-direction */
30.0e-6,
/* wavelength [m] */
0.8e-6,
/* pulselength [s], sigma of std. gauss for intensity (E^2) */
10.0e-15 / 2.3548200450309493820231386529194,
/* w_x [m], cylindrically focused spot size */
5.0e-6,
/* w_y [m] */
0.01,
/* interaction angle between TWTS laser propagation vector and the y-axis [rad] */
60. * (PI/180.),
/* propagation speed of overlap [speed of light]. */
1.0,
/* manual time delay [s] if auto_tdelay is false */
39.3e-6 / SI::SPEED_OF_LIGHT_SI,
/* Should PIConGPU automatically choose a suitable time delay? [true/false] */
false )
{}

/** Specify your background field B(r,t) here
*
* \param cellIdx The total cell id counted from the start at t=0
* \param currentStep The current time step */
HDINLINE float3_X
operator()( const DataSpace<simDim>& cellIdx,
const uint32_t currentStep ) const
{
/** unit: meter */
const double WAVE_LENGTH_SI = 0.8e-6;

/** UNITCONV */
/* const double UNITCONV_Intens_to_A0 = SI::ELECTRON_CHARGE_SI
* SI::ELECTRON_CHARGE_SI * 2.0 * WAVE_LENGTH_SI * WAVE_LENGTH_SI / (4.0 * PI * PI
* SI::ELECTRON_MASS_SI * SI::ELECTRON_MASS_SI * SI::SPEED_OF_LIGHT_SI
* SI::SPEED_OF_LIGHT_SI * SI::SPEED_OF_LIGHT_SI * SI::SPEED_OF_LIGHT_SI
* SI::SPEED_OF_LIGHT_SI * SI::EPS0_SI); */
const double UNITCONV_A0_to_Amplitude_SI = -2.0 * PI / WAVE_LENGTH_SI
* SI::ELECTRON_MASS_SI * SI::SPEED_OF_LIGHT_SI
* SI::SPEED_OF_LIGHT_SI / SI::ELECTRON_CHARGE_SI;

/** unit: W / m^2 */
/* const double _PEAK_INTENSITY_SI = 3.4e19 * 1.0e4; */
/** unit: none */
/* const double _A0 = _PEAK_INTENSITY_SI * UNITCONV_Intens_to_A0; */

/** unit: none */
const double _A0 = 1.0;

/** unit: Volt /meter */
const float3_64 invUnitField = float3_64(1.0/unitField[0],
1.0/unitField[1],
1.0/unitField[2]);

/* laser amplitude in picongpu units [ unit: (Volt /meter) / unitField-factor ]
* Note: the laser amplitude is included in all field components
* polarization and other properties are established by the peak amplitude
* normalized twtsFieldB(...) */
const float3_X amplitude = precisionCast<float_X>(
float_64(_A0 * UNITCONV_A0_to_Amplitude_SI) * invUnitField );

/* Note: twtsFieldB(...) is normalized, such that peak amplitude equals unity. */
return amplitude * twtsFieldB( cellIdx, currentStep );
}
};

class FieldBackgroundJ
{
public:
/* Add this additional field? */
static const bool activated = false;

/* We use this to calculate your SI input back to our unit system */
const float3_64 unitField;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use PMACC_ALIGN

HDINLINE FieldBackgroundJ( const float3_64 unitField ) : unitField(unitField)
{}

/** Specify your background field J(r,t) here
*
* \param cellIdx The total cell id counted from the start at t=0
* \param currentStep The current time step */
HDINLINE float3_X
operator()( const DataSpace<simDim>& cellIdx,
const uint32_t currentStep ) const
{
return float3_X(0.0, 0.0, 0.0);
}
};

} /* namespace picongpu */
125 changes: 125 additions & 0 deletions src/picongpu/include/fields/background/templates/TWTS/BField.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/**
* Copyright 2014-2015 Alexander Debus, Axel Huebl
*
* This file is part of PIConGPU.
*
* PIConGPU is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PIConGPU is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PIConGPU.
* If not, see <http://www.gnu.org/licenses/>.
*/


#pragma once

#include "types.h"

#include "math/Vector.hpp"
#include "dimensions/DataSpace.hpp"
#include "fields/background/templates/TWTS/numComponents.hpp"

namespace picongpu
{
/** Load pre-defined background field */
namespace templates
{
/** Traveling-wave Thomson scattering laser pulse */
namespace twts
{

class BField
{
public:
typedef float_X float_T;

/* Center of simulation volume in number of cells */
PMACC_ALIGN(halfSimSize,DataSpace<simDim>);
/* y-position of TWTS coordinate origin inside the simulation coordinates [meter]
The other origin coordinates (x and z) default to globally centered values
with respect to the simulation volume. */
const PMACC_ALIGN(focus_y_SI,float_64);
/* Laser wavelength [meter] */
const PMACC_ALIGN(wavelength_SI,float_64);
/* TWTS laser pulse duration [second] */
const PMACC_ALIGN(pulselength_SI,float_64);
/* line focus height of TWTS pulse [meter] */
const PMACC_ALIGN(w_x_SI,float_64);
/* line focus width of TWTS pulse [meter] */
const PMACC_ALIGN(w_y_SI,float_64);
/* interaction angle between TWTS laser propagation vector and the y-axis [rad] */
const PMACC_ALIGN(phi,float_X);
/* propagation speed of TWTS laser overlap
normalized to the speed of light. [Default: beta0=1.0] */
const PMACC_ALIGN(beta_0,float_X);
/* If auto_tdelay=FALSE, then a user defined delay is used. [second] */
const PMACC_ALIGN(tdelay_user_SI,float_64);
/* Make time step constant accessible to device. */
const PMACC_ALIGN(dt,float_64);
/* Make length normalization constant accessible to device. */
const PMACC_ALIGN(unit_length,float_64);
/* TWTS laser time delay */
PMACC_ALIGN(tdelay,float_64);
/* Should the TWTS laser time delay be chosen automatically, such that
the laser gradually enters the simulation volume? [Default: TRUE] */
const PMACC_ALIGN(auto_tdelay,bool);

HINLINE
BField( const float_64 focus_y_SI,
const float_64 wavelength_SI,
const float_64 pulselength_SI,
const float_64 w_x_SI,
const float_64 w_y_SI,
const float_X phi = 90.*(PI/180.),
const float_X beta_0 = 1.0,
const float_64 tdelay_user_SI = 0.0,
const bool auto_tdelay = true );


/** Specify your background field B(r,t) here
*
* \param cellIdx The total cell id counted from the start at t=0
* \param currentStep The current time step */
HDINLINE float3_X
operator()( const DataSpace<simDim>& cellIdx,
const uint32_t currentStep ) const;

/** Calculate the By(r,t) field here
*
* \param pos Spatial position of the target field.
* \param time Absolute time (SI, including all offsets and transformations)
* for calculating the field */
HDINLINE float_T
calcTWTSBy( const float3_64& pos, const float_64 time ) const;

/** Calculate the Bz(r,t) field here
*
* \param pos Spatial position of the target field.
* \param time Absolute time (SI, including all offsets and transformations)
* for calculating the field */
HDINLINE float_T
calcTWTSBz( const float3_64& pos, const float_64 time ) const;

/** Calculate the B-field vector of the TWTS laser in SI units.
* \tparam T_dim Specializes for the simulation dimension
* \param cellIdx The total cell id counted from the start at timestep 0
* \return B-field vector of the rotated TWTS field in SI units */
template<unsigned T_dim>
HDINLINE float3_X
getTWTSBfield_Normalized(
const PMacc::math::Vector<floatD_64,detail::numComponents>& eFieldPositions_SI,
const float_64 time) const;

};

} /* namespace twts */
} /* namespace templates */
} /* namespace picongpu */
Loading