diff --git a/src/timeloop/SelectableFunctionCreators.h b/src/timeloop/SelectableFunctionCreators.h index 965faf62731b49e438a85fe8ab5148e9be61fe28..b014f44deec75c414387fb4f68df428091db175b 100644 --- a/src/timeloop/SelectableFunctionCreators.h +++ b/src/timeloop/SelectableFunctionCreators.h @@ -45,6 +45,8 @@ namespace timeloop { requiredSelectors_( requiredSelectors ), incompatibleSelectors_( incompatibleSelectors ) {} + FuncCreator() = default; + std::function< FuncType > function_; std::string identifier_; Set<SUID> requiredSelectors_; diff --git a/src/timeloop/SweepTimeloop.cpp b/src/timeloop/SweepTimeloop.cpp index ba8032391781725d91cfde27d7c17d5fc5788943..df4e1d5cd0f96639e80f8bd46ce2f9646ffb02a0 100644 --- a/src/timeloop/SweepTimeloop.cpp +++ b/src/timeloop/SweepTimeloop.cpp @@ -1,15 +1,15 @@ //====================================================================================================================== // -// This file is part of waLBerla. waLBerla is free software: you can +// This file is part of waLBerla. waLBerla 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 +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// waLBerla 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 +// +// waLBerla 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 waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -53,9 +53,18 @@ void SweepTimeloop::doTimeStep(const Set<SUID> &selectors) "No sweep has been registered! Did you only register a BeforeFunction or AfterFunction?" ); } - Sweep * selectedSweep = s.sweep.getUnique( selectors + bi->getState() ); - if (!selectedSweep) + Sweep selectedSweep; + size_t numSweeps = s.sweep.get(selectedSweep, selectors + bi->getState()); + + // ensure that no more than one sweep has been added to a single SweepAdder object + if (numSweeps == size_t(0)) { continue; + } else { + if (numSweeps > size_t(1)) { + WALBERLA_ABORT("Only one sweep must be added to a single SweepAdder object. This error might be caused " + "by e.g. \"timeloop.add() << Sweep(A) << Sweep(B);\".") + } + } WALBERLA_LOG_PROGRESS_SECTION() { @@ -64,7 +73,7 @@ void SweepTimeloop::doTimeStep(const Set<SUID> &selectors) WALBERLA_LOG_PROGRESS("Running sweep \"" << sweepName << "\" on block " << bi->getId() ); } - (selectedSweep->function_)( bi.get() ); + (selectedSweep.function_)( bi.get() ); } // select and execute after functions @@ -105,17 +114,25 @@ void SweepTimeloop::doTimeStep(const Set<SUID> &selectors, WcTimingPool &timing) for( BlockStorage::iterator bi = blockStorage_.begin(); bi != blockStorage_.end(); ++bi ) { + Sweep selectedSweep; std::string sweepName; - Sweep * selectedSweep = s.sweep.getUnique( selectors + bi->getState(), sweepName ); + size_t numSweeps = s.sweep.get(selectedSweep, sweepName, selectors + bi->getState()); - if( !selectedSweep ) + // ensure that no more than one sweep has been added to a single SweepAdder object + if (numSweeps == size_t(0)) { continue; + } else { + if (numSweeps > size_t(1)) { + WALBERLA_ABORT("Only one sweep must be added to a single SweepAdder object. This error might be caused " + "by e.g. \"timeloop.add() << Sweep(A) << Sweep(B);\".") + } + } WALBERLA_LOG_PROGRESS("Running sweep \"" << sweepName << "\" on block " << bi->getId() ); // loop over all blocks timing[sweepName].start(); - (selectedSweep->function_)( bi.get() ); + (selectedSweep.function_)( bi.get() ); timing[sweepName].end(); }