Skip to content

Commit

Permalink
change interface conv.* to `conv().*
Browse files Browse the repository at this point in the history
nvcc is not possible to pull static constexpr member into the device
code, therefore acessing a function is required.
  • Loading branch information
psychocoderHPC committed Sep 23, 2024
1 parent 8634640 commit b52224a
Show file tree
Hide file tree
Showing 22 changed files with 226 additions and 220 deletions.
14 changes: 7 additions & 7 deletions docs/source/usage/workflows/ionization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ To include charge-state-only simulations in your simulations you must:
float_X,
7, // number charge states
Nitrogen, // name you may reference this by later, remember to prepend the namespace and append _t!
sim.si.conv.ev2auEnergy(14.53413),
sim.si.conv.ev2auEnergy(29.60125),
sim.si.conv.ev2auEnergy(47.4453),
sim.si.conv.ev2auEnergy(77.4735),
sim.si.conv.ev2auEnergy(97.89013),
sim.si.conv.ev2auEnergy(552.06731),
sim.si.conv.ev2auEnergy(667.04609));
sim.si.conv().ev2auEnergy(14.53413),
sim.si.conv().ev2auEnergy(29.60125),
sim.si.conv().ev2auEnergy(47.4453),
sim.si.conv().ev2auEnergy(77.4735),
sim.si.conv().ev2auEnergy(97.89013),
sim.si.conv().ev2auEnergy(552.06731),
sim.si.conv().ev2auEnergy(667.04609));
}; // namespace picongpu::ionization::energies::AU
.. note::
Expand Down
322 changes: 161 additions & 161 deletions include/picongpu/param/ionizationEnergies.param

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion include/picongpu/param/ionizer.param
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ namespace picongpu
*/
constexpr float_X CUTOFF_MAX_ENERGY_KEV = 50.0;
/** cutoff energy for electron "temperature" calculation in SI units*/
constexpr float_X CUTOFF_MAX_ENERGY = CUTOFF_MAX_ENERGY_KEV * sim.si.conv.ev2Joule(1.0e3);
constexpr float_X CUTOFF_MAX_ENERGY = CUTOFF_MAX_ENERGY_KEV * sim.si.conv().ev2Joule(1.0e3);

/** lower ion density cutoff
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace picongpu::particles::atomicPhysics
// unit conversion factor for eV
constexpr float_X eV = static_cast<float_X>(
picongpu::sim.unit.mass() * picongpu::sim.si.getSpeedOfLight() * picongpu::sim.si.getSpeedOfLight()
* sim.si.conv.joule2ev(1.0));
* sim.si.conv().joule2ev(1.0));

// eV
return energy * eV;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ namespace picongpu::particles::atomicPhysics::initElectrons
float_64 const mE_mI = static_cast<float_64>(massElectron / massIon);
// kg * m^2/s^2 * keV/J * 1e3 = J/J * eV = eV
float_64 const mc2_Ion = static_cast<float_64>(massIon) * sim.unit.mass()
* pmacc::math::cPow(picongpu::sim.si.getSpeedOfLight(), 2u) * sim.si.conv.joule2ev(1.0);
* pmacc::math::cPow(picongpu::sim.si.getSpeedOfLight(), 2u) * sim.si.conv().joule2ev(1.0);

// eV / eV + sim.unit.mass() / sim.unit.mass() = unitless
float_64 const A_E = deltaEnergy / mc2_Ion + mE_mI;
Expand Down Expand Up @@ -248,7 +248,7 @@ namespace picongpu::particles::atomicPhysics::initElectrons
float_64 const mI_mE = static_cast<float_64>(massIon / massElectron);
// kg * m^2/s^2 * keV/J * 1e3 = J/J * eV = eV
float_64 const mc2_Electron = static_cast<float_64>(massElectron) * sim.unit.mass()
* pmacc::math::cPow(picongpu::sim.si.getSpeedOfLight(), 2u) * sim.si.conv.joule2ev(1.0);
* pmacc::math::cPow(picongpu::sim.si.getSpeedOfLight(), 2u) * sim.si.conv().joule2ev(1.0);

float_64 const A_I = deltaEnergy / mc2_Electron + mI_mE;
float_64 const gammaStarIon_IonSystem = (A_I * (A_I + 2.) + (mI_mE * mI_mE)) / ((A_I + 1.) * 2. * mI_mE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ namespace picongpu::particles::atomicPhysics::ionizationPotentialDepression
// eV/(sim.unit.mass() * sim.unit.length()^2 / sim.unit.time()^2)
constexpr float_X eV = static_cast<float_X>(
picongpu::sim.unit.mass() * pmacc::math::cPow(picongpu::sim.unit.length(), 2u)
/ pmacc::math::cPow(picongpu::sim.unit.time(), 2u) * sim.si.conv.joule2ev(1.0));
/ pmacc::math::cPow(picongpu::sim.unit.time(), 2u) * sim.si.conv().joule2ev(1.0));

// eV/(sim.unit.mass() * sim.unit.length()^2 / sim.unit.time()^2) * unitless * sim.unit.charge()^2
// / ( unitless * sim.unit.charge()^2 * sim.unit.time()^2 / (sim.unit.length()^3 * sim.unit.mass()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ namespace picongpu::particles::atomicPhysics::ionizationPotentialDepression::ker
// eV/(sim.unit.mass() * sim.unit.length()^2 / sim.unit.time()^2)
constexpr float_X eV = static_cast<float_X>(
picongpu::sim.unit.mass() * pmacc::math::cPow(picongpu::sim.unit.length(), 2u)
/ pmacc::math::cPow(picongpu::sim.unit.time(), 2u) * sim.si.conv.joule2ev(1.0));
/ pmacc::math::cPow(picongpu::sim.unit.time(), 2u) * sim.si.conv().joule2ev(1.0));

// eV/(sim.unit.mass() * sim.unit.length()^2 / sim.unit.time()^2) * sim.unit.mass() *
// sim.unit.length()^2 / sim.unit.time()^2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ namespace picongpu::particles::atomicPhysics::kernel
float_X const mcSquaredElectron = static_cast<float_X>(
static_cast<float_64>(picongpu::traits::frame::getMass<typename T_Electron::FrameType>())
* sim.unit.mass() * pmacc::math::cPow(picongpu::sim.si.getSpeedOfLight(), 2u)
* sim.si.conv.joule2ev(1.0));
* sim.si.conv().joule2ev(1.0));
// eV, not weighted

// distribute energy change as mean by weight on all electrons in bin
Expand All @@ -134,15 +134,15 @@ namespace picongpu::particles::atomicPhysics::kernel
// usually ~1, internal units

constexpr float_X conversionEnergy
= static_cast<float_X>(sim.si.conv.ev2Joule(1.0) / sim.unit.energy());
= static_cast<float_X>(sim.si.conv().ev2Joule(1.0) / sim.unit.energy());
// J/(eV) * sim.unit.energy()/J = J/J * sim.unit.energy()/(eV)

constexpr float_X scalingFactor = 1._X / c_internal * conversionEnergy;

// sqrt(E' * (E' + 2* m*c^2)) / c
float_X const newElectronMomentum
= math::sqrt(newEnergyElectron * (newEnergyElectron + 2 * mcSquaredElectron)) * scalingFactor;
// AU = sim.si.conv.auEnergy2Joule()
// AU = sim.si.conv().auEnergy2Joule()
// sqrt(eV * (eV + eV))/(sim.unit.length()/sim.unit.time()) * (sim.unit.energy()/eV)
// = sqrt((eV)^2)/(eV) * sim.unit.time()/sim.unit.length() * sim.unit.energy()
// = sim.unit.mass() * sim.unit.length()^2/sim.unit.time()^2 * sim.unit.time()/sim.unit.length()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ namespace picongpu::particles::atomicPhysics::rateCalculation

// J/(eV) / (Js) * s/sim.unit.time() = J/J * s/s * 1/(eV * sim.unit.time())
constexpr float_X scalingConstantPhotonFrequency
= static_cast<float_X>(sim.si.conv.ev2Joule(1.0) / (2 * pi * hbar_SI) * picongpu::sim.unit.time());
= static_cast<float_X>(sim.si.conv().ev2Joule(1.0) / (2 * pi * hbar_SI) * picongpu::sim.unit.time());

/// @attention actual SI frequency, NOT angular frequency
// 1/sim.unit.time()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ namespace picongpu::particles::atomicPhysics::rateCalculation
chargeStateDataBox);
// unitless
float_X const effectivePrincipalQuantumNumber
= screenedCharge / math::sqrt(2._X * ionizationEnergy * sim.si.conv.ev2auEnergy(1.0));
= screenedCharge / math::sqrt(2._X * ionizationEnergy * sim.si.conv().ev2auEnergy(1.0));
float_X const eFieldNorm_AU = sim.pic.conv().eField2auEField(eFieldNorm);
float_X const screenedChargeCubed = pmacc::math::cPow(screenedCharge, 3u);
float_X const dBase = 4.0_X * math::exp(1._X) * screenedChargeCubed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace picongpu::particles2::atomicPhysics::rateCalculation
constexpr float_64 c_SI = picongpu::sim.si.getSpeedOfLight(); // [m/s]
constexpr float_64 m_e_SI = picongpu::sim.si.getElectronMass(); // [kg]

constexpr float_64 electronRestMassEnergy = m_e_SI * c_SI * c_SI / sim.si.conv.ev2Joule(1.0);
constexpr float_64 electronRestMassEnergy = m_e_SI * c_SI * c_SI / sim.si.conv().ev2Joule(1.0);
// kg * (m^2)/(s^2) * 1/(J/eV) = Nm * eV/J = J/J * eV
// [eV] ~ 5.11e5

Expand Down
2 changes: 1 addition & 1 deletion include/picongpu/particles/boundary/Thermal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace picongpu
static constexpr char const* name = "reflectThermalIfOutside";

HINLINE ReflectThermalIfOutside()
: energy((m_parameters.temperature * sim.si.conv.ev2Joule(1.0e3)) / sim.unit.energy())
: energy((m_parameters.temperature * sim.si.conv().ev2Joule(1.0e3)) / sim.unit.energy())
{
}

Expand Down
2 changes: 1 addition & 1 deletion include/picongpu/particles/debyeLength/Estimate.kernel
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ namespace picongpu
using Frame = typename T_ElectronBox::FrameType;
auto const mass = static_cast<double>(picongpu::traits::frame::getMass<Frame>());
auto const kT = (momentumVariance[0] + momentumVariance[1] + momentumVariance[2]) / (3.0 * mass);
auto const temperatureKeV = kT * sim.unit.energy() / sim.si.conv.ev2Joule(1.0e3);
auto const temperatureKeV = kT * sim.unit.energy() / sim.si.conv().ev2Joule(1.0e3);
auto const electronCharge = picongpu::traits::frame::getCharge<Frame>();
auto const debyeLength
= sqrt(sim.pic.getEps0() * kT / (electronDensity * electronCharge * electronCharge));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ namespace picongpu
/** convert kinetic energy in J to "temperature" in eV by assuming an ideal electron gas
* E_kin = 3/2 k*T
*/
constexpr float_64 convKinEnergyToTemperature = sim.si.conv.joule2ev(1.0) * float_64(2. / 3.);
constexpr float_64 convKinEnergyToTemperature = sim.si.conv().joule2ev(1.0) * float_64(2. / 3.);
/** electron "temperature" in electron volts */
float_64 const temperature = avgKinEnergy * convKinEnergyToTemperature;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace picongpu
* the same relation holds, just m and E are also macroweighted
*/
float_X const energy
= (temperatureKeV * sim.si.conv.ev2Joule(1.0e3)) / sim.unit.energy();
= (temperatureKeV * sim.si.conv().ev2Joule(1.0e3)) / sim.unit.energy();
float_X const macroWeighting = particle[weighting_];
float_X const macroEnergy = macroWeighting * energy;
float_X const macroMass = attribute::getMass(macroWeighting, particle);
Expand Down
4 changes: 2 additions & 2 deletions include/picongpu/plugins/BinEnergyParticles.x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ namespace picongpu
auto idProvider = dc.get<IdProvider>("globalId");

/* convert energy values from keV to PIConGPU units */
float_X const minEnergy = minEnergy_keV * sim.si.conv.ev2Joule(1.0e3) / sim.unit.energy();
float_X const maxEnergy = maxEnergy_keV * sim.si.conv.ev2Joule(1.0e3) / sim.unit.energy();
float_X const minEnergy = minEnergy_keV * sim.si.conv().ev2Joule(1.0e3) / sim.unit.energy();
float_X const maxEnergy = maxEnergy_keV * sim.si.conv().ev2Joule(1.0e3) / sim.unit.energy();

auto const mapper = makeAreaMapper<AREA>(*m_cellDescription);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ namespace picongpu
{
const float_64 minEnergy_SI = this->minEnergy * sim.unit.energy();
const float_64 maxEnergy_SI = this->maxEnergy * sim.unit.energy();
const float_64 minEnergy_keV = minEnergy_SI * sim.si.conv.joule2ev(1.0e-3);
const float_64 maxEnergy_keV = maxEnergy_SI * sim.si.conv.joule2ev(1.0e-3);
const float_64 minEnergy_keV = minEnergy_SI * sim.si.conv().joule2ev(1.0e-3);
const float_64 maxEnergy_keV = maxEnergy_SI * sim.si.conv().joule2ev(1.0e-3);

dataset.setAttribute<float_64>("minEnergy[keV]", minEnergy_keV);
dataset.setAttribute<float_64>("maxEnergy[keV]", maxEnergy_keV);
Expand Down Expand Up @@ -301,8 +301,8 @@ namespace picongpu
this->maxYaw_deg = float_X(0.5) * this->openingYaw_deg;
this->maxPitch_deg = float_X(0.5) * this->openingPitch_deg;
/* convert units */
const float_64 minEnergy_SI = this->minEnergy * sim.si.conv.ev2Joule(1.0e3);
const float_64 maxEnergy_SI = this->maxEnergy * sim.si.conv.ev2Joule(1.0e3);
const float_64 minEnergy_SI = this->minEnergy * sim.si.conv().ev2Joule(1.0e3);
const float_64 maxEnergy_SI = this->maxEnergy * sim.si.conv().ev2Joule(1.0e3);
this->minEnergy = minEnergy_SI / sim.unit.energy();
this->maxEnergy = maxEnergy_SI / sim.unit.energy();

Expand Down
18 changes: 12 additions & 6 deletions include/picongpu/unitless/simulation.unitless
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#pragma once

#include "picongpu/param/precision.param"

#include <pmacc/math/ConstVector.hpp>
#include <pmacc/math/Vector.hpp>

Expand Down Expand Up @@ -133,25 +135,25 @@ namespace picongpu
template<typename T_Type = float_X>
constexpr T_Type eField2auEField(T_Type eField = 1.0) const
{
return static_cast<T_Type>(si.conv.eField2auEField(eField * unit.eField()));
return static_cast<T_Type>(si.conv().eField2auEField(eField * unit.eField()));
}

template<typename T_Type = float_X>
constexpr T_Type auEnergy2Joule(T_Type auEnergy = 1.0) const
{
return static_cast<T_Type>(si.conv.auEnergy2Joule(auEnergy) / unit.energy());
return static_cast<T_Type>(si.conv().auEnergy2Joule(auEnergy) / unit.energy());
}

template<typename T_Type = float_X>
constexpr T_Type auTime2Time(T_Type auTime = 1.0) const
{
return static_cast<T_Type>(si.conv.auTime2Time(auTime) / unit.time());
return static_cast<T_Type>(si.conv().auTime2Time(auTime) / unit.time());
}

template<typename T_Type = float_X>
constexpr T_Type time2auTime(T_Type time = 1.0) const
{
return static_cast<T_Type>(si.conv.time2auTime(time * unit.time()));
return static_cast<T_Type>(si.conv().time2auTime(time * unit.time()));
}
};

Expand Down Expand Up @@ -278,7 +280,7 @@ namespace picongpu
constexpr float_64 getRydbergEnergy() const
{
// convert from unit eV to Joule
return conv.ev2Joule(13.605693122990);
return conv().ev2Joule(13.605693122990);
}

/** bohr radius, unit: m
Expand Down Expand Up @@ -373,7 +375,11 @@ namespace picongpu
}
};

static constexpr Convert conv{};
/** get conversion functions */
static constexpr Convert conv()
{
return Convert{};
}
};

/** units to convert from SI into PIConGPU's SI unit system */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace picongpu
* unit: keV
*/
static constexpr float_64 temperature = sim.si.getElectronMass() * sim.si.getSpeedOfLight()
* sim.si.getSpeedOfLight() * sim.si.conv.joule2ev(1.0e-3) * 0.0000002;
* sim.si.getSpeedOfLight() * sim.si.conv().joule2ev(1.0e-3) * 0.0000002;
};
/** Definition of manipulator assigning a temperature
* using parameters from struct TemperatureParamElectrons.
Expand All @@ -96,7 +96,7 @@ namespace picongpu
* unit: keV
*/
static constexpr float_64 temperature = sim.si.getElectronMass() * sim.si.getSpeedOfLight()
* sim.si.getSpeedOfLight() * sim.si.conv.joule2ev(1.0e-3) * 0.00002;
* sim.si.getSpeedOfLight() * sim.si.conv().joule2ev(1.0e-3) * 0.00002;
};
/** Definition of manipulator assigning a temperature
* using parameters from struct TemperatureParamIons.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace picongpu
* unit: keV
*/
static constexpr float_64 temperature = sim.si.getElectronMass() * sim.si.getSpeedOfLight()
* sim.si.getSpeedOfLight() * sim.si.conv.joule2ev(1.0e-3) * 0.0002;
* sim.si.getSpeedOfLight() * sim.si.conv().joule2ev(1.0e-3) * 0.0002;
};
/** Definition of manipulator assigning a temperature
* using parameters from struct TemperatureParamElectrons.
Expand All @@ -83,7 +83,7 @@ namespace picongpu
* unit: keV
*/
static constexpr float_64 temperature = sim.si.getElectronMass() * sim.si.getSpeedOfLight()
* sim.si.getSpeedOfLight() * sim.si.conv.joule2ev(1.0e-3) * 0.00018;
* sim.si.getSpeedOfLight() * sim.si.conv().joule2ev(1.0e-3) * 0.00018;
};
/** Definition of manipulator assigning a temperature
* using parameters from struct TemperatureParamIons.
Expand Down
Loading

0 comments on commit b52224a

Please sign in to comment.