Skip to content

Commit

Permalink
disable the moving window with simulation step X
Browse files Browse the repository at this point in the history
Sometimes for bunch-bunch or bunch-target collision it could be useful to allow to stop the
moving windows. This option is now available via `stopWindow`.

- add cli option `stopWindow`
- refactor `MovingWindow`: add method `setEndSlideOnStep` and `isEnabled`
  • Loading branch information
psychocoderHPC committed Nov 16, 2018
1 parent 82bec20 commit 7ed821a
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 30 deletions.
4 changes: 4 additions & 0 deletions docs/TBG_macros.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ TBG_periodic="--periodic 1 0 1"
# Enables moving window (sliding) in your simulation
TBG_movingWindow="-m"


# stop the moving window after given simulation step
TBG_stopWindow="--stopWindow 1337"

################################################################################
## Placeholder for multi data plugins:
##
Expand Down
2 changes: 1 addition & 1 deletion include/picongpu/fields/FieldManipulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class FieldManipulator
}

/* if sliding window is active we disable absorber on bottom side*/
if (MovingWindow::getInstance().isSlidingWindowActive() && i == BOTTOM) continue;
if (MovingWindow::getInstance().isSlidingWindowActive(currentStep) && i == BOTTOM) continue;

ExchangeMapping<GUARD, MappingDesc> mapper(cellDescription, i);
constexpr uint32_t numWorkers = pmacc::traits::GetNumWorkers<
Expand Down
2 changes: 1 addition & 1 deletion include/picongpu/plugins/IsaacPlugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ class IsaacPlugin : public ILightweightPlugin
{
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &numProc);
if ( MovingWindow::getInstance().isSlidingWindowActive() )
if ( MovingWindow::getInstance().isEnabled() )
movingWindow = true;
float_X minCellSize = math::min( cellSize[0], math::min( cellSize[1], cellSize[2] ) );
float3_X cellSizeFactor = cellSize / minCellSize;
Expand Down
9 changes: 5 additions & 4 deletions include/picongpu/plugins/PngPlugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,14 @@ namespace picongpu
charToAxisNumber(getValue(axis, i)[1])
);
/* if simulation run in 2D ignore all xz, yz slices (we had no z direction)*/
const bool isAllowed2DSlice= (simDim==DIM3) || (transpose.x()!=2 && transpose.y()!=2);
const bool isSlidingWindowActive=MovingWindow::getInstance().isSlidingWindowActive();
const bool isAllowed2DSlice = (simDim == DIM3) || (transpose.x() != 2 && transpose.y() != 2);
const bool isSlidingWindowEnabled = MovingWindow::getInstance().isEnabled();
/* if sliding window is active we are not allowed to create pngs from xz slice
* This means one dimension in transpose must contain 1 (y direction)
*/
const bool isAllowedMovingWindowSlice=!isSlidingWindowActive ||
(transpose.x()==1 || transpose.y()==1);
const bool isAllowedMovingWindowSlice =
!isSlidingWindowEnabled ||
(transpose.x() == 1 || transpose.y() == 1);
if( isAllowed2DSlice && isAllowedMovingWindowSlice )
{
VisType* tmp = new VisType(pluginName, pngCreator, period, transpose, getValue(slicePoints, i));
Expand Down
2 changes: 1 addition & 1 deletion include/picongpu/plugins/adios/WriteSpecies.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ struct WriteSpecies
typedef typename FilterFactory<usedFilters>::FilterType MyParticleFilter;
MyParticleFilter filter;
/* activate filter pipeline if moving window is activated */
filter.setStatus(MovingWindow::getInstance().isSlidingWindowActive());
filter.setStatus(MovingWindow::getInstance().isEnabled());
filter.setWindowPosition(params->localWindowToDomainOffset,
params->window.localDimensions.size);

Expand Down
2 changes: 1 addition & 1 deletion include/picongpu/plugins/hdf5/WriteSpecies.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ struct WriteSpecies
typedef typename FilterFactory<usedFilters>::FilterType MyParticleFilter;
MyParticleFilter filter;
/* activate filter pipeline if moving window is activated */
filter.setStatus(MovingWindow::getInstance().isSlidingWindowActive());
filter.setStatus(MovingWindow::getInstance().isEnabled());
filter.setWindowPosition(params->localWindowToDomainOffset,
params->window.localDimensions.size);

Expand Down
75 changes: 56 additions & 19 deletions include/picongpu/simulationControl/MovingWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ class MovingWindow
{
private:

MovingWindow() : slidingWindowActive(false), slideCounter(0), lastSlideStep(0)
{
}
MovingWindow() = default;

MovingWindow(MovingWindow& cc);

Expand All @@ -50,8 +48,15 @@ class MovingWindow
if (offsetFirstGPU)
*offsetFirstGPU = 0.0;

if (slidingWindowActive)
if (slidingWindowEnabled)
{
/* Sliding stayed enabled but if we reach the end step where we should stop sliding
* the moving window is freezed.
* All offsets will stay constant until the end of the simulation.
*/
if (currentStep >= endSlidingOnStep)
currentStep = endSlidingOnStep;

const SubGrid<simDim>& subGrid = Environment<simDim>::get().SubGrid();

/* speed of the moving window */
Expand Down Expand Up @@ -181,34 +186,55 @@ class MovingWindow
void incrementSlideCounter(const uint32_t currentStep)
{
// do not slide twice in one simulation step
if (slidingWindowActive==true && lastSlideStep < currentStep)
if (isSlidingWindowActive( currentStep ) && lastSlideStep < currentStep)
{
slideCounter++;
lastSlideStep = currentStep;
}
}

/** true is sliding window is activated */
bool slidingWindowActive;
/** true is sliding window is activated
*
* How long the window is sliding is defined with endSlidingOnStep.
*/
bool slidingWindowEnabled = false;

/** current number of slides since start of simulation */
uint32_t slideCounter;
uint32_t slideCounter = 0u;

/**
* last simulation step with slide
* used to prevent multiple slides per simulation step
*/
uint32_t lastSlideStep;
uint32_t lastSlideStep = 0u;

//! time step where the sliding window is stopped
uint32_t endSlidingOnStep = 0u;

public:

/**
* Enable or disable sliding window
* Set step where the simulation stops the moving window
*
* @param value true to enable, false otherwise
* @param step 0 means no sliding window, else sliding is enabled until step is reached.
*/
void setSlidingWindow(bool value)
void setEndSlideOnStep(int32_t step)
{
slidingWindowActive = value;
// maybe we have a underflow in the cast, this is fine because it results in a very large number
const uint32_t maxSlideStep = static_cast<uint32_t>(step);
if ( maxSlideStep < lastSlideStep)
throw std::runtime_error("It is not allowed to stop the moving window in the past.");

endSlidingOnStep = maxSlideStep;

static bool firstCall = true;
/* Disable or enable sliding window only in the first call.
* Later changes of step will not influence if the sliding window is activated.
*/
if (firstCall && endSlidingOnStep != 0u)
slidingWindowEnabled = true;

firstCall = false;
}

/**
Expand Down Expand Up @@ -240,13 +266,24 @@ class MovingWindow
}

/**
* Returns if sliding window is active
* Returns if sliding window is enabled
*
* @return true if enabled, false otherwise
*/
bool isEnabled() const
{
return slidingWindowEnabled;
}

/**
* Returns if the window can move in the current step
*
* @return true if active, false otherwise
* @return false, if Moving window is activated (isEnabled() == true) but already stopped.
* true if moving windows is enabled and simulation step is smaller than
*/
bool isSlidingWindowActive() const
bool isSlidingWindowActive(const uint32_t currenStep) const
{
return slidingWindowActive;
return isEnabled() && currenStep < endSlidingOnStep;
}

/**
Expand All @@ -259,7 +296,7 @@ class MovingWindow
{
bool doSlide = false;

if (slidingWindowActive)
if (slidingWindowEnabled)
{
getCurrentSlideInfo(currentStep, &doSlide, nullptr);
}
Expand Down Expand Up @@ -311,7 +348,7 @@ class MovingWindow
window.globalDimensions = Selection<simDim>(subGrid.getGlobalDomain().size);

/* moving window can only slide in y direction */
if (slidingWindowActive)
if (slidingWindowEnabled)
{
/* the moving window is smaller than the global domain by exactly one
* GPU (local domain size) in moving (y) direction
Expand Down
14 changes: 11 additions & 3 deletions include/picongpu/simulationControl/MySimulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class MySimulation : public SimulationHelper<simDim>
cellDescription(nullptr),
initialiserController(nullptr),
slidingWindow(false),
endSlidingOnStep(-1),
showVersionOnce(false)
{
}
Expand All @@ -143,7 +144,10 @@ class MySimulation : public SimulationHelper<simDim>
("periodic", po::value<std::vector<uint32_t> > (&periodic)->multitoken(),
"specifying whether the grid is periodic (1) or not (0) in each dimension, default: no periodic dimensions")

("moving,m", po::value<bool>(&slidingWindow)->zero_tokens(), "enable sliding/moving window");
("moving,m", po::value<bool>(&slidingWindow)->zero_tokens(), "enable sliding/moving window")
("stopWindow", po::value<int32_t>(&endSlidingOnStep)->default_value(-1),
"stops the window at stimulation step, "
"-1 means that window is never stopping");
}

std::string pluginGetName() const
Expand Down Expand Up @@ -224,7 +228,10 @@ class MySimulation : public SimulationHelper<simDim>

Environment<simDim>::get().initGrids(global_grid_size, gridSizeLocal, gridOffset);

MovingWindow::getInstance().setSlidingWindow(slidingWindow);
if (slidingWindow)
MovingWindow::getInstance().setEndSlideOnStep(endSlidingOnStep);
else
MovingWindow::getInstance().setEndSlideOnStep(0);

log<picLog::DOMAINS > ("rank %1%; localsize %2%; localoffset %3%;") %
myGPUpos.toString() % gridSizeLocal.toString() % gridOffset.toString();
Expand All @@ -238,7 +245,7 @@ class MySimulation : public SimulationHelper<simDim>

if (gc.getGlobalRank() == 0)
{
if (slidingWindow)
if (MovingWindow::getInstance().isEnabled())
log<picLog::PHYSICS > ("Sliding Window is ON");
else
log<picLog::PHYSICS > ("Sliding Window is OFF");
Expand Down Expand Up @@ -807,6 +814,7 @@ class MySimulation : public SimulationHelper<simDim>
std::vector<std::string> gridDistribution;

bool slidingWindow;
int32_t endSlidingOnStep;
bool showVersionOnce;
};
} /* namespace picongpu */
Expand Down

0 comments on commit 7ed821a

Please sign in to comment.