Skip to content

Commit

Permalink
Modified UsesRNG trait, encapsulate RNGFactory
Browse files Browse the repository at this point in the history
RNGFactory is only created when it is needed.
  • Loading branch information
Marco Garten committed Aug 17, 2016
1 parent e73de97 commit cc4047d
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/picongpu/include/particles/ionization/byField/ADK/ADK_Impl.hpp
Expand Up @@ -20,8 +20,11 @@

#pragma once

#include <boost/type_traits/integral_constant.hpp>

#include "simulation_defines.hpp"
#include "traits/Resolve.hpp"
#include "traits/UsesRNG.hpp"
#include "mappings/kernel/AreaMapping.hpp"

#include "fields/FieldB.hpp"
Expand All @@ -42,6 +45,18 @@

namespace picongpu
{
namespace traits
{
/** specialization of the UsesRNG trait
* --> ionization module uses random number generation
*/
template<typename T_IonizationAlgorithm, typename T_DestSpecies, typename T_SrcSpecies>
struct UsesRNG<particles::ionization::ADK_Impl<T_IonizationAlgorithm, T_DestSpecies, T_SrcSpecies> > :
public boost::true_type
{
};
} // namespace traits

namespace particles
{
namespace ionization
Expand Down
21 changes: 19 additions & 2 deletions src/picongpu/include/simulationControl/MySimulation.hpp
Expand Up @@ -26,6 +26,7 @@
#include <string>
#include <vector>
#include <boost/lexical_cast.hpp>
#include <boost/mpl/count.hpp>

#include "pmacc_types.hpp"
#include "simulationControl/SimulationHelper.hpp"
Expand Down Expand Up @@ -285,17 +286,33 @@ class MySimulation : public SimulationHelper<simDim>

laser = new LaserPhysics(cellDescription->getGridLayout());

// Make a list of all species that can be ionized
typedef typename PMacc::particles::traits::FilterByFlag
<
VectorAllSpecies,
ionizer<>
>::type VectorSpeciesWithIonizer;

/* Make a list of `boost::true_type`s and `boost::false_type`s for species that use or do not use the RNG during ionization */
typedef typename PMacc::OperateOnSeq<VectorSpeciesWithIonizer,picongpu::traits::UsesRNG<picongpu::traits::GetIonizer<bmpl::_> > >::type VectorIonizersUsingRNG;
/* define a type that contains the number of `boost::true_type`s when `::value` is accessed */
typedef typename boost::mpl::count<VectorIonizersUsingRNG, boost::true_type>::type NumReqRNGs;

// Initialize random number generator and synchrotron functions, if there are synchrotron photon species
typedef typename PMacc::particles::traits::FilterByFlag<VectorAllSpecies,
synchrotronPhotons<> >::type AllSynchrotronPhotonsSpecies;
if(!bmpl::empty<AllSynchrotronPhotonsSpecies>::value)

if(!bmpl::empty<AllSynchrotronPhotonsSpecies>::value || NumReqRNGs::value)
{
// create factory for the random number generator
this->rngFactory = new RNGFactory(Environment<simDim>::get().SubGrid().getLocalDomain().size);
// init factory
PMacc::GridController<simDim>& gridCon = PMacc::Environment<simDim>::get().GridController();
this->rngFactory->init(gridCon.getScalarPosition());
}

// Initialize synchrotron functions, if there are synchrotron photon species
if(!bmpl::empty<AllSynchrotronPhotonsSpecies>::value)
{
this->synchrotronFunctions.init();
}

Expand Down
43 changes: 43 additions & 0 deletions src/picongpu/include/traits/UsesRNG.hpp
@@ -0,0 +1,43 @@
/**
* Copyright 2016 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 <boost/type_traits/integral_constant.hpp>

namespace picongpu
{
namespace traits
{

/** Checks if an object requires the RNG
*
* @tparam T_Object any object (class or typename)
*
* This struct must inherit from (boost::true_type/false_type)
*/
template<typename T_Object>
struct UsesRNG : public boost::false_type
{
};

}// namespace traits

}// namespace picongpu

0 comments on commit cc4047d

Please sign in to comment.