# periodic boundaries for 3 D systems

Hi,

I am doing simulation for periodic boundaries on all sides of a 3D system. The flow is driven by a body force. I used lattice.collideAndStream(true) to signify periodic boundaries
In the interior of the system, using bounce-back, my code looks like

while(in)

``````{

for (int iZ=1; iZ< nz-1; ++iZ) {
for (int iY=1; iY< ny-1; ++iY) {
for (int iX=1; iX<nx-1; ++iX) {
in.get(ch);
if(ch == '0')
{
T u = converter.getLatticeU();
T vel[3] = { u, T(), T() };
T force[3] = { poiseuilleforce(converter), T(), T() };
lattice.get(iX,iY,iZ).defineExternalField(
DESCRIPTOR<T>::ExternalField::forceBeginsAt,
DESCRIPTOR<T>::ExternalField::sizeOfForce,
force
);
lattice.get(iX,iY,iZ).defineRhoU((T)1, vel);
lattice.get(iX,iY,iZ).iniEquilibrium((T)1, vel);

}
else if(ch == '1')
{
lattice.defineDynamics(iX,iX,iY,iY,iZ,iZ,
&instances::getBounceBack<T, DESCRIPTOR> () );
}
}
}
}
}
``````

While the sides are defined as below

T u = converter.getLatticeU();
T vel[3] = { u, T(), T() };
T force[3] = { poiseuilleforce(converter), T(), T() };

``````for(int iZ=0; iZ<nz; ++iZ){
for(int iX=0; iX<nx; ++iX){
lattice.get(iX, 0, iZ).defineExternalField(
DESCRIPTOR<T>::ExternalField::forceBeginsAt,
DESCRIPTOR<T>::ExternalField::sizeOfForce,
force);
lattice.get(iX, 0, iZ).defineRhoU((T)1, vel);
lattice.get(iX, 0, iZ).iniEquilibrium((T)1, vel);
}
}

for(int iZ=0; iZ<nz; ++iZ){
for(int iX=0; iX<nx; ++iX){
lattice.get(iX, nz-1, iZ).defineExternalField(
DESCRIPTOR<T>::ExternalField::forceBeginsAt,
DESCRIPTOR<T>::ExternalField::sizeOfForce,
force);
lattice.get(iX, ny-1, iZ).defineRhoU((T)1, vel);
lattice.get(iX, ny-1, iZ).iniEquilibrium((T)1, vel);
}
}

for(int iY=0; iY<ny; ++iY){
for(int iX=0; iX<nx; ++iX){
lattice.get(iX, iY, 0).defineExternalField(
DESCRIPTOR<T>::ExternalField::forceBeginsAt,
DESCRIPTOR<T>::ExternalField::sizeOfForce,
force);
lattice.get(iX, iY, 0).defineRhoU((T)1, vel);
lattice.get(iX, iY, 0).iniEquilibrium((T)1, vel);
}
}

for(int iY=0; iY<ny; ++iY){
for(int iX=0; iX<nx; ++iX){
lattice.get(iX, iY, nz-1).defineExternalField(
DESCRIPTOR<T>::ExternalField::forceBeginsAt,
DESCRIPTOR<T>::ExternalField::sizeOfForce,
force);
lattice.get(iX, iY, nz-1).defineRhoU((T)1, vel);
lattice.get(iX, iY, nz-1).iniEquilibrium((T)1, vel);
}
}

for(int iZ=0; iZ<nz; ++iZ){
for(int iY=0; iY<ny; ++iY){
lattice.get(0, iY, iZ).defineExternalField(
DESCRIPTOR<T>::ExternalField::forceBeginsAt,
DESCRIPTOR<T>::ExternalField::sizeOfForce,
force);
lattice.get(0, iY, iZ).defineRhoU((T)1, vel);
lattice.get(0, iY, iZ).iniEquilibrium((T)1, vel);
}
}

for(int iZ=0; iZ<nz; ++iZ){
for(int iY=0; iY<ny; ++iY){
lattice.get(nx-1, iY, iZ).defineExternalField(
DESCRIPTOR<T>::ExternalField::forceBeginsAt,
DESCRIPTOR<T>::ExternalField::sizeOfForce,
force);
lattice.get(nx-1, iY, iZ).defineRhoU((T)1, vel);
lattice.get(nx-1, iY, iZ).iniEquilibrium((T)1, vel);
}
}
lattice.initialize();
``````

}
Compilation of the code was successful. On running it, however, I got error messages.
I would appreciate if any mistake in the above definitions is pointed out to me.

Hi,
You need to find out at which line the code crashes. Here’s how to do:

1. Compile in debug mode
2. Type “gdb nameOfTheProgram”
3. Type “run”
4. After the program crashes, type “back” to get a history of the functional calls.

Hope this helps.

Hi,

After typing “gdb cavity3d”, I get

cavity3d: …/…/src/core/cell.h:271: void olb::Cell<T, Lattice>::defineExternalField(int, int, const T*) [with T = T, Lattice = olb::descriptors::ForcedD3Q19Descriptor]: Assertion `dynamics’ failed.

[Switching to Thread 182894189440 (LWP 2677)]
0x00000036e1e2e21d in raise () from /lib64/tls/libc.so.6

After typing “back”, I get

0 0x00000036e1e2e21d in raise () from /lib64/tls/libc.so.6
#1 0x00000036e1e2fa1e in abort () from /lib64/tls/libc.so.6
#2 0x00000036e1e27ae1 in __assert_fail () from /lib64/tls/libc.so.6
#3 0x00000000004079ef in olb::Cell<double, olb::descriptors::ForcedD3Q19Descriptor>::defineExternalField (this=0x2aa0c9fc90, pos=0, size=3, ext=0x7fbfffe6a0)
at …/…/src/core/cell.h:271
#4 0x0000000000452d2f in olb::ParallelDynamics<double, olb::descriptors::ForcedD3Q19Descriptor>::defineExternalField (this=0x6480b0, cell=@0x648278, pos=0,
size=3, ext=0x7fbfffe6a0)
at …/…/src/complexGrids/multiBlockStructure/parallelDynamics.hh:212
#5 0x0000000000407a30 in olb::Cell<double, olb::descriptors::ForcedD3Q19Descriptor>::defineExternalField (this=0x648278, pos=0, size=3, ext=0x7fbfffe6a0)
at …/…/src/core/cell.h:272
#6 0x000000000040599d in iniGeometry (lattice=@0x7fbfffea80,
converter=@0x7fbfffebf0, bulkDynamics=@0x7fbfffec20) at cavity3d.cpp:96
#7 0x0000000000406b38 in main (argc=1, argv=0x7fbfffed48) at cavity3d.cpp:244

Line 232 in cavity3d.cpp contains

``````iniGeometry(lattice, converter, bulkDynamics); There is no boundary condition defined in it because I am simulating with a periodic boundary on all side.
``````

While line 85 is an empty space but the preceding line contain
lattice.get(iX,iY,iZ).defineExternalField(
DESCRIPTOR::ExternalField::forceBeginsAt,
DESCRIPTOR::ExternalField::sizeOfForce,
force
);

Great, so here we’ve come quite a bit closer to the solution. Everything is in the line

``````
Assertion `dynamics' failed

``````

which means: you’re using a cell which has no dynamics object assigned to it. Cells are pretty much unable to perform any action before they have a dynamics object assigned to them. This object not only specifies the nature of the collision step on the cell, but also takes care of all other high-level interaction between a user and a cell.

A good practice is to start assigning BGK dynamics to all cells (like in the example programs), and possibly override some of them later on.

Thank you!!! Jonas,

I found out my mistake,…I think I found my mistake. I missed out the "lattice.defineDynamics(0, nx-1, 0, ny-1, 0, nz-1, &bulkDynamics)

Thanks for your help!!! I hope the simulation result turns out well,…