diff --git a/src/boundary/ShiftedPeriodicity.h b/src/boundary/ShiftedPeriodicity.h index f0e46ce010ed80c96077fd6933e4dc776380b15b..7f6181a1384884ab36eb537adefd27dc34779226 100644 --- a/src/boundary/ShiftedPeriodicity.h +++ b/src/boundary/ShiftedPeriodicity.h @@ -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_; } @@ -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; } @@ -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 > diff --git a/tests/boundary/TestShiftedPeriodicity.cpp b/tests/boundary/TestShiftedPeriodicity.cpp index 2351a2f37896cbaaa8d725701b3c33f2dd2396d8..809c8b9b37c128fe19461aa2c11ada950730e2ee 100644 --- a/tests/boundary/TestShiftedPeriodicity.cpp +++ b/tests/boundary/TestShiftedPeriodicity.cpp @@ -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); diff --git a/tests/boundary/TestShiftedPeriodicitySetup.py b/tests/boundary/TestShiftedPeriodicitySetup.py index 1ca890c22f56abb1449ad2f55d63c1350fa029b9..95294fc82d969de9b1073e277d5b0a96f00f6050 100644 --- a/tests/boundary/TestShiftedPeriodicitySetup.py +++ b/tests/boundary/TestShiftedPeriodicitySetup.py @@ -2,11 +2,12 @@ import waLBerla as wlb 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): @@ -17,6 +18,7 @@ class Scenario: 'cellsPerBlock': (4, 4, 4), 'cartesianSetup': 0, 'periodic': self.periodicity, + 'zeroCenteredDomain': self.zero_centered_domain }, 'Boundaries': { 'ShiftedPeriodicity': { @@ -40,4 +42,5 @@ for normal_dir in (0, 1, 2): 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)) diff --git a/tests/gpu/TestShiftedPeriodicityGPU.cpp b/tests/gpu/TestShiftedPeriodicityGPU.cpp index 02cd9777e9535e214a18303b929ae9289fa3f562..e084d58fc8dbc2837c6c8ee25e2f296e27034a42 100644 --- a/tests/gpu/TestShiftedPeriodicityGPU.cpp +++ b/tests/gpu/TestShiftedPeriodicityGPU.cpp @@ -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); diff --git a/tests/gpu/TestShiftedPeriodicitySetupGPU.py b/tests/gpu/TestShiftedPeriodicitySetupGPU.py index 06443685aa1119fbe6391d89e64ae048e047cd93..95294fc82d969de9b1073e277d5b0a96f00f6050 100644 --- a/tests/gpu/TestShiftedPeriodicitySetupGPU.py +++ b/tests/gpu/TestShiftedPeriodicitySetupGPU.py @@ -2,11 +2,12 @@ import waLBerla as wlb 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): @@ -17,6 +18,7 @@ class Scenario: 'cellsPerBlock': (4, 4, 4), 'cartesianSetup': 0, 'periodic': self.periodicity, + 'zeroCenteredDomain': self.zero_centered_domain }, 'Boundaries': { 'ShiftedPeriodicity': { @@ -24,6 +26,9 @@ class Scenario: 'shiftValue': self.shift_value, 'normalDir': self.normal_dir } + }, + 'Logging': { + 'logLevel': "Info" } } @@ -37,4 +42,5 @@ for normal_dir in (0, 1, 2): 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))