Skip to content
Snippets Groups Projects
Commit c61a659d authored by Markus Holzer's avatar Markus Holzer
Browse files

Added test case to test multiple field swaps in one kernel

parent 5110ba9b
No related merge requests found
...@@ -72,4 +72,9 @@ waLBerla_generate_target_from_python(NAME CodegenPoissonGeneratedKernel FILE cod ...@@ -72,4 +72,9 @@ waLBerla_generate_target_from_python(NAME CodegenPoissonGeneratedKernel FILE cod
OUT_FILES Poisson.cpp Poisson.h ) OUT_FILES Poisson.cpp Poisson.h )
waLBerla_compile_test( FILES codegen/CodegenPoisson.cpp DEPENDS gui timeloop CodegenPoissonGeneratedKernel) waLBerla_compile_test( FILES codegen/CodegenPoisson.cpp DEPENDS gui timeloop CodegenPoissonGeneratedKernel)
waLBerla_execute_test( NAME CodegenPoisson ) 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() endif()
//======================================================================================================================
//
// 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
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)])
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment