Skip to content

Commit

Permalink
Merge branch 'mr_fix_shifted_periodicity' into 'master'
Browse files Browse the repository at this point in the history
Fix shifted periodicity

See merge request walberla/walberla!705
  • Loading branch information
brendan-waters committed Feb 1, 2025
2 parents 04f9152 + c9b97ee commit c38ab1f
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 14 deletions.
20 changes: 12 additions & 8 deletions src/boundary/ShiftedPeriodicity.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ class ShiftedPeriodicityBase {

// sanity checks
WALBERLA_CHECK_UNEQUAL( shiftDir_, normalDir_, "Direction of periodic shift and boundary normal must not coincide." )

WALBERLA_CHECK( sbf->isPeriodic(shiftDir_), "Blockforest must be periodic in direction " << shiftDir_ << "!" )
WALBERLA_CHECK( !sbf->isPeriodic(normalDir_), "Blockforest must NOT be periodic in direction " << normalDir_ << "!" )

}

Vector3<ShiftType> shift() const { return shift_; }
Expand All @@ -116,6 +112,11 @@ class ShiftedPeriodicityBase {

// only setup send and receive information once at the beginning
if(!setupPeriodicity_){

// check once during setup if the domain's periodicity was well defined
WALBERLA_CHECK( sbf->isPeriodic(shiftDir_), "Blockforest must be periodic in direction " << shiftDir_ << "!" )
WALBERLA_CHECK( !sbf->isPeriodic(normalDir_), "Blockforest must NOT be periodic in direction " << normalDir_ << "!" )

setupPeriodicity();
setupPeriodicity_ = true;
}
Expand Down Expand Up @@ -498,11 +499,14 @@ class ShiftedPeriodicityBase {
}

CellInterval globalAABBToLocalCI( const AABB & aabb, const std::shared_ptr<StructuredBlockForest> & sbf, IBlock * const block ) {
auto globalCI = CellInterval{toCellVector(aabb.min()), toCellVector(aabb.max()) - Vector3<cell_idx_t>(1, 1, 1)};
CellInterval localCI;
sbf->transformGlobalToBlockLocalCellInterval(localCI, *block, globalCI);

return localCI;
Vector3<real_t> local_min;
sbf->transformGlobalToBlockLocal(local_min , *block, aabb.min());

Vector3<real_t> local_max;
sbf->transformGlobalToBlockLocal(local_max , *block, aabb.max());

return CellInterval{toCellVector(local_min), toCellVector(local_max) - Vector3<cell_idx_t>(1, 1, 1)};
}

template< typename tPair >
Expand Down
24 changes: 23 additions & 1 deletion tests/boundary/TestShiftedPeriodicity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,29 @@ int main( int argc, char **argv ) {
logging::configureLogging(config);

// create the domain, flag field and vector field (non-uniform initialisation)
auto blocks = blockforest::createUniformBlockGridFromConfig(config->getBlock("DomainSetup"), nullptr, true);
auto configBlock = config->getBlock("DomainSetup");

const Vector3<bool> periodicity = configBlock.getParameter<Vector3<bool> >( "periodic" );
const Vector3<uint_t> cellsPerBlock = configBlock.getParameter<Vector3<uint_t> >( "cellsPerBlock" );
const Vector3<uint_t> nBlocks = configBlock.getParameter<Vector3<uint_t> >( "blocks" );
const bool zeroCenteredDomain = configBlock.getParameter<bool>( "zeroCenteredDomain" );

Vector3<real_t> domainSize{};
Vector3<real_t> domainCorner{};
for(uint_t d = 0; d < 3; ++d) {
domainSize[d] = real_c(nBlocks[d] * cellsPerBlock[d]);
domainCorner[d] = zeroCenteredDomain ? real_t(0) : - domainSize[d] / real_t(2);
}

auto blocks = blockforest::createUniformBlockGrid(
AABB(domainCorner, domainCorner + domainSize), // AABB spanning the entire domain
nBlocks[0], nBlocks[1], nBlocks[2], // number of blocks in x/y/z direction
cellsPerBlock[0], cellsPerBlock[1], cellsPerBlock[2], // cells per block in x/y/z direction
uint_t(0), // maximum number of blocks per process
true, false, // include but don't force Metis
periodicity[0], periodicity[1], periodicity[2], // periodicity
true // keep global block information
);

const auto fieldID = field::addToStorage< Field_T >(blocks, "test field", real_t(0), field::Layout::fzyx, fieldGhostLayers);
FieldInitialiser< Field_T > initialiser(blocks, fieldID);
Expand Down
7 changes: 5 additions & 2 deletions tests/boundary/TestShiftedPeriodicitySetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@


class Scenario:
def __init__(self, normal_dir, shift_dir, shift_value, periodicity):
def __init__(self, normal_dir, shift_dir, shift_value, periodicity, zero_centered_domain):
self.normal_dir = normal_dir
self.shift_dir = shift_dir
self.shift_value = shift_value
self.periodicity = tuple(periodicity)
self.zero_centered_domain = zero_centered_domain

@wlb.member_callback
def config(self):
Expand All @@ -17,6 +18,7 @@ def config(self):
'cellsPerBlock': (4, 4, 4),
'cartesianSetup': 0,
'periodic': self.periodicity,
'zeroCenteredDomain': self.zero_centered_domain
},
'Boundaries': {
'ShiftedPeriodicity': {
Expand All @@ -40,4 +42,5 @@ def config(self):
periodicity = 3 * [0]
periodicity[shift_dir] = 1
for shift_value in (-3, 0, 2, 5, 8, 15):
scenarios.add(Scenario(normal_dir, shift_dir, shift_value, periodicity))
for zero_centered_domain in (True, False):
scenarios.add(Scenario(normal_dir, shift_dir, shift_value, periodicity, zero_centered_domain))
24 changes: 23 additions & 1 deletion tests/gpu/TestShiftedPeriodicityGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,29 @@ int main( int argc, char **argv ) {
logging::configureLogging(config);

// create the domain, flag field and vector field (non-uniform initialisation)
auto blocks = blockforest::createUniformBlockGridFromConfig(config->getBlock("DomainSetup"), nullptr, true);
auto configBlock = config->getBlock("DomainSetup");

const Vector3<bool> periodicity = configBlock.getParameter<Vector3<bool> >( "periodic" );
const Vector3<uint_t> cellsPerBlock = configBlock.getParameter<Vector3<uint_t> >( "cellsPerBlock" );
const Vector3<uint_t> nBlocks = configBlock.getParameter<Vector3<uint_t> >( "blocks" );
const bool zeroCenteredDomain = configBlock.getParameter<bool>( "zeroCenteredDomain" );

Vector3<real_t> domainSize{};
Vector3<real_t> domainCorner{};
for(uint_t d = 0; d < 3; ++d) {
domainSize[d] = real_c(nBlocks[d] * cellsPerBlock[d]);
domainCorner[d] = zeroCenteredDomain ? real_t(0) : - domainSize[d] / real_t(2);
}

auto blocks = blockforest::createUniformBlockGrid(
AABB(domainCorner, domainCorner + domainSize), // AABB spanning the entire domain
nBlocks[0], nBlocks[1], nBlocks[2], // number of blocks in x/y/z direction
cellsPerBlock[0], cellsPerBlock[1], cellsPerBlock[2], // cells per block in x/y/z direction
uint_t(0), // maximum number of blocks per process
true, false, // include but don't force Metis
periodicity[0], periodicity[1], periodicity[2], // periodicity
true // keep global block information
);

const auto h_fieldID = field::addToStorage< Field_T >(blocks, "test field CPU", real_t(0), field::Layout::fzyx, fieldGhostLayers);
FieldInitialiser< Field_T > initialiser(blocks, h_fieldID);
Expand Down
10 changes: 8 additions & 2 deletions tests/gpu/TestShiftedPeriodicitySetupGPU.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@


class Scenario:
def __init__(self, normal_dir, shift_dir, shift_value, periodicity):
def __init__(self, normal_dir, shift_dir, shift_value, periodicity, zero_centered_domain):
self.normal_dir = normal_dir
self.shift_dir = shift_dir
self.shift_value = shift_value
self.periodicity = tuple(periodicity)
self.zero_centered_domain = zero_centered_domain

@wlb.member_callback
def config(self):
Expand All @@ -17,13 +18,17 @@ def config(self):
'cellsPerBlock': (4, 4, 4),
'cartesianSetup': 0,
'periodic': self.periodicity,
'zeroCenteredDomain': self.zero_centered_domain
},
'Boundaries': {
'ShiftedPeriodicity': {
'shiftDir': self.shift_dir,
'shiftValue': self.shift_value,
'normalDir': self.normal_dir
}
},
'Logging': {
'logLevel': "Info"
}
}

Expand All @@ -37,4 +42,5 @@ def config(self):
periodicity = 3 * [0]
periodicity[shift_dir] = 1
for shift_value in (-3, 0, 2, 5, 8, 15):
scenarios.add(Scenario(normal_dir, shift_dir, shift_value, periodicity))
for zero_centered_domain in (True, False):
scenarios.add(Scenario(normal_dir, shift_dir, shift_value, periodicity, zero_centered_domain))

0 comments on commit c38ab1f

Please sign in to comment.