Skip to content
Snippets Groups Projects
Commit e422296b authored by Dominik Thoennes's avatar Dominik Thoennes
Browse files

Merge branch 'mr_codegen_app' into 'master'

Add exemplary codegen app.

See merge request !1
parents 17d335e8 3068ffde
Branches
Tags
No related merge requests found
......@@ -12,3 +12,11 @@ cd build
cmake .. -DWALBERLA_DIR=path/to/walberla/sources
How to build with code generation via pystencils / lbmpy
=========================================================
mkdir build
cd build
cmake .. -DWALBERLA_DIR=path/to/walberla/sources
-DWALBERLA_BUILD_WITH_CODEGEN=ON
-DPython_ROOT_DIR=path/to/python/root/directory
add_subdirectory( example_app )
if( WALBERLA_BUILD_WITH_CODEGEN )
add_subdirectory( example_app_codegen )
endif()
\ No newline at end of file
waLBerla_link_files_to_builddir( *.prm *.py)
waLBerla_generate_target_from_python(NAME LatticeModelGenerated FILE LatticeModel.py
OUT_FILES LatticeModel.cpp LatticeModel.h
)
waLBerla_add_executable ( NAME ExampleAppCodegen
FILES ExampleApp.cpp
DEPENDS blockforest core field lbm geometry timeloop gui
LatticeModelGenerated)
//======================================================================================================================
//
// 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 01_BlocksAndFields.cpp
//! \author Martin Bauer <martin.bauer@fau.de>
//
//======================================================================================================================
#include "blockforest/Initialization.h"
#include "core/Environment.h"
#include "field/Field.h"
#include "gui/Gui.h"
#include "timeloop/SweepTimeloop.h"
namespace walberla {
Field<real_t, 1>* createFields(IBlock* const block, StructuredBlockStorage * const storage) {
return new Field<real_t,1>(storage->getNumberOfXCells(*block),
storage->getNumberOfYCells(*block),
storage->getNumberOfZCells(*block),
real_c(0));
}
int main( int argc, char ** argv )
{
walberla::Environment env( argc, argv );
shared_ptr<StructuredBlockForest> blocks = blockforest::createUniformBlockGrid(
uint_c(3), uint_c(2), uint_c(4),
uint_c(10), uint_c(8), uint_c(12),
real_c(0.5),
false,
false, false, false);
blocks->addStructuredBlockData< Field<real_t,1> >( &createFields, "My Field" );
SweepTimeloop timeloop( blocks, uint_c(1) );
GUI gui( timeloop, blocks, argc, argv );
gui.run();
return EXIT_SUCCESS;
}
}
int main( int argc, char ** argv )
{
return walberla::main(argc, argv);
}
import sympy as sp
from lbmpy import LBMConfig, LBMOptimisation, LBStencil, Method, Stencil
from lbmpy.creationfunctions import create_lb_collision_rule, create_lb_update_rule
from pystencils_walberla import CodeGeneration, generate_pack_info_from_kernel
from lbmpy_walberla import generate_lattice_model
# ========================
# General Parameters
# ========================
stencil = LBStencil(Stencil.D2Q9)
omega = sp.Symbol('omega')
layout = 'fzyx'
# Optimizations for the LBM Method
lbm_opt = LBMOptimisation(cse_global=True, field_layout=layout)
# ===========================
# SRT Method Definition
# ===========================
lbm_config = LBMConfig(stencil=stencil, method=Method.SRT, relaxation_rate=omega)
collision_rule = create_lb_collision_rule(lbm_config=lbm_config, lbm_optimisation=lbm_opt)
# =====================
# Code Generation
# =====================
with CodeGeneration() as ctx:
# generation of the lattice model ...
generate_lattice_model(ctx, "LatticeModel", collision_rule, field_layout=layout)
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