diff --git a/tests/field/CMakeLists.txt b/tests/field/CMakeLists.txt index 031496b99ca8f34177ec383d1f6b9b22f12b00a5..3c2cd3244fbc7e363e06d7706298e9dc0b605510 100644 --- a/tests/field/CMakeLists.txt +++ b/tests/field/CMakeLists.txt @@ -72,4 +72,9 @@ waLBerla_generate_target_from_python(NAME CodegenPoissonGeneratedKernel FILE cod OUT_FILES Poisson.cpp Poisson.h ) waLBerla_compile_test( FILES codegen/CodegenPoisson.cpp DEPENDS gui timeloop CodegenPoissonGeneratedKernel) waLBerla_execute_test( NAME CodegenPoisson ) + +waLBerla_generate_target_from_python(NAME CodeGenMultipleFieldSwaps FILE codegen/MultipleFieldSwaps.py + OUT_FILES MultipleFieldSwaps.cpp MultipleFieldSwaps.h ) +waLBerla_compile_test( FILES codegen/MultipleFieldSwaps.cpp DEPENDS gui timeloop CodeGenMultipleFieldSwaps) +waLBerla_execute_test( NAME MultipleFieldSwaps ) endif() diff --git a/tests/field/codegen/MultipleFieldSwaps.cpp b/tests/field/codegen/MultipleFieldSwaps.cpp new file mode 100644 index 0000000000000000000000000000000000000000..965bf15a3260cacf0a5ebfb19001a85c98200f8f --- /dev/null +++ b/tests/field/codegen/MultipleFieldSwaps.cpp @@ -0,0 +1,84 @@ +//====================================================================================================================== +// +// 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 +// 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 +// 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/>. +// +//! \file MultipleFieldSwaps.cpp +//! \author Markus Holzer <markus.holzer@fau.de> +// +//====================================================================================================================== + +#include "MultipleFieldSwaps.h" +#include "blockforest/Initialization.h" +#include "blockforest/communication/UniformDirectScheme.h" + +#include "core/Environment.h" +#include "core/debug/TestSubsystem.h" + +#include "field/AddToStorage.h" + +#include "stencil/D2Q9.h" + + +using namespace walberla; + +typedef GhostLayerField<double,1> ScalarField; +void testMultipleFieldSwaps() +{ + uint_t xSize = 5; + uint_t ySize = 5; + // Create blocks + shared_ptr< StructuredBlockForest > blocks = blockforest::createUniformBlockGrid ( + uint_t(1) , uint_t(1), uint_t(1), // number of blocks in x,y,z direction + xSize, ySize, uint_t(1), // how many cells per block (x,y,z) + real_t(1), // dx: length of one cell in physical coordinates + false, // one block per process - "false" means all blocks to one process + true, true, true ); // full periodicity + + + BlockDataID fieldID_1 = field::addToStorage<ScalarField>(blocks, "Field_1", real_t(1.0)); + BlockDataID fieldID_2 = field::addToStorage<ScalarField>(blocks, "Field_2", real_t(1.0)); + BlockDataID fieldID_3 = field::addToStorage<ScalarField>(blocks, "Field_3", real_t(1.0)); + + pystencils::MultipleFieldSwaps kernel(fieldID_1, fieldID_2, fieldID_3); + + for (auto &block: *blocks) + kernel(&block); + + for (auto& block : *blocks) + { + auto field_1 = block.getData< ScalarField >(fieldID_1); + auto field_2 = block.getData< ScalarField >(fieldID_2); + auto field_3 = block.getData< ScalarField >(fieldID_3); + // clang-format off + WALBERLA_FOR_ALL_CELLS_XYZ(field_1, Cell globalCell; + blocks->transformBlockLocalToGlobalCell(globalCell, block, Cell(x, y, z)); + WALBERLA_CHECK_FLOAT_EQUAL(field_1->get(x, y, z), real_t(2.0)) + WALBERLA_CHECK_FLOAT_EQUAL(field_2->get(x, y, z), real_t(2.0)) + WALBERLA_CHECK_FLOAT_EQUAL(field_3->get(x, y, z), real_t(2.0)) + ) + // clang-format on + } +} + + + +int main( int argc, char ** argv ) +{ + mpi::Environment env( argc, argv ); + debug::enterTestMode(); + + testMultipleFieldSwaps(); + + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/tests/field/codegen/MultipleFieldSwaps.py b/tests/field/codegen/MultipleFieldSwaps.py new file mode 100644 index 0000000000000000000000000000000000000000..d4268d8ea020aec22dcd410613c5180b6518fd54 --- /dev/null +++ b/tests/field/codegen/MultipleFieldSwaps.py @@ -0,0 +1,14 @@ +import pystencils as ps +from pystencils_walberla import CodeGeneration, generate_sweep + +with CodeGeneration() as ctx: + src_1, dst_1 = ps.fields("src1, src1_tmp: [2D]", layout='fzyx') + src_2, dst_2 = ps.fields("src2, src2_tmp: [2D]", layout='fzyx') + src_3, dst_3 = ps.fields("src3, src3_tmp: [2D]", layout='fzyx') + + assignments = ps.AssignmentCollection([ps.Assignment(dst_1.center, 2 * src_1.center), + ps.Assignment(dst_2.center, 2 * src_2.center), + ps.Assignment(dst_3.center, 2 * src_3.center)]) + + generate_sweep(ctx, 'MultipleFieldSwaps', assignments, + field_swaps=[(src_1, dst_1), (src_2, dst_2), (src_3, dst_3)])