# Code Generation Tutorials

if( WALBERLA_BUILD_WITH_CODEGEN )

    #   Tutorial 1: Heat Equation with pystencils
    walberla_generate_target_from_python( NAME CodegenHeatEquationKernel
        FILE HeatEquationKernel.py
        OUT_FILES HeatEquationKernel.cpp HeatEquationKernel.h )
    
    walberla_add_executable ( NAME 01_CodegenHeatEquation 
                              FILES 01_CodegenHeatEquation.cpp
                              DEPENDS blockforest core field stencil timeloop vtk pde CodegenHeatEquationKernel )

    #   Tutorial 2: lbmpy Lattice Model Generation
    waLBerla_link_files_to_builddir( *.prm )
    
    walberla_generate_target_from_python( NAME 02_LBMLatticeModelGenerationPython
        FILE 02_LBMLatticeModelGeneration.py
        OUT_FILES   SRTLatticeModel.cpp SRTLatticeModel.h 
                    SRTPackInfo.cpp SRTPackInfo.h )

    walberla_add_executable ( NAME 02_LBMLatticeModelGenerationApp 
                    FILES 02_LBMLatticeModelGeneration.cpp
                    DEPENDS blockforest core domain_decomposition field geometry timeloop lbm stencil vtk 02_LBMLatticeModelGenerationPython )

    #   Tutorial 3: Advanced lbmpy Code Generation
    walberla_generate_target_from_python( NAME 03_AdvancedLBMCodegenPython
        FILE 03_AdvancedLBMCodegen.py
        OUT_FILES   CumulantMRTSweep.${CODEGEN_FILE_SUFFIX} CumulantMRTSweep.h
                    CumulantMRTPackInfo.${CODEGEN_FILE_SUFFIX} CumulantMRTPackInfo.h
                    InitialPDFsSetter.${CODEGEN_FILE_SUFFIX} InitialPDFsSetter.h
                    CumulantMRTNoSlip.${CODEGEN_FILE_SUFFIX} CumulantMRTNoSlip.h)

    if(WALBERLA_BUILD_WITH_GPU_SUPPORT)
        walberla_add_executable ( NAME 03_AdvancedLBMCodegenApp
                FILES 03_AdvancedLBMCodegen.cpp
                DEPENDS blockforest gpu core domain_decomposition field geometry timeloop lbm stencil vtk 03_AdvancedLBMCodegenPython )
    else()
        walberla_add_executable ( NAME 03_AdvancedLBMCodegenApp
                FILES 03_AdvancedLBMCodegen.cpp
                DEPENDS blockforest core domain_decomposition field geometry timeloop lbm stencil vtk 03_AdvancedLBMCodegenPython )
    endif()

    #   Tutorial 4: Advanced lbmpy Code Generation with Complex geometry
    if ( WALBERLA_BUILD_WITH_OPENMESH )

        # Links obj files in PROJECT_ROOT_DIR/geometry to build dir.
        waLBerla_link_geometry_to_builddir(cube.obj)
        waLBerla_link_geometry_to_builddir(bunny.obj)
        
        waLBerla_link_files_to_builddir( "04_LBComplexGeometryConfig.py" )

        set(TUT4_OUT_FILES)
        list(APPEND TUT4_OUT_FILES
            FreeSlipBC.h FreeSlipBC.${CODEGEN_FILE_SUFFIX}
            NoSlipBC.h NoSlipBC.${CODEGEN_FILE_SUFFIX}
            NoSlipQBBBC.h NoSlipQBBBC.${CODEGEN_FILE_SUFFIX}
            ObjNoSlipQBBBC.h ObjNoSlipQBBBC.${CODEGEN_FILE_SUFFIX}
            UBBBC.h UBBBC.${CODEGEN_FILE_SUFFIX}
            OutflowBC.h OutflowBC.${CODEGEN_FILE_SUFFIX}
            LBComplexGeometryStorageSpecification.h LBComplexGeometryStorageSpecification.${CODEGEN_FILE_SUFFIX}
            LBComplexGeometrySweepCollection.h LBComplexGeometrySweepCollection.${CODEGEN_FILE_SUFFIX}
            LBComplexGeometryBoundaryCollection.h
            InfoHeader.h
        )
        
        set(TUT4_DEPENDENCIES blockforest boundary core field geometry lbm lbm_generated mesh python_coupling stencil timeloop vtk 04_LBComplexGeometryPython)
        
        if(WALBERLA_BUILD_WITH_GPU_SUPPORT)
            list(APPEND TUT4_DEPENDENCIES gpu)
        endif()
        
        walberla_generate_target_from_python( 
                NAME 04_LBComplexGeometryPython
                FILE 04_LBComplexGeometry.py
                CODEGEN_CFG 04_codegen
                OUT_FILES  ${TUT4_OUT_FILES}
            )

        walberla_add_executable ( NAME 04_LBComplexGeometryCodeGen
            FILES 04_LBComplexGeometry.cpp
            DEPENDS ${TUT4_DEPENDENCIES} )
    endif()

endif()