From cc4047dab3166ec0b4392ba266272c638d78b331 Mon Sep 17 00:00:00 2001 From: Marco Garten Date: Thu, 18 Aug 2016 00:44:34 +0200 Subject: [PATCH] Modified UsesRNG trait, encapsulate RNGFactory RNGFactory is only created when it is needed. --- .../ionization/byField/ADK/ADK_Impl.hpp | 15 +++++++ .../simulationControl/MySimulation.hpp | 21 ++++++++- src/picongpu/include/traits/UsesRNG.hpp | 43 +++++++++++++++++++ 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 src/picongpu/include/traits/UsesRNG.hpp diff --git a/src/picongpu/include/particles/ionization/byField/ADK/ADK_Impl.hpp b/src/picongpu/include/particles/ionization/byField/ADK/ADK_Impl.hpp index 5f4785c9d76..4ed3304e895 100644 --- a/src/picongpu/include/particles/ionization/byField/ADK/ADK_Impl.hpp +++ b/src/picongpu/include/particles/ionization/byField/ADK/ADK_Impl.hpp @@ -20,8 +20,11 @@ #pragma once +#include + #include "simulation_defines.hpp" #include "traits/Resolve.hpp" +#include "traits/UsesRNG.hpp" #include "mappings/kernel/AreaMapping.hpp" #include "fields/FieldB.hpp" @@ -42,6 +45,18 @@ namespace picongpu { +namespace traits +{ + /** specialization of the UsesRNG trait + * --> ionization module uses random number generation + */ + template + struct UsesRNG > : + public boost::true_type + { + }; +} // namespace traits + namespace particles { namespace ionization diff --git a/src/picongpu/include/simulationControl/MySimulation.hpp b/src/picongpu/include/simulationControl/MySimulation.hpp index e7e48a53e2d..4adb20a7a12 100644 --- a/src/picongpu/include/simulationControl/MySimulation.hpp +++ b/src/picongpu/include/simulationControl/MySimulation.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "pmacc_types.hpp" #include "simulationControl/SimulationHelper.hpp" @@ -285,17 +286,33 @@ class MySimulation : public SimulationHelper 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 > >::type VectorIonizersUsingRNG; + /* define a type that contains the number of `boost::true_type`s when `::value` is accessed */ + typedef typename boost::mpl::count::type NumReqRNGs; + // Initialize random number generator and synchrotron functions, if there are synchrotron photon species typedef typename PMacc::particles::traits::FilterByFlag >::type AllSynchrotronPhotonsSpecies; - if(!bmpl::empty::value) + + if(!bmpl::empty::value || NumReqRNGs::value) { // create factory for the random number generator this->rngFactory = new RNGFactory(Environment::get().SubGrid().getLocalDomain().size); // init factory PMacc::GridController& gridCon = PMacc::Environment::get().GridController(); this->rngFactory->init(gridCon.getScalarPosition()); + } + // Initialize synchrotron functions, if there are synchrotron photon species + if(!bmpl::empty::value) + { this->synchrotronFunctions.init(); } diff --git a/src/picongpu/include/traits/UsesRNG.hpp b/src/picongpu/include/traits/UsesRNG.hpp new file mode 100644 index 00000000000..528212d9718 --- /dev/null +++ b/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 . + */ + +#pragma once + +#include + +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 +struct UsesRNG : public boost::false_type +{ +}; + +}// namespace traits + +}// namespace picongpu