Geometry / Read the grid
Does the endpoint occupy a sample?
Predict the coordinates before you run the code.
Download runnable lesson (.zip)
Includes the model, inputs, required headers and a short run guide.
Before choosing a stencil or an FFT, decide what the endpoints mean. Five samples on a periodic interval and five samples including both endpoints are different grids, even when their physical bounds are identical.
Count intervals before dividing
For \(N\) periodic samples on \([a,b)\), there are \(N\) intervals around the periodic cycle: \(h=(b-a)/N\). For \(N\) samples including both ends of a closed interval, there are \(N-1\) intervals: \(h=(b-a)/(N-1)\). OpenPFC’s domain::from_bounds makes this choice independently for each axis.
for (bool periodic : {true, false}) {
const auto grid = pfc::domain::from_bounds(
{5, 2, 2}, {0, 0, 0}, {2 * std::numbers::pi, 1, 1}, {periodic, true, true});
for (int i = 0; i < 5; ++i) {
const double x = pfc::domain::to_coords(grid, {i, 0, 0})[0];
std::cout << (periodic ? "periodic" : "closed") << ',' << i << ',' << x << ','
<< pfc::domain::get_spacing(grid)[0] << ','
<< pfc::domain::upper(grid)[0] << '\n';
}
}With \(N=5\) and \([a,b]=[0,2\pi]\), the periodic x coordinates stop at \(8\pi/5\). The closed-grid coordinates include \(2\pi\). In both cases domain::upper returns the requested bound. On the periodic grid that bound is an image of the first sample, rather than a sixth stored sample.
Make the convention explicit
openpfc run model.cpp input.json --launcher=noneThis source-driven lesson ignores the empty input file; edit its constants to experiment. Its CSV is printed to standard output. Change the sample count in both the domain and loop, then predict the last coordinate. Keep every nonperiodic axis at least two samples wide in this experiment.
Periodicity is geometric metadata here. It does not choose a derivative, exchange a halo, or impose a boundary equation by itself. Compare the periodic heat stencil with explicit boundary equations. The regression checks all ten coordinates against independent interval counts. The exact contract is in the public domain header.
The complete C++ model and starting input are available with this lesson.