Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove attribute chargeState, add boundElectrons #706

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ AttributRadiationFlag
typedef
typename MakeSeq<
DefaultParticleAttributes,
chargeState
boundElectrons
>::type AttributeSeqIons;

/*########################### end particle attributes ########################*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
#include "types.h"
#include "particles/ionization/ionizationEnergies.param"
#include "particles/traits/GetAtomicNumbers.hpp"
#include "traits/attribute/GetChargeState.hpp"

/** IONIZATION ALGORITHM
* - implements the calculation of ionization probability and changes charge states
* by decreasing the number of bound electrons
* - is called with the IONIZATION MODEL, specifically by setting the flag in @see speciesDefinition.param */

namespace picongpu
Expand Down Expand Up @@ -55,12 +57,13 @@ namespace ionization
{

const float_X protonNumber = GetAtomicNumbers<ParticleType>::type::numberOfProtons;
float_X chargeState = attribute::getChargeState(parentIon);

/* ionization condition */
if (math::abs(eField)*UNIT_EFIELD >= SI::IONIZATION_EFIELD && parentIon[chargeState_] < protonNumber)
if (math::abs(eField)*UNIT_EFIELD >= SI::IONIZATION_EFIELD && chargeState < protonNumber)
{
/* set new particle charge state */
parentIon[chargeState_] += float_X(1.0);
parentIon[boundElectrons_] -= float_X(1.0);
}

}
Expand Down
6 changes: 3 additions & 3 deletions src/picongpu/include/particles/ionization/ionization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ struct IonizeParticlesPerFrame
float3_X mom = particle[momentum_];
const float_X mass = attribute::getMass(weighting,particle);

/* define charge state before ionization */
float_X prevChState = particle[chargeState_];
/* define number of bound macro electrons before ionization */
float_X prevBoundElectrons = particle[boundElectrons_];

/* this is the point where actual ionization takes place */
IonizeAlgo ionizeAlgo;
Expand All @@ -109,7 +109,7 @@ struct IonizeParticlesPerFrame
particle[momentum_] = mom;
particle[position_] = pos;
/* determine number of new macro electrons to be created */
newMacroElectrons = particle[chargeState_] - prevChState;
newMacroElectrons = prevBoundElectrons - particle[boundElectrons_];
/*calculate one dimensional cell index*/
particle[localCellIdx_] = DataSpaceOperations<TVec::dim>::template map<TVec > (localCell);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace ionization
* some attributes:
* - multiMask: reading from global memory takes longer than just setting it again explicitly
* - momentum: because the electron would get a higher energy because of the ion mass
* - chargeState: because electrons cannot have a charge state other than 1
* - boundElectrons: because species other than ions or atoms do not have them
* (gets AUTOMATICALLY deselected because electrons do not have this attribute) */
PMACC_AUTO(targetElectronClone, partOp::deselect<bmpl::vector2<multiMask, momentum> >(childElectron));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ value_identifier(float_X, weighting, 0.0);
/** use this particle for radiation diagnostics */
value_identifier(bool, radiationFlag, false);

/** charge state of the particle
/** number of electrons bound to the atom / ion
*
* value type is float_X to avoid casts during the runtime
*
* - float is also reasonable because effective charge numbers are possible
* - only reasonable for ion species if ionization is enabled
* - \todo calculate from new attribute boundElectrons */
value_identifier(float_X,chargeState,float_X(1.0));
*
* \todo connect default to proton number
Copy link
Member

Choose a reason for hiding this comment

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

yes, pls :)

Copy link
Member Author

Choose a reason for hiding this comment

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

waiting for @psychocoderHPC 's #640

*/
value_identifier(float_X,boundElectrons,float_X(0.0));

/** specialization global position inside a domain (relative to origin of the
* moving window) and is loaded after all other param files)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ struct Unit<globalCellIdx<T_Type> >
};

template<>
struct Unit<chargeState >
struct Unit<boundElectrons>
{
static std::vector<double> get()
{
Copy link
Member

Choose a reason for hiding this comment

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

same question as with the radiationFlag: seems to be an empty vector... -> needs verification

Copy link
Member Author

Choose a reason for hiding this comment

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

This is defined here:
Unit.hpp
... and used here:
hdf5/writer/ParticleAttribute.hpp

@psychocoderHPC , your verdict?

Copy link
Member

Choose a reason for hiding this comment

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

please see this issue #707

Copy link
Member

Choose a reason for hiding this comment

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

👍 thx!

Copy link
Member

Choose a reason for hiding this comment

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

@n01r please add a comment above the trait

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess that should be done for all of them in one PR. That would be far more effective than doing each one separately.

Copy link
Member

Choose a reason for hiding this comment

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

fine with me 👍

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "traits/frame/GetCharge.hpp"
#include "traits/frame/GetMass.hpp"
#include "traits/attribute/GetCharge.hpp"
#include "traits/attribute/GetChargeState.hpp"
#include "traits/attribute/GetMass.hpp"
#include "fields/currentDeposition/Solver.hpp"
#include "particles/Particles.tpp"
Expand Down
54 changes: 38 additions & 16 deletions src/picongpu/include/traits/attribute/GetCharge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "simulation_defines.hpp"
#include "traits/frame/GetCharge.hpp"
#include "traits/HasIdentifier.hpp"
#include "particles/traits/GetAtomicNumbers.hpp"

namespace picongpu
{
Expand All @@ -35,49 +36,70 @@ namespace detail

/** Calculate the real charge of a particle
*
* use attribute `chargeState` to calculate the charge
* use attribute `boundElectrons` and the proton number from
* flag `atomicNumbers` to calculate the charge
*
* \tparam T_HasBoundElectrons boolean that describes if species allows multiple charge states
* due to bound electrons
*/
template<bool T_HasChargeState>
struct LoadChargeState
template<bool T_HasBoundElectrons>
struct LoadBoundElectrons
{

/** Functor implementation
*
* \tparam T_Particle particle type
* \param singlyChargedResult charge resulting from multiplying a single
* electron charge (positive OR negative) by the macro particle weighting
* \param particle particle reference
*/
template<typename T_Particle>
Copy link
Member

Choose a reason for hiding this comment

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

pls add a doxygen string for the params here, I am already confused what "partialResult" means :)

Copy link
Member Author

Choose a reason for hiding this comment

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

the right step then would be to also rename partialResult

Copy link
Member

Choose a reason for hiding this comment

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

... and to document what it means in the Doxygen flag * \return this is my description

Copy link
Member Author

Choose a reason for hiding this comment

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

that's why I said: also
;)

HDINLINE float_X operator()(const float_X partialResult, const T_Particle& particle)
HDINLINE float_X operator()(const float_X singlyChargedResult, const T_Particle& particle)
{
return partialResult * particle[chargeState_];
const float_X protonNumber = GetAtomicNumbers<T_Particle>::type::numberOfProtons;

return singlyChargedResult * (protonNumber - particle[boundElectrons_]);
}
};

/** Calculate the real charge of a particle
*
* This is the fallback implementation if no `chargeState` is available for a particle
* This is the fallback implementation if no `boundElectrons` are available for a particle
*
* \tparam T_HasBoundElectrons boolean that describes if species allows multiple charge states
* due to bound electrons
*/
template<>
struct LoadChargeState<false>
struct LoadBoundElectrons<false>
{

/** Functor implementation
*
* \tparam T_Particle particle type
* \param singlyChargedResult charge resulting from multiplying a single
* electron charge (positive OR negative) by the macro particle weighting
* \param particle particle reference
*/
template<typename T_Particle>
HDINLINE float_X operator()(const float_X partialResult, const T_Particle& particle)
HDINLINE float_X operator()(const float_X singlyChargedResult, const T_Particle& particle)
{
return partialResult;
return singlyChargedResult;
}
};
} // namespace detail

/** get the charge of a makro particle
/** get the charge of a macro particle
*
* This function trait take care to the `chargeState` attribute if it is set
* This function trait considers the `boundElectrons` attribute if it is set
*
* @param weighting weighting of the particle
* @param particle a reference to a particle
* @return charge of the makro particle
* @return charge of the macro particle
*/
template<typename T_Particle>
HDINLINE float_X getCharge(const float_X weighting, const T_Particle& particle)
{
typedef T_Particle ParticleType;
typedef typename PMacc::traits::HasIdentifier<ParticleType, chargeState>::type hasChargeState;
return detail::LoadChargeState<hasChargeState::value >()(
typedef typename PMacc::traits::HasIdentifier<ParticleType, boundElectrons>::type hasBoundElectrons;
return detail::LoadBoundElectrons<hasBoundElectrons::value >()(
frame::getCharge<typename ParticleType::FrameType > () * weighting,
particle);
}
Expand Down
92 changes: 92 additions & 0 deletions src/picongpu/include/traits/attribute/GetChargeState.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* Copyright 2014-2015 Marco Garten, Rene Widera
*
* 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 "simulation_defines.hpp"
#include "traits/HasIdentifier.hpp"
#include "algorithms/TypeCast.hpp"
#include "particles/traits/GetAtomicNumbers.hpp"

namespace picongpu
{
namespace traits
{
namespace attribute
{
namespace detail
{

/** Calculate the charge state of an atom / ion
*
* use attribute `boundElectrons` to calculate the charge state
*/
template<bool T_HasBoundElectrons>
struct LoadChargeState
{
/** Functor implementation
*
* \return chargeState = number of electrons in neutral atom - number of currently bound electrons
*/
template<typename T_Particle>
HDINLINE float_X operator()(const T_Particle& particle)
{
const float_X protonNumber = GetAtomicNumbers<T_Particle>::type::numberOfProtons;
return protonNumber - particle[boundElectrons_];
}
};

/** Calculate charge state of an atom / ion
*
* This is the fallback implementation to throw an error if no `boundElectrons`
* are available for a species.
*/
template<>
struct LoadChargeState<false>
{

template<typename T_Particle>
HDINLINE void operator()(const T_Particle& particle)
{
PMACC_CASSERT_MSG(This_species_has_only_one_charge_state,1==2);
}
};
} // namespace detail

/** get the charge state of a macro particle
*
* This function trait considers the `boundElectrons` attribute if it is set.
* Charge states do not add up and also the various particles in a macro particle
* do NOT have different charge states where one would average over them.
*
* @param particle a reference to a particle
* @return charge of the macro particle
*/
template<typename T_Particle>
HDINLINE float_X getChargeState(const T_Particle& particle)
{
typedef T_Particle ParticleType;
typedef typename PMacc::traits::HasIdentifier<ParticleType, boundElectrons>::type hasBoundElectrons;
return detail::LoadChargeState<hasBoundElectrons::value >()(particle);
}

}// namespace attribute
}// namespace traits
}// namespace picongpu