Tutorial - LBM 6: Boundary Conditions

A tutorial for elucidating the usage of and the differences between several boundary conditions

Overview

In this tutorial, we will have a look at several boundary conditions. How they are motivated and implemented, and how they differ from each other.
In general, boundary conditions are both physically and mathematically/ numerically motivated.
The physical systems of interest are usually described by a set of partial differential equations (PDE). In analytical mathematics, boundary conditions help to single out one from all admissible solutions of the PDE. These boundary conditions are imposed by the physical system through, e.g., walls, inflows, outflows, etc.
For discrete numerical schemes, the situation is slightly different. Here, boundary conditions are part of the solution routine, and different implementations of the same physical boundary condition may alter the result. Especially in lattice Boltzmann methods, there is a whole zoo of boundary conditions. This can be easily explained by the fact that boundaries are usually prescribed in terms of macroscopic variables. lattice Boltzmann methods, however, are determined by a set of mesoscopic variables \(f_i(\mathbf{x}, t)\). Different sets of distribution functions may lead to the same hydrodynamic behavior. Eventually, this leads to the question of how to prescribe the mesoscopic variables.
In the following, we will discuss different approaches for wall, inflow and outflow boundary conditions and their realization in waLBerla. You will learn about the differences between them, their limitations, and how to use them.
Note that we will not discuss the generation of boundary conditions with lbmpy. For this, please refer to Tutorial - Code Generation 3: Advanced LBM Code Generation.

Periodic Boundary Conditions

Let us start with boundary conditions that are well known from previous tutorials: periodic boundary conditions.
Periodic boundary conditions are probably the easiest ones to implement and work with. They apply only for solutions with repeating flow patterns and intend to isolate this pattern in order to avoid an unnecessary large computational domain.
In waLBerla, they do not require a special boundary setup but are easily realizable using the functionalities of walberla::blockforest. We either use a configuration file where we specify a parameter periodic in the DomainSetup block, or we manually build the block forest with functions as walberla::blockforest::createUniformBlockGrid. In the latter case, information about periodicity can directly be specified as input arguments of the function. For a system with periodicity in the z-direction, the DomainSetup block in the parameter file may look like

DomainSetup
{
blocks < 1, 1, 1 >;
cellsPerBlock < 300, 80, 1 >;
periodic < 0, 0, 1 >;
}

However, periodic boundaries are often not sufficient for real-world applications. Therefore, we will discuss more realistic boundary conditions in lattice Boltzmann simulations in the following.

The Default Boundary Handling Factory

For standard setups in LBM (channel flow, lid-driven cavity, etc.), waLBerla offers the convenience factory class lbm::DefaultBoundaryHandlingFactory with which you can easily specify no-slip, free-slip, velocity and pressure boundaries in a few lines of code.
As this way of describing boundaries was already detailed in previous tutorials, we will only show some code snippets but will not use them in the provided source file.
In the parameter file, we need to add a block for the boundary handling, e.g.,

Boundaries
{
velocity0 < 0.1, 0, 0 >;
velocity1 < 0, 0, 0 >;
pressure0 1.1;
pressure1 1.0;
Border { direction W; walldistance -1; Velocity0 {} }
Border { direction E; walldistance -1; Pressure1 {} }
Border { direction S,N; walldistance -1; NoSlip {} }
}

You can add up to two different velocities and pressures, respectively. In the Border subblocks, one specifies where to place which boundary condition. In this case, we set up a standard channel flow with an inflow at the west border (min x) and an outflow at the east border (max x). South and north (min and max y, respectively) are set to no-slip.
In general, you want to set walldistance to -1. This lies the boundaries on the outer ghost layers, and the size of the computational domain is not reduced. In the channel flow setup, this means that the actual channel width is equal to the specified (analytical) one.
With this parameter file, we can easily create and initialize the boundary handling as usual:

typedef lbm::DefaultBoundaryHandlingFactory< LatticeModel_T, FlagField_T > BHFactory;
BlockDataID boundaryHandlingId = BHFactory::addBoundaryHandlingToStorage(
blocks, "boundary handling", flagFieldId, pdfFieldId, fluidFlagUID,
velocity0, velocity1, pressure0, pressure1);
geometry::initBoundaryHandling< BHFactory::BoundaryHandling >(*blocks, boundaryHandlingId, boundariesConfig);
geometry::setNonBoundaryCellsToDomain< BHFactory::BoundaryHandling >(*blocks, boundaryHandlingId);

The only part that is left to be done is adding the boundary handling to the time loop such that these boundaries are enforced every time step. For this, we get the sweep directly from the boundary handling class:

timeloop.add() << Sweep(BHFactory::BoundaryHandling::getBlockSweep(boundaryHandlingId), "boundary handling");

And that's it. With these few lines of code, we have successfully implemented our first boundary handling.

But what if we need different boundary conditions? If we need to specify more than two velocities or pressures? If we do not want to have constant inflow or straight boundaries? In these cases, the lbm::DefaultBoundaryHandlingFactory is not sufficient, and we have to set up the boundary handling manually.

Basic Setup for Custom Boundary Handling

In this section, we will explain the basic setup of a simulation if one is not using the lbm::DefaultBoundaryHandlingFactory.
As a standard channel flow nicely shows the differences in the boundaries' behavior, we will, firstly, rebuild the same configuration that was set up with the lbm::DefaultBoundaryHandlingFactory. The basis is, again, Tutorial - LBM 1: Basic LBM Simulation. Hence, we will only comment on differences concerning the boundary handling and will not discuss every detail.

First of all, a structure is defined in which we will gather all relevant simulation parameters for the boundary handling. This is just convenience and not necessarily needed.

struct Setup
{
std::string wallType;
std::string inflowType;
std::string outflowType;
// DynamicUBB
// ParserUBB
Config::BlockHandle parser;
// SimplePAB
};

The first three parameters define which wall, inflow, and outflow types we will use in the simulation. This enables parsing the types from a configuration file, and we do not need to rebuild the executable every time we change one of the boundary condition types. Of course, this has not to be done in a fixed setup.
The next two parameters define the velocity (amplitude) at the inflow and the pressure (or, to be more precise: the density) at the outflow.
Lastly, there are some parameters specific to a particular boundary condition. We will detail their meaning later.

Moreover, we define some variables

// number of ghost layers
// unique identifiers for flags
const FlagUID FluidFlagUID("Fluid Flag");
const FlagUID NoSlipFlagUID("NoSlip Flag");
const FlagUID SimpleUBBFlagUID("SimpleUBB Flag");
const FlagUID SimplePressureFlagUID("SimplePressure Flag");

and typedefs for the boundary handling:

using NoSlip_T = lbm::NoSlip< LatticeModel_T, flag_t >;
using FreeSlip_T = lbm::FreeSlip< LatticeModel_T, FlagField_T >;
using SimpleUBB_T = lbm::SimpleUBB< LatticeModel_T, flag_t >;
using UBB_T = lbm::UBB< LatticeModel_T, flag_t >;
using DynamicUBB_T = lbm::DynamicUBB< LatticeModel_T, flag_t, VelocityFunctor >;
using ParserUBB_T = lbm::ParserUBB< LatticeModel_T, flag_t >;
using SimplePressure_T = lbm::SimplePressure< LatticeModel_T, flag_t >;
using Pressure_T = lbm::Pressure< LatticeModel_T, flag_t >;
using Outlet_T = lbm::Outlet< LatticeModel_T, FlagField_T >;
using SimplePAB_T = lbm::SimplePAB< LatticeModel_T, FlagField_T >;

Here, we already added typedef's for all boundary conditions that will be discussed in the following. If you do not use all of them, it is sufficient to specify only those you utilise. For the default boundary setup this would look like

typedef lbm::NoSlip< LatticeModel_T, flag_t > NoSlip_T;
typedef lbm::SimpleUBB< LatticeModel_T, flag_t > SimpleUBB_T;
typedef lbm::SimplePressure< LatticeModel_T, flag_t > SimplePressure_T;
typedef BoundaryHandling< FlagField_T, Stencil_T,

An object of BoundaryHandling_T will later enforce the boundary conditions for every cell and every timestep.
If you need to use more or different boundary conditions, you need to add corresponding variables and typedef's here.

But how does it know where to enforce which boundary with which parameters? In the default boundary handling factory setup, this was configured in the parameter file and processed in geometry::initBoundaryHandling. As we do not want to use this functionality anymore, we define a functor, MyBoundaryHandling, which should take care of this configuration.

class MyBoundaryHandling
{
public:
MyBoundaryHandling(const BlockDataID& flagFieldID, const BlockDataID& pdfFieldID, const Setup & setup,
const std::shared_ptr< lbm::TimeTracker >& timeTracker)
: flagFieldID_(flagFieldID), pdfFieldID_(pdfFieldID), setup_(setup), timeTracker_(timeTracker)
{}
BoundaryHandling_T* operator()(IBlock* const block, const StructuredBlockStorage* const storage) const;
private:
const BlockDataID flagFieldID_;
const BlockDataID pdfFieldID_;
Setup setup_;
std::shared_ptr< lbm::TimeTracker > timeTracker_;
}; // class MyBoundaryHandling

In general, this class can be designed in any way you want to. However, there is a necessity for an operator operator() (remember: this class must be a functor). Here, we further equipped it with the simulation setup Setup setup_ and a pointer to a lbm::TimeTracker which will be discussed later as the time tracking is only needed for more advanced boundary conditions.
The operator operator() is responsible for correctly setting the flags for the different boundaries, initializing the boundaries, and creating a new BoundaryHandling_T object.
Inside the operator definition, we start with retrieving the flag and pdf fields. Moreover, we get the bitmask of the FluidFlagUID or register the flag if this has not happened yet.

FlagField_T* flagField = block->getData< FlagField_T >(flagFieldID_);
PdfField_T* pdfField = block->getData< PdfField_T >(pdfFieldID_);
const auto fluidFlag = flagField->getOrRegisterFlag(FluidFlagUID);

With this data, we can initialize a new boundary handling object to set the precise boundary conditions. Note that the order of boundary objects is determined by the order of template arguments of BoundaryHandling_T (in particular: add only objects of the classes you specified in the typedef of BoundaryHandling_T). For the lbm::DefaultBoundaryHandlingFactory behavior, this would be

"Boundary Handling", flagField, fluidFlag,
NoSlip_T("NoSlip", NoSlipFlagUID, pdfField),
SimpleUBB_T("SimpleUBB", SimpleUBBFlagUID, pdfField, setup_.inflowVelocity),
SimplePressure_T("SimplePressure", SimplePressureFlagUID, pdfField, setup_.outflowPressure));

With this BoundaryHandling object pointer, we can now set the flag field correctly. Even though you have direct access to the flag field, NEVER set flags directly in the flag field. This has to be done entirely by the boundary handling.
The last step is going over the domain and enforce the correct flags at the boundaries. For this purpose, we get the cell interval that spans the entire simulation domain and convert the cell interval from global coordinates into local coordinates. The conversion has to be done as functions of the boundary handling always expect local cell coordinates.

CellInterval domainBB = storage->getDomainCellBB();
storage->transformGlobalToBlockLocalCellInterval(domainBB, *block);

Further, we extend the domain by FieldGhostLayers cells such that the boundaries will lie on ghost nodes, just as discussed in The Default Boundary Handling Factory .
To give an example, if you wanted to obtain the western boundary (minimum x), you would need to write

domainBB.xMin() -= ghost;
domainBB.xMax() += ghost;
// WEST - Inflow
CellInterval west(domainBB.xMin(), domainBB.yMin(),
domainBB.zMin(), domainBB.xMin(),
domainBB.yMax(), domainBB.zMin());

Finally, we need to specify the required flag, which is done by the forceBoundary function. In the case of SimpleUBB boundaries, this would look like

handling->forceBoundary(SimpleUBBFlagUID, west);

After all boundary flags were set accordingly, we fill the remaining cells with fluid

handling->fillWithDomain(domainBB);

and return the boundary handling object handling.

Now it is only left to adjust the main according to our custom boundary handling. Firstly, we add the boundary handling to every block by

BlockDataID const boundaryHandlingID = blocks->addStructuredBlockData< BoundaryHandling_T >(
MyBoundaryHandling(flagFieldID, pdfFieldID, setup, timeTracker), "boundary handling");

instead of initializing the BoundaryHandlingFactory. Secondly, we add the corresponding sweep

timeloop.add() << BeforeFunction(communication, "communication")
<< Sweep(BoundaryHandling_T::getBlockSweep(boundaryHandlingID), "boundary handling");

That's it! We have successfully set up our first custom boundary handling and can run the simulation.

In the next section, we will detail the different boundary conditions provided by waLBerla and how to incorporate them into the basic setup correctly.

Velocity Boundary Conditions

The first family of boundaries we will have a look at are the velocity boundary conditions. We have already seen two of them in the lbm::DefaultBoundaryHandlingFactory (NoSlip and Velocity0), but now we will detail them and show alternatives.
In general, there are two different approaches for boundary conditions in lattice Boltzmann methods with straight boundaries: the link-wise and the wet-node approach. Whereas the computational boundary lies on lattice links for link-wise boundary conditions (bounce-back), the computational boundary lies on lattice nodes and hence coincides with the physical boundary for wet-node approaches.
We will spare the theoretical details here and focus on the differences between the specific implementations. We will always need to add a boundary object to BoundaryHandling_T and force the flag accordingly.
To begin with, we comment on wall boundaries before we provide an overview of the different schemes for open boundaries.

Wall Boundaries

In physical systems, the domain of interest is often limited by some kind of wall, e.g., the pipe in pipe flows. Hence, it is crucial to have correct implementations of wall boundaries. In waLBerla, both wall boundaries, NoSlip and FreeSlip, are realized by bounce-back schemes, which belong to the link-wise family.

NoSlip

The no-slip condition is the most common fluid-solid interface condition in hydrodynamics. It assumes impermeable walls and zero velocity of the fluid relative to the wall.
The usage of NoSlip is quite straightforward, and we have already seen it in the basic setup.
In the constructor of handling, we add a simple NoSlip_T object as

NoSlip_T("NoSlip", NoSlipFlagUID, pdfField),

Moreover, when forcing the boundary flag, we use the command

handling->forceBoundary(NoSlipFlagUID, south);

With this, the NoSlip boundary condition is already finished, and we have a look at the other wall boundary condition, the FreeSlip.

FreeSlip

The free-slip condition also assumes impermeable walls, i.e., zero normal velocity. However, in contrast to the no-slip condition, it places no restrictions on the tangential fluid velocity. Instead, it enforces a specular reflection on the wall.

As the FreeSlip boundary requires special boundary handling at corners and edges, we need to provide more information. Hence, we add

FreeSlip_T("FreeSlip", FreeSlipFlagUID, pdfField, flagField, fluidFlag),

to the handling object. As you can see, the additional required information is the flag field and the domain flag. With this, the boundary is forced as usual

handling->forceBoundary(FreeSlipFlagUID, south);

Open Boundaries

Things become more interesting when considering open boundaries as inflows or outflows. Again, these can be modeled using bounce-back schemes. waLBerla offers four implementations of bounce-back velocity boundary conditions, which will be detailed in the following. Afterward, we briefly comment on the wet-node approach for velocity boundary conditions.

SimpleUBB

The SimpleUBB is the most simple and also the most efficient velocity boundary that is implemented in waLBerla. Whereas all UBB-named schemes implement the standard bounce-back velocity boundary conditions, the internal handling differs.
With a single SimpleUBB boundary, only one velocity value can be set. In doing so, only three real_t values have to be stored per boundary, which reduces the memory consumption for the boundary object.
Due to its simplicity, the setup is quite straightforward. We just need to add

SimpleUBB_T("SimpleUBB", SimpleUBBFlagUID, pdfField, setup_.inflowVelocity),

to the handling. The flag is set by

handling->forceBoundary(SimpleUBBFlagUID, west);

UBB

In some cases, the SimpleUBB is not sufficient to specify the requested boundary conditions, e.g., when applying non-constant inflow. Then, you can use the UBB boundary conditions.
We will illustrate the usage of UBB boundaries prescribing a fully developed Poiseuille flow at the inlet which is given by

\[ u_x(y) = - 4 u_0 \cdot \frac{y (y - H)}{H^2}, \]

where \(H\) is the channel height. Again, we add information to the BoundaryHandling_T object as

UBB_T("UBB", UBBFlagUID, pdfField),

Enforcing the correct flags on the boundary is a bit more complicated than usual. Here, we need to iterate through the boundary cells and set every cell flag separately with the corresponding prescribed velocity.
As we have already mentioned in Basic Setup for Custom Boundary Handling, the BoundaryHandling classes assume block-local coordinates. The prescribed velocity, however, is defined in terms of the global coordinate \(y\). For this reason, we first calculate the offset of the current block, i.e., the shift from local to global coordinates. With this offset, we iterate over the boundary and calculate the cell position in global coordinates. Finally, we assign the boundary flag with the corresponding velocity to each cell:

Cell offset(0, 0, 0);
storage->transformBlockLocalToGlobalCell(offset, *block);
for (auto cellIt = west.begin(); cellIt != west.end(); ++cellIt)
{
Cell globalCell = *cellIt + offset;
const real_t y = real_c(globalCell[1]);
Vector3< real_t > ubbVel(0);
ubbVel[0] = -real_t(4) * y * (y - H) / (H * H) * setup_.inflowVelocity[0];
handling->forceBoundary(UBBFlagUID, cellIt->x(), cellIt->y(), cellIt->z(), UBB_T::Velocity(ubbVel));
}

An advantage is, of course, the greater flexibility. But it comes at a cost. Instead of three real_t values in total for the velocity, now three real_t values per cell have to be stored for the inflow velocity. Therefore, the memory consumption is higher, but the boundary condition is also more costly, as the values have to be loaded from memory first in every time step before applying the boundary treatment.

DynamicUBB

Until now, only static inflow was discussed. However, it is possible in waLBerla to also define dynamic boundary conditions, realized by the class DynamicUBB.
You might have already noticed that we introduced an ominous template argument for the DynamicUBB_T typedef:

typedef lbm::DynamicUBB< LatticeModel_T, flag_t, VelocityFunctor > DynamicUBB_T;

This ominous argument is the self-written VelocityFunctor class which is responsible for prescribing the correct velocity at a certain point in time and space.
Let us shortly assume that an object of this class and a time tracker are already given. The handling object then is enriched by an object of DynamicUBB_T, which looks as follows:

DynamicUBB_T("DynamicUBB", DynamicUBBFlagUID, pdfField, timeTracker_, storage->getLevel(*block), velocity,
block->getAABB()),

The timeTracker_ is the linkage between the time loop and the VelocityFunctor velocity and provides information about the current time step. We will see how to set it up later in this section. Moreover, we add the current refinement level with storage->getLevel(*block) (this is necessary as time and space scales are different for refinement) and the bounding box of the block block->getAABB() from which the global position of a cell is obtained. But now, let us discuss the VelocityFunctor more in-depth. In this example, we will again prescribe a Poiseuille profile at the inlet, swelling and fading with time.
In general, the functor for DynamicUBB requires the implementation of two operators:

  • void operator()(const real_t time): this function is called once before boundary treatment. Its parameter is the current time step.
  • Vector3<real_t> operator()(const Vector3<real_t> & position, const real_t time): this function is called during boundary treatment for each and every boundary link. It takes the position of the boundary cell and the current time step and returns the prescribed velocity.

In the case of our prescribed time-dependent Poiseuille inflow, the VelocityFunctor may look like

class VelocityFunctor
{
public:
VelocityFunctor(const Vector3< real_t >& velocity, real_t period, real_t H)
: velocity_(velocity), period_(period), H_(H)
{
constantTerm_ = real_t(4) * velocity_[0] / (H_ * H_);
}
void operator()(const real_t time)
{
amplitude_ = constantTerm_ * real_t(0.5) * (real_t(1) - std::cos(real_t(2) * math::pi * time / period_));
}
{
return Vector3< real_t >(amplitude_ * pos[1] * (H_ - pos[1]), real_t(0), real_t(0));
}
private:
const real_t period_;
const real_t H_;
real_t constantTerm_; // part of the velocity that is constant in both time and space
};

Lastly, we need to detail the time tracker, which is created by

std::shared_ptr< lbm::TimeTracker > const timeTracker = std::make_shared< lbm::TimeTracker >();

This alone is not sufficient as the time tracker holds no information about the time loop and, therefore, the progress in time during the simulation. The coupling between time tracker and time loop is done by adding a functor to the time loop:

timeloop.addFuncAfterTimeStep(makeSharedFunctor(timeTracker), "time tracking");

With this, the time counter in the tracker has incremented automatically every time step (note that we assume a time step size of 1 for unrefined domains; in refined domains, the step size is adjusted accordingly).

ParserUBB

With the boundary conditions discussed in previous sessions, we can do whatever we want to. But in case we want to experiment with different velocity profiles, this approach is not very flexible, and we would need to recompile the entire application after every little change to the profile.
The ParserUBB boundary condition was introduced in waLBerla to circumvent this problem. Here, the profile can be described at runtime with simple mathematical expressions.

First, let us have a look at the ParserUBB object that is passed to the handling. If you want to define time-dependent equations for the boundary, this object needs to be specified as

ParserUBB_T("ParserUBB", ParserUBBFlagUID, pdfField, flagField, timeTracker_, storage->getLevel(*block),
block->getAABB()),

If you have time-independent equations only, you can, of course, omit the time tracker.
For the ParserUBB, we define a configuration block in the parameter file. It may look like

Parser {
x 0.1 * 4 / 80 / 80 * y * (80 - y) * 0.5 * (1 - cos(2 * 3.1415926538 * t / 150));
y 0;
z 0;
}

In this configuration block, just define for each velocity component the symbolic equation. If no equation is given, the velocity defaults to 0 in this direction. As symbols, you may use the coordinates x, y, and z, as well as the current time.

To eventually pass the boundary condition the flag field, use

handling->forceBoundary(ParserUBBFlagUID, west, ParserUBB_T::Parser(setup_.parser));

So far, so good. But you might have noticed that we hard-coded information like the domain height and the periodicity. So we needed to check always that, e.g., \( H \) and the domain height in the DomainSetup config block match. If you still experiment with the domain size, this can be dangerous and you might prefer to specify the height symbolically.
This can be done by defining the equations in the source code and feeding them with variables, e.g.

char x_eq[150];
sprintf(x_eq, "0.1*4/%f/%f * y * (%f - y) * 0.5 * (1 - cos(2 * 3.1415926538 * t / %f));", H, H, H, setup_.period);
std::array< std::string, 3 > eqs = { x_eq, "0", "0" };
handling->forceBoundary(ParserUBBFlagUID, west, ParserUBB_T::Parser(eqs));

Wet-Node Approaches

Until now, we have only discussed bounce-back schemes, both for wall and open boundaries. But as already mentioned, there is another family of boundary conditions: the wet-node boundary conditions. In waLBerla, there are two implementations for wet-node boundaries: the SimpleVelocityBoundary and the VelocityBoundary. Both are versions of the equilibrium scheme. As this scheme has some deficiencies (accuracy, need for explicitly enforcing the continuity equation at the boundary, etc.), we suggest using them only if you already have experience with these kinds of boundary conditions. Hence, we will not further discuss them here.

Pressure Boundary Conditions

Now that we have discussed inflows and walls in great detail, only the pressure boundary conditions for the outflows are left.
As for the velocity boundary conditions, there are multiple ways to enforce a certain pressure at an outlet. In lattice Boltzmann solvers, however, it is usually the density that is prescribed, as it is more directly related to the pdfs. As density and pressure, in turn, are linked via \(p = c_s^2 \rho\), this is perfectly legitimate.

SimplePressure

Our first boundary condition to be discussed is the SimplePressure that is based on the anti-bounce-back method. Here, the pdfs are calculated by the fixed boundary density and an approximated boundary velocity.
Analogously to the SimpleUBB, it prescribes only one value for the entire boundary. The setup is likewise simple. Again, we add a boundary object with information about the outflow density to the boundary handler

SimplePressure_T("SimplePressure", SimplePressureFlagUID, pdfField, setup_.outflowPressure),

and enforce the boundary flags at the outflow

handling->forceBoundary(SimplePressureFlagUID, east);

Pressure

The Pressure boundary conditions are, as can be expected, the generalized version of the SimplePressure. Likewise based on the anti-bounce-back approach, we can specify a complete density profile instead of a single value.
The boundary object can be simply defined as

Pressure_T("Pressure", PressureFlagUID, pdfField),

To set the precise profile of the outflow density, we need to iterate over all affected boundary cells again and manually set the single values. This is done analogously to the UBB conditions and results in

Cell offset(0, 0, 0);
storage->transformBlockLocalToGlobalCell(offset, *block);
for (auto cellIt = east.begin(); cellIt != east.end(); ++cellIt)
{
Cell globalCell = *cellIt + offset;
const real_t y = real_c(globalCell[1]);
real_t local_density =
setup_.outflowPressure * (real_t(1.0) + real_t(0.01) * std::sin(real_t(2.0 * 3.1415926538) * y / H));
handling->forceBoundary(PressureFlagUID, cellIt->x(), cellIt->y(), cellIt->z(),
Pressure_T::LatticeDensity(local_density));
}

When running the simulations for these two pressure boundary conditions, you will notice pressure waves reflected at the outlet. These pressure waves are characteristic of such simple outlets and cannot be avoided. However, if your system is sensitive to acoustic perturbations or the pressure waves are too strong, you will need to use more advanced, non-reflective outlet conditions.

SimplePAB

The SimplePAB is an enhanced version of the previously mentioned anti-bounce-back methods. In contrast to the Pressure implementations, this version uses an improved approximation of the boundary velocity by extrapolation. Also, it includes an additional correction term for errors of second-order.
As calculating the pdfs is more complex for this kind of pressure condition, we also need to provide information about the domain cells (via flag field) and the relaxation rate. Hence, the boundary object can be set up as follows.

SimplePAB_T("SimplePAB", SimplePABFlagUID, pdfField, flagField, setup_.outflowPressure, setup_.omega,

As everything is handled internally, however, the setting of the boundary flags is rather easy.

handling->forceBoundary(SimplePABFlagUID, east);

Despite the error correction, note in the simulation output that the system is still adherent to the pressure waves. One way to eliminate these pressure waves is, e.g., the usage of extrapolation boundary conditions, as the Outlet.

Outlet

The Outlet boundary conditions are not based on the anti-bounce-back method but the pure extrapolation of the pdfs, hence enforcing a particular pressure gradient at the outflow. While these are not yet completely non-reflective, the Outlet boundary conditions significantly reduce the spurious reflections at the boundary.
Implementation-wise, they are straightforward to set up, as everything is handled internally by extrapolation, and no further information is needed. The boundary object is defined as

Outlet_T("Outlet", OutletFlagUID, pdfField, flagField, fluidFlag),

whereas the boundary flags are enforced as

handling->forceBoundary(OutletFlagUID, east);

Even though the initial pressure wave stemming from the inflow is reflected once or twice, the boundaries quickly absorb these reflections, and the system is stabilized. Hence, the Outlet boundary conditions are well suited for all configurations where the acoustic reflections are too strong for a physical solution. Note, however, that lbmpy offers even more specialized extrapolation boundary conditions that further stabilize the domain.

LatticeModel_T::Stencil Stencil_T
Definition: 02_LBMLatticeModelGeneration.cpp:56
@ S
South.
Definition: Directions.h:47
std::string wallType
Definition: 06_LBBoundaryCondition.cpp:73
real_t constantTerm_
Definition: 06_LBBoundaryCondition.cpp:120
MyBoundaryHandling(const BlockDataID &flagFieldId, const BlockDataID &pdfFieldId, const real_t topVelocity)
Definition: 03_LBLidDrivenCavity.cpp:111
lbm::FreeSlip< LatticeModel_T, FlagField_T > FreeSlip_T
Definition: 06_LBBoundaryCondition.cpp:128
SharedFunctor< F > makeSharedFunctor(const shared_ptr< F > &functorPtr)
Definition: SharedFunctor.h:46
VelocityFunctor(const Vector3< real_t > &velocity, real_t period, real_t H)
Definition: 06_LBBoundaryCondition.cpp:99
@ N
North.
Definition: Directions.h:46
const real_t period_
Definition: 06_LBBoundaryCondition.cpp:117
const FlagUID SimpleUBBFlagUID("SimpleUBB Flag")
std::string outflowType
Definition: 06_LBBoundaryCondition.cpp:75
const FlagUID PressureFlagUID("Pressure Flag")
lbm::DynamicUBB< LatticeModel_T, flag_t, VelocityFunctor > DynamicUBB_T
Definition: 06_LBBoundaryCondition.cpp:132
constexpr real_t pi
Definition: Constants.h:42
const BlockDataID pdfFieldID_
Definition: 06_LBBoundaryCondition.cpp:158
real_t period
Definition: 06_LBBoundaryCondition.cpp:81
const uint_t FieldGhostLayers
[variableDefines]
Definition: 06_LBBoundaryCondition.cpp:50
lbm::ParserUBB< LatticeModel_T, flag_t > ParserUBB_T
Definition: 06_LBBoundaryCondition.cpp:133
const FlagUID DynamicUBBFlagUID("DynamicUBB Flag")
BoundaryHandling_T * operator()(IBlock *const block) const
Definition: 03_LBLidDrivenCavity.cpp:125
int cell_idx_t
Definition: DataTypes.h:151
FuncCreator< void(IBlock *)> Sweep
Definition: SelectableFunctionCreators.h:133
real_t amplitude_
Definition: 06_LBBoundaryCondition.cpp:121
std::shared_ptr< lbm::TimeTracker > timeTracker_
Definition: 06_LBBoundaryCondition.cpp:161
const FlagUID OutletFlagUID("Outlet Flag")
const BlockDataID flagFieldID_
Definition: 06_LBBoundaryCondition.cpp:157
std::size_t uint_t
Definition: DataTypes.h:133
lbm::SimplePressure< LatticeModel_T, flag_t > SimplePressure_T
Definition: 06_LBBoundaryCondition.cpp:135
const FlagUID FreeSlipFlagUID("FreeSlip Flag")
float real_t
Definition: DataTypes.h:167
lbm::CumulantMRTNoSlip NoSlip_T
[VelocityFunctor]
Definition: 03_AdvancedLBMCodegen.cpp:69
const FlagUID ParserUBBFlagUID("ParserUBB Flag")
@ E
East.
Definition: Directions.h:49
void operator()(const real_t time)
Definition: 06_LBBoundaryCondition.cpp:105
static BlockSweep getBlockSweep(const BlockDataID handling, const uint_t numberOfGhostLayersToInclude=0)
Definition: BoundaryHandling.h:347
lbm::PdfField< LatticeModel_T > PdfField_T
[typedefs]
Definition: 02_LBMLatticeModelGeneration.cpp:60
@ W
West.
Definition: Directions.h:48
FlagField< flag_t > FlagField_T
Definition: 02_LBMLatticeModelGeneration.cpp:64
const FlagUID FluidFlagUID("Fluid Flag")
Vector3< real_t > inflowVelocity
Definition: 06_LBBoundaryCondition.cpp:77
const FlagUID SimplePABFlagUID("SimplePAB Flag")
lbm::SimpleUBB< LatticeModel_T, flag_t > UBB_T
Definition: 03_LBLidDrivenCavity.cpp:79
const FlagUID SimplePressureFlagUID("SimplePressure Flag")
lbm::SimpleUBB< LatticeModel_T, flag_t > SimpleUBB_T
Definition: 06_LBBoundaryCondition.cpp:130
const real_t H_
Definition: 06_LBBoundaryCondition.cpp:118
const FlagUID NoSlipFlagUID("NoSlip Flag")
const FlagUID UBBFlagUID("UBB Flag")
lbm::Outlet< LatticeModel_T, FlagField_T > Outlet_T
Definition: 06_LBBoundaryCondition.cpp:137
real_t omega
Definition: 06_LBBoundaryCondition.cpp:87
Config::BlockHandle parser
Definition: 06_LBBoundaryCondition.cpp:84
Setup setup_
Definition: 06_LBBoundaryCondition.cpp:160
BoundaryHandling< FlagField_T, Stencil_T, NoSlip_T, UBB_T > BoundaryHandling_T
Definition: 03_LBLidDrivenCavity.cpp:82
lbm::Pressure< LatticeModel_T, flag_t > Pressure_T
Definition: 06_LBBoundaryCondition.cpp:136
std::string inflowType
Definition: 06_LBBoundaryCondition.cpp:74
static BlockDataID addBoundaryHandlingToStorage(const shared_ptr< StructuredBlockStorage > &bs, const std::string &identifier, BlockDataID flagFieldID, BlockDataID pdfFieldID, const Set< FlagUID > &flagUIDSet, const Vector3< real_t > &velocity0, const Vector3< real_t > &velocity1, const real_t pressure0, const real_t pressure1)
Definition: DefaultBoundaryHandling.h:85
real_t outflowPressure
Definition: 06_LBBoundaryCondition.cpp:78
lbm::DefaultBoundaryHandlingFactory< LatticeModel_T, FlagField_T > BHFactory
Definition: 02_LBMLatticeModelGeneration.cpp:65
const Vector3< real_t > velocity_
Definition: 06_LBBoundaryCondition.cpp:116
lbm::SimplePAB< LatticeModel_T, FlagField_T > SimplePAB_T
Definition: 06_LBBoundaryCondition.cpp:138