CombinedResolvedUnresolved.cpp 65.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
//======================================================================================================================
//
//  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 CombinedResolvedUnresolved.cpp
//! \author Matthias König <matthias.k.koenig@fau.de>
//
//======================================================================================================================

#include "blockforest/Initialization.h"
#include "blockforest/communication/UniformBufferedScheme.h"

#include "boundary/all.h"

#include "core/DataTypes.h"
#include "core/Environment.h"
#include "core/SharedFunctor.h"
#include "core/debug/Debug.h"
#include "core/debug/TestSubsystem.h"
#include "core/grid_generator/SCIterator.h"
#include "core/logging/all.h"
#include "core/math/all.h"
#include "core/timing/RemainingTimeLogger.h"

#include "domain_decomposition/SharedSweep.h"

#include "field/AddToStorage.h"
#include "field/StabilityChecker.h"
#include "field/communication/PackInfo.h"
#include "field/vtk/all.h"

#include "lbm/boundary/all.h"
#include "lbm/communication/PdfFieldPackInfo.h"
#include "lbm/field/AddToStorage.h"
#include "lbm/field/PdfField.h"
#include "lbm/lattice_model/D3Q19.h"
#include "lbm/sweeps/CellwiseSweep.h"
#include "lbm/sweeps/SweepWrappers.h"
#include "lbm/vtk/all.h"

#include "pe/Types.h"
#include "pe/basic.h"
#include "pe/cr/ICR.h"
#include "pe/vtk/BodyVtkOutput.h"
#include "pe/vtk/SphereVtkOutput.h"

#include "pe_coupling/discrete_particle_methods/all.h"
#include "pe_coupling/mapping/all.h"
#include "pe_coupling/momentum_exchange_method/all.h"
#include "pe_coupling/utility/all.h"

#include "timeloop/SweepTimeloop.h"

#include "vtk/all.h"

#include <functional>

namespace combined_resolved_unresolved
{
///////////
// USING //
///////////

using namespace walberla;
using walberla::uint_t;

//////////////
// TYPEDEFS //
//////////////

// PDF field, flag field & body field

typedef GhostLayerField< pe::BodyID, 1 > BodyField_T;
typedef GhostLayerField< Matrix3< real_t >, 1 > TensorField_T;
typedef GhostLayerField< Vector3< real_t >, 1 > Vec3Field_T;
typedef GhostLayerField< real_t, 1 > ScalarField_T;
using ForceModel_T = lbm::force_model::GuoField< Vec3Field_T >;

typedef lbm::D3Q19< lbm::collision_model::SRTField< ScalarField_T >, false, ForceModel_T > LatticeModel_T;
using Stencil_T  = LatticeModel_T::Stencil;
using PdfField_T = lbm::PdfField< LatticeModel_T >;

using flag_t      = walberla::uint8_t;
using FlagField_T = FlagField< flag_t >;

const uint_t FieldGhostLayers = 1;

// boundary handling
typedef lbm::NoSlip< LatticeModel_T, flag_t > NoSlip_T;

typedef pe_coupling::CurvedLinear< LatticeModel_T, FlagField_T > MO_T;

typedef BoundaryHandling< FlagField_T, Stencil_T, NoSlip_T, MO_T > BoundaryHandling_T;

typedef std::tuple< pe::Sphere, pe::Plane > BodyTypeTuple;

///////////
// FLAGS //
///////////

const FlagUID Fluid_Flag("fluid");
const FlagUID NoSlip_Flag("no slip");
const FlagUID MO_Flag("moving obstacle");
const FlagUID FormerMO_Flag("former moving obstacle");

// interpolation (for PDFs, velocity and/or solid volume fraction)
enum Interpolation { INearestNeighbor, IKernel };

// force distribution
enum Distribution { DNearestNeighbor, DKernel };

// drag correlation
enum DragCorrelation { ErgunWenYu, Tang, Stokes, Felice, Tenneti, NoDrag };

// lift correlation
enum LiftCorrelation { NoLift, Saffman };

// added mass correlation
enum AddedMassCorrelation { NoAM, Finn };

// effective viscosity
enum EffectiveViscosity { None, Rescaled, Eilers };

/////////////////////////////////////
// BOUNDARY HANDLING CUSTOMIZATION //
/////////////////////////////////////
class MyBoundaryHandling
{
 public:
   MyBoundaryHandling(const BlockDataID& flagFieldID, const BlockDataID& pdfFieldID, const BlockDataID& bodyFieldID)
      : flagFieldID_(flagFieldID), pdfFieldID_(pdfFieldID), bodyFieldID_(bodyFieldID)
   {}

   BoundaryHandling_T* operator()(IBlock* const block, const StructuredBlockStorage* const storage) const;

 private:
   const BlockDataID flagFieldID_;
   const BlockDataID pdfFieldID_;
   const BlockDataID bodyFieldID_;

}; // class MyBoundaryHandling

BoundaryHandling_T* MyBoundaryHandling::operator()(IBlock* const block,
                                                   const StructuredBlockStorage* const storage) const
{
   WALBERLA_ASSERT_NOT_NULLPTR(block);
   WALBERLA_ASSERT_NOT_NULLPTR(storage);

   FlagField_T* flagField = block->getData< FlagField_T >(flagFieldID_);
   PdfField_T* pdfField   = block->getData< PdfField_T >(pdfFieldID_);
   BodyField_T* bodyField = block->getData< BodyField_T >(bodyFieldID_);

   const auto fluid =
      flagField->flagExists(Fluid_Flag) ? flagField->getFlag(Fluid_Flag) : flagField->registerFlag(Fluid_Flag);

   BoundaryHandling_T* handling = new BoundaryHandling_T(
      "moving obstacle boundary handling", flagField, fluid, NoSlip_T("NoSlip", NoSlip_Flag, pdfField),
      MO_T("MO", MO_Flag, pdfField, flagField, bodyField, fluid, *storage, *block));

   // boundary conditions (no-slip) are set by mapping the planes into the domain

   handling->fillWithDomain(FieldGhostLayers);

   return handling;
}

// VTK Output
shared_ptr< vtk::VTKOutput > createFluidFieldVTKWriter(shared_ptr< StructuredBlockForest >& blocks,
                                                       const BlockDataID& pdfFieldID, const BlockDataID& flagFieldID,
                                                       uint_t writeFrequency, const std::string& vtkBaseFolder)
{
   auto pdfFieldVTKWriter =
      vtk::createVTKOutput_BlockData(blocks, "fluid_field", writeFrequency, uint_t(1), false, vtkBaseFolder);

   blockforest::communication::UniformBufferedScheme< stencil::D3Q27 > pdfGhostLayerSync(blocks);
   pdfGhostLayerSync.addPackInfo(make_shared< field::communication::PackInfo< PdfField_T > >(pdfFieldID));
   pdfFieldVTKWriter->addBeforeFunction(pdfGhostLayerSync);

   field::FlagFieldCellFilter< FlagField_T > fluidFilter(flagFieldID);
   fluidFilter.addFlag(Fluid_Flag);
   pdfFieldVTKWriter->addCellInclusionFilter(fluidFilter);

   auto velocityWriter =
      make_shared< lbm::VelocityVTKWriter< LatticeModel_T, float > >(pdfFieldID, "Velocity (Lattice)");
   auto densityWriter = make_shared< lbm::DensityVTKWriter< LatticeModel_T, float > >(pdfFieldID, "Density (Lattice)");
   pdfFieldVTKWriter->addCellDataWriter(velocityWriter);
   pdfFieldVTKWriter->addCellDataWriter(densityWriter);

   return pdfFieldVTKWriter;
}

void createSphereLattice(StructuredBlockForest& forest, pe::BodyStorage& globalBodyStorage,
                         const BlockDataID& bodyStorageID, const AABB& generationDomain, real_t diameter,
                         real_t solidVolumeFraction, const pe::MaterialID& material, real_t initialZVelocity)
{
   real_t sphereVolume        = math::pi * diameter * diameter * diameter / real_t(6);
   real_t numSpheresDesired   = solidVolumeFraction * generationDomain.volume() / sphereVolume;
   uint_t spheresPerDirection = uint_c(std::cbrt(numSpheresDesired));

   real_t spacing = generationDomain.xSize() / real_c(spheresPerDirection);

   WALBERLA_ASSERT(spacing >= diameter);

   Vector3< real_t > generationOrigin(generationDomain.xMin() + spacing * real_t(0.5),
                                      generationDomain.yMin() + spacing * real_t(0.5),
                                      generationDomain.zMin() + spacing * real_t(0.5));

   uint_t numSpheres(0);

   for (auto it = grid_generator::SCIterator(generationDomain, generationOrigin, spacing);
        it != grid_generator::SCIterator(); ++it)
   {
      pe::SphereID sp = pe::createSphere(globalBodyStorage, forest.getBlockStorage(), bodyStorageID, 0, *it,
                                         diameter * real_t(0.5), material);

      if (sp != nullptr)
      {
         sp->setLinearVel(Vector3< real_t >(real_t(0), real_t(0), initialZVelocity));
         ++numSpheres;
      }
   }

   WALBERLA_MPI_SECTION() { mpi::allReduceInplace(numSpheres, mpi::SUM); }

   WALBERLA_LOG_INFO_ON_ROOT("Created " << numSpheres << " spheres of diameter " << diameter << " in "
                                        << generationDomain << " with a center-to-center spacing of " << spacing
                                        << " ( " << real_t(100) * spacing / diameter << "% of diameter )");
}

pe::MaterialID createSphereMaterial(const std::string& name, real_t diameter, real_t densityRatio)
{
   const real_t restitutionCoeff = real_t(0.88);
   const real_t frictionCoeff    = real_t(0.25);

   real_t sphereVolume        = diameter * diameter * diameter * math::pi / real_t(6);
   const real_t particleMass  = densityRatio * sphereVolume;
   const real_t Mij           = particleMass * particleMass / (real_t(2) * particleMass);
   const real_t lnDryResCoeff = std::log(restitutionCoeff);
   const real_t collisionTime = real_t(10.0);
   const real_t stiffnessCoeff =
      math::pi * math::pi * Mij /
      (collisionTime * collisionTime *
       (real_t(1) - lnDryResCoeff * lnDryResCoeff / (math::pi * math::pi + lnDryResCoeff * lnDryResCoeff)));
   const real_t dampingCoeff =
      -real_t(2) * std::sqrt(Mij * stiffnessCoeff) *
      (std::log(restitutionCoeff) /
       std::sqrt(math::pi * math::pi + (std::log(restitutionCoeff) * std::log(restitutionCoeff))));

   return pe::createMaterial(name, densityRatio, restitutionCoeff, frictionCoeff, frictionCoeff, real_t(0), real_t(200),
                             stiffnessCoeff, dampingCoeff, dampingCoeff);
}

bool selectDPMBodies(pe::BodyID bodyID)
{
   pe::SphereID sphere = static_cast< pe::SphereID >(bodyID);
   real_t radius       = sphere->getRadius();
Sebastian Eibl's avatar
Sebastian Eibl committed
268
   return radius <= real_t(0.5);
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
}

bool selectMEMBodies(pe::BodyID bodyID) { return !selectDPMBodies(bodyID); }

void resetSphereVelocities(const shared_ptr< StructuredBlockForest >& blocks, const BlockDataID& bodyStorageID,
                           Vector3< real_t > vel)
{
   for (auto blockIt = blocks->begin(); blockIt != blocks->end(); ++blockIt)
   {
      for (auto bodyIt = pe::BodyIterator::begin< pe::Sphere >(*blockIt, bodyStorageID);
           bodyIt != pe::BodyIterator::end< pe::Sphere >(); ++bodyIt)
      {
         bodyIt->setAngularVel(real_t(0), real_t(0), real_t(0));
         bodyIt->setLinearVel(vel);
      }
   }
}

class DummySweep
{
 public:
   DummySweep() = default;

   void operator()(IBlock* const /*block*/) {}
};

void emptyFunction() {}

//*******************************************************************************************************************
/*!\brief Simualtion of a strongly heterogeneous sized particulate flow system using combined resolved and unresolved
 * methods.
 *
 * For the coupling of resolved particles the Momentum Exchange Method (MEM) is used, whereas for the
 * unresolved particles the Discrete Particle Method by Rettinger, Ruede - "A Coupled Lattice Boltzmann Method and
 * Discrete Element Method for Discrete Particle Simulations of Particulate Flows" is used.
 *
 * For the default setup of the showcase a 100 × 100 × 100mm box is filled with a viscous fluid.
 * The domain is resolved by a 32 × 32 × 32 lattice. One large MEM particle of diameter Dp_MEM = 35mm
 * - which equates to a resolution of 12 lattice cells - is dropped from a gap height of 37.5mm. There
 * is a layer 4096 DPM spheres of diameter Dp_DPM = 1mm from height 12.5mm to 25mm which
 * generates an average solid volume fraction of svf = 0.017 inside the layer. DPM particles thus have
 * a diameter of Dp_DPM = 0.32 cells in lattice units. For the evaluation of forces and fluid properties
 * by the DPM part of the algorithm 10 interaction subcycles are used.
 * This setup can be customized in the customization section.
 *
 * The algorithm, as well as the setup and the outcome are described in detail in
 * Koenig - "Combining fully resolved and unresolved coupling methods for strongly heterogeneous sized particulate
 * flow simulations" to be published
 *
 */
//*******************************************************************************************************************

int main(int argc, char** argv)
{
   debug::enterTestMode();

   mpi::Environment env(argc, argv);

   ///////////////////
   // Customization //
   ///////////////////

   // simulation control
   uint_t vtkIOFreq           = 0;
   std::string baseFolder_vtk = "vtk_out_Combined";

   // physical setup
   uint_t fluidType = 1;

   uint_t timesteps            = uint_t(5000);
   uint_t interactionSubcycles = uint_t(10);

   Interpolation interpol             = Interpolation::IKernel;
   Distribution dist                  = Distribution::DKernel;
   DragCorrelation dragCorr           = DragCorrelation::Tenneti;
   LiftCorrelation liftCorr           = LiftCorrelation::Saffman;
   AddedMassCorrelation addedMassCorr = AddedMassCorrelation::Finn;
   EffectiveViscosity effVisc         = EffectiveViscosity::Eilers;

   // numerical parameters
   uint_t numberOfCellsInHorizontalDirection = uint_t(32);

   for (int i = 1; i < argc; ++i)
   {
      if (std::strcmp(argv[i], "--vtkIOFreq") == 0)
      {
         vtkIOFreq = uint_c(std::atof(argv[++i]));
         continue;
      }
      if (std::strcmp(argv[i], "--fluidType") == 0)
      {
         fluidType = uint_c(std::atof(argv[++i]));
         continue;
      }
      if (std::strcmp(argv[i], "--resolution") == 0)
      {
         numberOfCellsInHorizontalDirection = uint_c(std::atof(argv[++i]));
         continue;
      }
      if (std::strcmp(argv[i], "--baseFolder_vtk") == 0)
      {
         baseFolder_vtk = argv[++i];
         continue;
      }
      if (std::strcmp(argv[i], "--timesteps") == 0)
      {
         timesteps = uint_c(std::atof(argv[++i]));
         continue;
      }
      if (std::strcmp(argv[i], "--interactionSubcycles") == 0)
      {
         interactionSubcycles = uint_c(std::atof(argv[++i]));
         continue;
      }
      WALBERLA_ABORT("Unrecognized command line argument found: " << argv[i]);
   }

   //////////////////////////////////////
   // SIMULATION PROPERTIES in SI units//
   //////////////////////////////////////

   real_t densityFluid_SI;
   real_t dynamicViscosityFluid_SI;
   real_t expectedSettlingVelocity_SI;
   switch (fluidType)
   {
   case 1:
      // Re_p around 1.5
      densityFluid_SI             = real_t(970);
      dynamicViscosityFluid_SI    = real_t(373e-3);
      expectedSettlingVelocity_SI = real_t(0.035986);
      break;
   case 2:
      // Re_p around 4.1
      densityFluid_SI             = real_t(965);
      dynamicViscosityFluid_SI    = real_t(212e-3);
      expectedSettlingVelocity_SI = real_t(0.05718);
      break;
   case 3:
      // Re_p around 11.6
      densityFluid_SI             = real_t(962);
      dynamicViscosityFluid_SI    = real_t(113e-3);
      expectedSettlingVelocity_SI = real_t(0.087269);
      break;
   case 4:
      // Re_p around 31.9
      densityFluid_SI             = real_t(960);
      dynamicViscosityFluid_SI    = real_t(58e-3);
      expectedSettlingVelocity_SI = real_t(0.12224);
      break;
   default:
      WALBERLA_ABORT("Only four different fluids are supported! Choose type between 1 and 4.");
   }
   const real_t kinematicViscosityFluid_SI = dynamicViscosityFluid_SI / densityFluid_SI;

   const real_t diameter_MEM_SI      = real_t(35e-3);
   const real_t densitySphere_MEM_SI = real_t(1120);
   const real_t densityRatio_MEM     = densitySphere_MEM_SI / densityFluid_SI;

   const real_t diameter_DPM_SI      = real_t(1e-3);
   const real_t densitySphere_DPM_SI = real_t(1120);
   const real_t densityRatio_DPM     = densitySphere_DPM_SI / densityFluid_SI;

   const real_t gravitationalAcceleration_SI = real_t(9.81);
   Vector3< real_t > domainSize_SI(real_t(100e-3), real_t(100e-3), real_t(100e-3));
   // shift starting gap a bit upwards to match the reported (plotted) values
   const real_t startingGapSize_SI = real_t(20e-3) + real_t(0.5) * diameter_MEM_SI;

   WALBERLA_LOG_INFO_ON_ROOT("Setup (in SI units):");
   WALBERLA_LOG_INFO_ON_ROOT(" - domain size = " << domainSize_SI);
   WALBERLA_LOG_INFO_ON_ROOT(" - sphere: diameter_MEM = " << diameter_MEM_SI << ", density = " << densitySphere_MEM_SI
                                                          << ", starting gap size = " << startingGapSize_SI);
   WALBERLA_LOG_INFO_ON_ROOT(" - fluid: density = " << densityFluid_SI << ", dyn. visc = " << dynamicViscosityFluid_SI
                                                    << ", kin. visc = " << kinematicViscosityFluid_SI);
   WALBERLA_LOG_INFO_ON_ROOT(" - expected settling velocity = "
                             << expectedSettlingVelocity_SI << " --> Re_p = "
                             << expectedSettlingVelocity_SI * diameter_MEM_SI / kinematicViscosityFluid_SI);

   //////////////////////////
   // NUMERICAL PARAMETERS //
   //////////////////////////

   const real_t dx_SI = domainSize_SI[0] / real_c(numberOfCellsInHorizontalDirection);
   const Vector3< uint_t > domainSize(uint_c(floor(domainSize_SI[0] / dx_SI + real_t(0.5))),
                                      uint_c(floor(domainSize_SI[1] / dx_SI + real_t(0.5))),
                                      uint_c(floor(domainSize_SI[2] / dx_SI + real_t(0.5))));
   const real_t diameter_MEM     = diameter_MEM_SI / dx_SI;
   const real_t sphereVolume_MEM = math::pi / real_t(6) * diameter_MEM * diameter_MEM * diameter_MEM;

   const real_t diameter_DPM = diameter_DPM_SI / dx_SI;

   const real_t sphereVolume_DPM = math::pi / real_t(6) * diameter_DPM * diameter_DPM * diameter_DPM;

   const real_t expectedSettlingVelocity = real_t(0.01);
   const real_t dt_SI                    = expectedSettlingVelocity / expectedSettlingVelocity_SI * dx_SI;

   const real_t viscosity      = kinematicViscosityFluid_SI * dt_SI / (dx_SI * dx_SI);
   const real_t relaxationTime = real_t(1) / lbm::collision_model::omegaFromViscosity(viscosity);

   const real_t gravitationalAcceleration = gravitationalAcceleration_SI * dt_SI * dt_SI / dx_SI;

   const real_t dx                                     = real_t(1);
   const real_t dt                                     = real_t(1);
   const real_t dtInteractionSubCycle                  = real_t(dt) / real_t(interactionSubcycles);
   const real_t dtBodyVelocityTimeDerivativeEvaluation = dtInteractionSubCycle;

   const Vector3< real_t > initialFluidVelocity(real_t(0));

   const uint_t numPeSubCycles = uint_t(1);

   WALBERLA_LOG_INFO_ON_ROOT(" - dx_SI = " << dx_SI << ", dt_SI = " << dt_SI);
   WALBERLA_LOG_INFO_ON_ROOT("Setup (in simulation, i.e. lattice, units):");
   WALBERLA_LOG_INFO_ON_ROOT(" - domain size = " << domainSize);
   WALBERLA_LOG_INFO_ON_ROOT(" - sphere: diameter_MEM = " << diameter_MEM);
   WALBERLA_LOG_INFO_ON_ROOT(" - relaxation time (tau) = " << relaxationTime << ", kin. visc = " << viscosity);
   WALBERLA_LOG_INFO_ON_ROOT(" - gravitational acceleration = " << gravitationalAcceleration);
   WALBERLA_LOG_INFO_ON_ROOT(" - expected settling velocity = " << expectedSettlingVelocity << " --> Re_p = "
                                                                << expectedSettlingVelocity * diameter_MEM / viscosity);

   if (vtkIOFreq > 0)
   {
      WALBERLA_LOG_INFO_ON_ROOT(" - writing vtk files to folder \"" << baseFolder_vtk << "\" with frequency "
                                                                    << vtkIOFreq);
   }

   ///////////////////////////
   // BLOCK STRUCTURE SETUP //
   ///////////////////////////

   Vector3< uint_t > numberOfBlocksPerDirection(uint_t(2), uint_t(2), uint_t(2));
   Vector3< uint_t > cellsPerBlockPerDirection(domainSize[0] / numberOfBlocksPerDirection[0],
                                               domainSize[1] / numberOfBlocksPerDirection[1],
                                               domainSize[2] / numberOfBlocksPerDirection[2]);
   for (uint_t i = 0; i < 3; ++i)
   {
      WALBERLA_CHECK_EQUAL(cellsPerBlockPerDirection[i] * numberOfBlocksPerDirection[i], domainSize[i],
                           "Unmatching domain decomposition in direction " << i << "!");
   }

   auto blocks = blockforest::createUniformBlockGrid(numberOfBlocksPerDirection[0], numberOfBlocksPerDirection[1],
                                                     numberOfBlocksPerDirection[2], cellsPerBlockPerDirection[0],
                                                     cellsPerBlockPerDirection[1], cellsPerBlockPerDirection[2], dx, 0,
                                                     false, false, false, false, false, // periodicity
                                                     false);

   WALBERLA_LOG_INFO_ON_ROOT("Domain decomposition:");
   WALBERLA_LOG_INFO_ON_ROOT(" - blocks per direction = " << numberOfBlocksPerDirection);
   WALBERLA_LOG_INFO_ON_ROOT(" - cells per block = " << cellsPerBlockPerDirection);

   // write domain decomposition to file
   if (vtkIOFreq > 0) { vtk::writeDomainDecomposition(blocks, "initial_domain_decomposition", baseFolder_vtk); }

   /////////////////
   // PE COUPLING //
   /////////////////

   // set up pe functionality
   shared_ptr< pe::BodyStorage > globalBodyStorage = make_shared< pe::BodyStorage >();
   pe::SetBodyTypeIDs< BodyTypeTuple >::execute();

   auto bodyStorageID = blocks->addBlockData(pe::createStorageDataHandling< BodyTypeTuple >(), "pe Body Storage");
   auto ccdID = blocks->addBlockData(pe::ccd::createHashGridsDataHandling(globalBodyStorage, bodyStorageID), "CCD");
   auto fcdID = blocks->addBlockData(
      pe::fcd::createGenericFCDDataHandling< BodyTypeTuple, pe::fcd::AnalyticCollideFunctor >(), "FCD");

   // set up collision response, here DEM solver
   pe::cr::DEM cr(globalBodyStorage, blocks->getBlockStoragePointer(), bodyStorageID, ccdID, fcdID, nullptr);

   // set up synchronization procedure
   const real_t overlap = real_t(1.5) * dx;
   std::function< void(void) > syncCall =
      std::bind(pe::syncShadowOwners< BodyTypeTuple >, std::ref(blocks->getBlockForest()), bodyStorageID,
                static_cast< WcTimingTree* >(nullptr), overlap, false);

   // create pe bodies

   // bounding planes (global)
546
   const auto planeMaterial = pe::createMaterial("planeMaterial", 1000_r, 0.8_r, 0.1_r, 0.05_r, 0.2_r, 80_r, 100_r, 10_r, 11_r);
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
   pe::createPlane(*globalBodyStorage, 0, Vector3< real_t >(1, 0, 0), Vector3< real_t >(0, 0, 0), planeMaterial);
   pe::createPlane(*globalBodyStorage, 0, Vector3< real_t >(-1, 0, 0), Vector3< real_t >(real_c(domainSize[0]), 0, 0),
                   planeMaterial);
   pe::createPlane(*globalBodyStorage, 0, Vector3< real_t >(0, 1, 0), Vector3< real_t >(0, 0, 0), planeMaterial);
   pe::createPlane(*globalBodyStorage, 0, Vector3< real_t >(0, -1, 0), Vector3< real_t >(0, real_c(domainSize[1]), 0),
                   planeMaterial);
   pe::createPlane(*globalBodyStorage, 0, Vector3< real_t >(0, 0, 1), Vector3< real_t >(0, 0, 0), planeMaterial);
   pe::createPlane(*globalBodyStorage, 0, Vector3< real_t >(0, 0, -1), Vector3< real_t >(0, 0, real_c(domainSize[2])),
                   planeMaterial);

   // add the MEM sphere
   const auto peMaterial_MEM = createSphereMaterial("peMaterial_MEM", diameter_MEM, densityRatio_MEM);
   Vector3< real_t > initialPosition(real_t(0.5) * real_c(domainSize[0]), real_t(0.5) * real_c(domainSize[1]),
                                     startingGapSize_SI / dx_SI + real_t(0.5) * diameter_MEM);
   pe::createSphere(*globalBodyStorage, blocks->getBlockStorage(), bodyStorageID, 0, initialPosition,
                    real_t(0.5) * diameter_MEM, peMaterial_MEM);

   // add DPM spheres
   const auto peMaterial_DPM = createSphereMaterial("peMaterial_DPM", diameter_DPM, densityRatio_DPM);
   createSphereLattice(*blocks, *globalBodyStorage, bodyStorageID,
567
568
                       AABB(real_t(0), real_t(0), real_t(1.0 * real_t(domainSize[2]) / 8.0_r), real_t(domainSize[0]),
                            real_t(domainSize[1]), real_t(2.0 * real_t(domainSize[2]) / 8.0_r)),
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
                       diameter_DPM, real_t(0.15), peMaterial_DPM, real_t(0));

   syncCall();

   ///////////////////////
   // ADD DATA TO BLOCKS //
   ////////////////////////

   // create force field
   BlockDataID forceFieldID = field::addToStorage< Vec3Field_T >(blocks, "force field", Vector3< real_t >(real_t(0)),
                                                                 field::zyxf, FieldGhostLayers);

   // create omega field
   BlockDataID omegaFieldID =
      field::addToStorage< ScalarField_T >(blocks, "omega field", real_t(0), field::zyxf, FieldGhostLayers);

   // create the lattice model
   LatticeModel_T latticeModel = LatticeModel_T(omegaFieldID, ForceModel_T(forceFieldID));

   // add PDF field
   BlockDataID pdfFieldID = lbm::addPdfFieldToStorage< LatticeModel_T >(
      blocks, "pdf field (zyxf)", latticeModel, Vector3< real_t >(real_t(0)), real_t(1), uint_t(1), field::zyxf);
   // add flag field
   BlockDataID flagFieldID = field::addFlagFieldToStorage< FlagField_T >(blocks, "flag field");

   // add body field
   BlockDataID bodyFieldID = field::addToStorage< BodyField_T >(blocks, "body field", nullptr, field::zyxf);

   // add boundary handling
   BlockDataID boundaryHandlingID = blocks->addStructuredBlockData< BoundaryHandling_T >(
      MyBoundaryHandling(flagFieldID, pdfFieldID, bodyFieldID), "boundary handling");

   // field to store fluid velolcity
   BlockDataID velocityFieldID =
      field::addToStorage< Vec3Field_T >(blocks, "velocity field", initialFluidVelocity, field::zyxf, FieldGhostLayers);

   BlockDataID oldVelocityFieldID = field::addToStorage< Vec3Field_T >(
      blocks, "old velocity field", initialFluidVelocity, field::zyxf, FieldGhostLayers);
   BlockDataID swappedOldVelocityFieldID = field::addToStorage< Vec3Field_T >(
      blocks, "swapped old velocity field", initialFluidVelocity, field::zyxf, FieldGhostLayers);

   // field to store curl of fluid velocity
   BlockDataID velocityCurlFieldID = field::addToStorage< Vec3Field_T >(
      blocks, "velocity curl field", Vector3< real_t >(real_c(0)), field::zyxf, FieldGhostLayers);

   // field to store velocity gradient
   BlockDataID velocityGradientFieldID = field::addToStorage< TensorField_T >(
      blocks, "velocity gradient field", Matrix3< real_t >(real_c(0)), field::zyxf, FieldGhostLayers);

   // field to store time derivative of fluid velocity
   BlockDataID timeDerivativeVelocityFieldID = field::addToStorage< Vec3Field_T >(
      blocks, "time derivative velocity field", Vector3< real_t >(real_c(0)), field::zyxf, FieldGhostLayers);

   // create solid volume fraction field
   BlockDataID svfFieldID =
      field::addToStorage< ScalarField_T >(blocks, "svf field", real_t(0), field::zyxf, FieldGhostLayers);

   // create pressure field
   BlockDataID pressureFieldID =
      field::addToStorage< ScalarField_T >(blocks, "pressure field", real_t(0), field::zyxf, FieldGhostLayers);

   // field to store pressure gradient
   BlockDataID pressureGradientFieldID = field::addToStorage< Vec3Field_T >(
      blocks, "pressure gradient field", Vector3< real_t >(real_c(0)), field::zyxf, FieldGhostLayers);

   BlockDataID dragForceFieldID = field::addToStorage< Vec3Field_T >(
      blocks, "drag force field", Vector3< real_t >(real_t(0)), field::zyxf, FieldGhostLayers);

   BlockDataID amForceFieldID = field::addToStorage< Vec3Field_T >(
      blocks, "am force field", Vector3< real_t >(real_t(0)), field::zyxf, FieldGhostLayers);
   BlockDataID liftForceFieldID = field::addToStorage< Vec3Field_T >(
      blocks, "lift force field", Vector3< real_t >(real_t(0)), field::zyxf, FieldGhostLayers);

   // map planes into the LBM simulation -> act as no-slip boundaries
   pe_coupling::mapBodies< BoundaryHandling_T >(*blocks, boundaryHandlingID, bodyStorageID, *globalBodyStorage,
                                                NoSlip_Flag, pe_coupling::selectGlobalBodies);

   // map pe bodies into the LBM simulation
   pe_coupling::mapMovingBodies< BoundaryHandling_T >(*blocks, boundaryHandlingID, bodyStorageID, *globalBodyStorage,
                                                      bodyFieldID, MO_Flag, selectMEMBodies);

   // communication for synchronizing the interaction force field
   pe_coupling::discrete_particle_methods::CombinedReductionFieldCommunication< Vec3Field_T > dragForceComm(
      blocks, dragForceFieldID);

   pe_coupling::discrete_particle_methods::CombinedReductionFieldCommunication< Vec3Field_T > amForceComm(
      blocks, amForceFieldID);
   pe_coupling::discrete_particle_methods::CombinedReductionFieldCommunication< Vec3Field_T > liftForceComm(
      blocks, liftForceFieldID);

   blockforest::communication::UniformBufferedScheme< stencil::D3Q27 > pdfScheme(blocks);
   pdfScheme.addPackInfo(make_shared< field::communication::PackInfo< PdfField_T > >(pdfFieldID));

   shared_ptr< blockforest::communication::UniformBufferedScheme< stencil::D3Q27 > > velocityCommunicationScheme =
      make_shared< blockforest::communication::UniformBufferedScheme< stencil::D3Q27 > >(blocks);
   velocityCommunicationScheme->addPackInfo(
      make_shared< field::communication::PackInfo< Vec3Field_T > >(velocityFieldID));

   shared_ptr< blockforest::communication::UniformBufferedScheme< stencil::D3Q27 > > oldVelocityCommunicationScheme =
      make_shared< blockforest::communication::UniformBufferedScheme< stencil::D3Q27 > >(blocks);
   oldVelocityCommunicationScheme->addPackInfo(
      make_shared< field::communication::PackInfo< Vec3Field_T > >(oldVelocityFieldID));

   // setup of the communication for synchronizing the solid volume fraction field between neighboring blocks which
   // takes into account the svf values inside the ghost layers
   shared_ptr< pe_coupling::discrete_particle_methods::CombinedReductionFieldCommunication< ScalarField_T > >
      svfCommunicationScheme =
         make_shared< pe_coupling::discrete_particle_methods::CombinedReductionFieldCommunication< ScalarField_T > >(
            blocks, svfFieldID);

   // setup of the communication for synchronizing the pressure field between neighboring blocks
   shared_ptr< blockforest::communication::UniformBufferedScheme< stencil::D3Q27 > > pressureCommunicationScheme =
      make_shared< blockforest::communication::UniformBufferedScheme< stencil::D3Q27 > >(blocks);
   pressureCommunicationScheme->addPackInfo(
      make_shared< field::communication::PackInfo< ScalarField_T > >(pressureFieldID));

   // setup of the communication for synchronizing the pressure gradient field between neighboring blocks
   shared_ptr< blockforest::communication::UniformBufferedScheme< stencil::D3Q27 > >
      pressureGradientCommunicationScheme =
         make_shared< blockforest::communication::UniformBufferedScheme< stencil::D3Q27 > >(blocks);
   pressureGradientCommunicationScheme->addPackInfo(
      make_shared< field::communication::PackInfo< Vec3Field_T > >(pressureGradientFieldID));

   // setup of the communication for synchronizing the velocity curl field between neighboring blocks
   shared_ptr< blockforest::communication::UniformBufferedScheme< stencil::D3Q27 > > velocityCurlCommunicationScheme =
      make_shared< blockforest::communication::UniformBufferedScheme< stencil::D3Q27 > >(blocks);
   velocityCurlCommunicationScheme->addPackInfo(
      make_shared< field::communication::PackInfo< Vec3Field_T > >(velocityCurlFieldID));

   // communication for synchronizing the velocity gradient values
   shared_ptr< blockforest::communication::UniformBufferedScheme< stencil::D3Q27 > >
      velocityGradientCommunicationScheme =
         make_shared< blockforest::communication::UniformBufferedScheme< stencil::D3Q27 > >(blocks);
   velocityGradientCommunicationScheme->addPackInfo(
      make_shared< field::communication::PackInfo< TensorField_T > >(velocityGradientFieldID));

   shared_ptr< pe_coupling::discrete_particle_methods::AveragedInteractionForceFieldToForceFieldAdder >
      dragForceFieldToForceFieldAdder =
         make_shared< pe_coupling::discrete_particle_methods::AveragedInteractionForceFieldToForceFieldAdder >(
            blocks, forceFieldID, dragForceFieldID, uint_t(1));
   shared_ptr< pe_coupling::discrete_particle_methods::AveragedInteractionForceFieldToForceFieldAdder >
      amForceFieldToForceFieldAdder =
         make_shared< pe_coupling::discrete_particle_methods::AveragedInteractionForceFieldToForceFieldAdder >(
            blocks, forceFieldID, amForceFieldID, uint_t(1));
   shared_ptr< pe_coupling::discrete_particle_methods::AveragedInteractionForceFieldToForceFieldAdder >
      liftForceFieldToForceFieldAdder =
         make_shared< pe_coupling::discrete_particle_methods::AveragedInteractionForceFieldToForceFieldAdder >(
            blocks, forceFieldID, liftForceFieldID, uint_t(1));

   /////////////////////////////////
   //                             //
   //    CORRELATION FUNCTIONS    //
   //                             //
   /////////////////////////////////

   // drag correlation function
   std::function< Vector3< real_t >(const Vector3< real_t >&, const Vector3< real_t >&, real_t, real_t, real_t,
                                    real_t) >
      dragCorrelationFunction;
   if (dragCorr == DragCorrelation::ErgunWenYu)
   { dragCorrelationFunction = pe_coupling::discrete_particle_methods::dragForceErgunWenYu; }
   else if (dragCorr == DragCorrelation::Tang)
   {
      dragCorrelationFunction = pe_coupling::discrete_particle_methods::dragForceTang;
   }
   else if (dragCorr == DragCorrelation::Stokes)
   {
      dragCorrelationFunction = pe_coupling::discrete_particle_methods::dragForceStokes;
   }
   else if (dragCorr == DragCorrelation::Felice)
   {
      dragCorrelationFunction = pe_coupling::discrete_particle_methods::dragForceFelice;
   }
   else if (dragCorr == DragCorrelation::Tenneti)
   {
      dragCorrelationFunction = pe_coupling::discrete_particle_methods::dragForceTenneti;
   }
   else if (dragCorr == DragCorrelation::NoDrag)
   {
      dragCorrelationFunction = pe_coupling::discrete_particle_methods::noDragForce;
   }
   else
   {
      WALBERLA_ABORT("Drag correlation not yet implemented!");
   }

   // lift correlation function
   std::function< Vector3< real_t >(const Vector3< real_t >&, const Vector3< real_t >&, const Vector3< real_t >&,
                                    real_t, real_t, real_t) >
      liftCorrelationFunction;
   if (liftCorr == LiftCorrelation::NoLift)
   { liftCorrelationFunction = pe_coupling::discrete_particle_methods::noLiftForce; }
   else if (liftCorr == LiftCorrelation::Saffman)
   {
      liftCorrelationFunction = pe_coupling::discrete_particle_methods::liftForceSaffman;
   }
   else
   {
      WALBERLA_ABORT("Lift correlation not yet implemented!");
   }

   // added mass correlation function
   std::function< Vector3< real_t >(const Vector3< real_t >&, const Vector3< real_t >&, real_t, real_t) >
      addedMassCorrelationFunction;
   if (addedMassCorr == AddedMassCorrelation::NoAM)
   { addedMassCorrelationFunction = pe_coupling::discrete_particle_methods::noAddedMassForce; }
   else if (addedMassCorr == AddedMassCorrelation::Finn)
   {
      addedMassCorrelationFunction = pe_coupling::discrete_particle_methods::addedMassForceFinn;
   }
   else
   {
      WALBERLA_ABORT("Added mass correlation not yet implemented!");
   }

   ////////////////
   // EVALUATION //
   ////////////////

   // evaluator for bodies' velocity time derivative
   shared_ptr< pe_coupling::discrete_particle_methods::BodyVelocityTimeDerivativeEvaluator >
      bodyVelocityTimeDerivativeEvaluator =
         make_shared< pe_coupling::discrete_particle_methods::BodyVelocityTimeDerivativeEvaluator >(
            blocks, bodyStorageID, dtBodyVelocityTimeDerivativeEvaluation);
   (*bodyVelocityTimeDerivativeEvaluator)();

   // function used to evaluate the interaction force between fluid and particles
   std::function< void(void) > dragAndPressureForceEvaluationFunction;
   if (interpol == Interpolation::INearestNeighbor)
   {
      if (dist == Distribution::DNearestNeighbor)
      {
         typedef pe_coupling::discrete_particle_methods::InteractionForceEvaluator<
            FlagField_T, field::NearestNeighborFieldInterpolator, field::NearestNeighborDistributor >
            IFE_T;
         shared_ptr< IFE_T > forceEvaluatorPtr = make_shared< IFE_T >(
            blocks, dragForceFieldID, bodyStorageID, flagFieldID, Fluid_Flag, velocityFieldID, svfFieldID,
            pressureGradientFieldID, dragCorrelationFunction, viscosity, selectDPMBodies);
         dragAndPressureForceEvaluationFunction = std::bind(&IFE_T::operator(), forceEvaluatorPtr);
      }
      else if (dist == Distribution::DKernel)
      {
         typedef pe_coupling::discrete_particle_methods::InteractionForceEvaluator<
            FlagField_T, field::NearestNeighborFieldInterpolator, field::KernelDistributor >
            IFE_T;
         shared_ptr< IFE_T > forceEvaluatorPtr = make_shared< IFE_T >(
            blocks, dragForceFieldID, bodyStorageID, flagFieldID, Fluid_Flag, velocityFieldID, svfFieldID,
            pressureGradientFieldID, dragCorrelationFunction, viscosity, selectDPMBodies);
         dragAndPressureForceEvaluationFunction = std::bind(&IFE_T::operator(), forceEvaluatorPtr);
      }
   }
   else if (interpol == Interpolation::IKernel)
   {
      if (dist == Distribution::DNearestNeighbor)
      {
         typedef pe_coupling::discrete_particle_methods::InteractionForceEvaluator<
            FlagField_T, field::KernelFieldInterpolator, field::NearestNeighborDistributor >
            IFE_T;
         shared_ptr< IFE_T > forceEvaluatorPtr = make_shared< IFE_T >(
            blocks, dragForceFieldID, bodyStorageID, flagFieldID, Fluid_Flag, velocityFieldID, svfFieldID,
            pressureGradientFieldID, dragCorrelationFunction, viscosity, selectDPMBodies);
         dragAndPressureForceEvaluationFunction = std::bind(&IFE_T::operator(), forceEvaluatorPtr);
      }
      else if (dist == Distribution::DKernel)
      {
         typedef pe_coupling::discrete_particle_methods::InteractionForceEvaluator<
            FlagField_T, field::KernelFieldInterpolator, field::KernelDistributor >
            IFE_T;
         shared_ptr< IFE_T > forceEvaluatorPtr = make_shared< IFE_T >(
            blocks, dragForceFieldID, bodyStorageID, flagFieldID, Fluid_Flag, velocityFieldID, svfFieldID,
            pressureGradientFieldID, dragCorrelationFunction, viscosity, selectDPMBodies);
         dragAndPressureForceEvaluationFunction = std::bind(&IFE_T::operator(), forceEvaluatorPtr);
      }
   }

   // function to evaluate the lift force contribution
   std::function< void(void) > liftForceEvaluationFunction;
   if (interpol == Interpolation::INearestNeighbor)
   {
      if (dist == Distribution::DNearestNeighbor)
      {
         typedef pe_coupling::discrete_particle_methods::LiftForceEvaluator<
            FlagField_T, field::NearestNeighborFieldInterpolator, field::NearestNeighborDistributor >
            IFE_T;
         shared_ptr< IFE_T > forceEvaluatorPtr =
            make_shared< IFE_T >(blocks, liftForceFieldID, bodyStorageID, flagFieldID, Fluid_Flag, velocityFieldID,
                                 velocityCurlFieldID, liftCorrelationFunction, viscosity, selectDPMBodies);
         liftForceEvaluationFunction = std::bind(&IFE_T::operator(), forceEvaluatorPtr);
      }
      else if (dist == Distribution::DKernel)
      {
         typedef pe_coupling::discrete_particle_methods::LiftForceEvaluator<
            FlagField_T, field::NearestNeighborFieldInterpolator, field::KernelDistributor >
            IFE_T;
         shared_ptr< IFE_T > forceEvaluatorPtr =
            make_shared< IFE_T >(blocks, liftForceFieldID, bodyStorageID, flagFieldID, Fluid_Flag, velocityFieldID,
                                 velocityCurlFieldID, liftCorrelationFunction, viscosity, selectDPMBodies);
         liftForceEvaluationFunction = std::bind(&IFE_T::operator(), forceEvaluatorPtr);
      }
   }
   else if (interpol == Interpolation::IKernel)
   {
      if (dist == Distribution::DNearestNeighbor)
      {
         typedef pe_coupling::discrete_particle_methods::LiftForceEvaluator<
            FlagField_T, field::KernelFieldInterpolator, field::NearestNeighborDistributor >
            IFE_T;
         shared_ptr< IFE_T > forceEvaluatorPtr =
            make_shared< IFE_T >(blocks, liftForceFieldID, bodyStorageID, flagFieldID, Fluid_Flag, velocityFieldID,
                                 velocityCurlFieldID, liftCorrelationFunction, viscosity, selectDPMBodies);
         liftForceEvaluationFunction = std::bind(&IFE_T::operator(), forceEvaluatorPtr);
      }
      else if (dist == Distribution::DKernel)
      {
         typedef pe_coupling::discrete_particle_methods::LiftForceEvaluator<
            FlagField_T, field::KernelFieldInterpolator, field::KernelDistributor >
            IFE_T;
         shared_ptr< IFE_T > forceEvaluatorPtr =
            make_shared< IFE_T >(blocks, liftForceFieldID, bodyStorageID, flagFieldID, Fluid_Flag, velocityFieldID,
                                 velocityCurlFieldID, liftCorrelationFunction, viscosity, selectDPMBodies);
         liftForceEvaluationFunction = std::bind(&IFE_T::operator(), forceEvaluatorPtr);
      }
   }

   // function to evaluate the added mass contribution
   std::function< void(void) > addedMassEvaluationFunction;
   if (interpol == Interpolation::INearestNeighbor)
   {
      if (dist == Distribution::DNearestNeighbor)
      {
         typedef pe_coupling::discrete_particle_methods::AddedMassForceEvaluator<
            FlagField_T, field::NearestNeighborFieldInterpolator, field::NearestNeighborDistributor >
            IFE_T;
         shared_ptr< IFE_T > forceEvaluatorPtr = make_shared< IFE_T >(
            blocks, amForceFieldID, bodyStorageID, flagFieldID, Fluid_Flag, timeDerivativeVelocityFieldID,
            addedMassCorrelationFunction, bodyVelocityTimeDerivativeEvaluator, selectDPMBodies);
         addedMassEvaluationFunction = std::bind(&IFE_T::operator(), forceEvaluatorPtr);
      }
      else if (dist == Distribution::DKernel)
      {
         typedef pe_coupling::discrete_particle_methods::AddedMassForceEvaluator<
            FlagField_T, field::NearestNeighborFieldInterpolator, field::KernelDistributor >
            IFE_T;
         shared_ptr< IFE_T > forceEvaluatorPtr = make_shared< IFE_T >(
            blocks, amForceFieldID, bodyStorageID, flagFieldID, Fluid_Flag, timeDerivativeVelocityFieldID,
            addedMassCorrelationFunction, bodyVelocityTimeDerivativeEvaluator, selectDPMBodies);
         addedMassEvaluationFunction = std::bind(&IFE_T::operator(), forceEvaluatorPtr);
      }
   }
   else if (interpol == Interpolation::IKernel)
   {
      if (dist == Distribution::DNearestNeighbor)
      {
         typedef pe_coupling::discrete_particle_methods::AddedMassForceEvaluator<
            FlagField_T, field::KernelFieldInterpolator, field::NearestNeighborDistributor >
            IFE_T;
         shared_ptr< IFE_T > forceEvaluatorPtr = make_shared< IFE_T >(
            blocks, amForceFieldID, bodyStorageID, flagFieldID, Fluid_Flag, timeDerivativeVelocityFieldID,
            addedMassCorrelationFunction, bodyVelocityTimeDerivativeEvaluator, selectDPMBodies);
         addedMassEvaluationFunction = std::bind(&IFE_T::operator(), forceEvaluatorPtr);
      }
      else if (dist == Distribution::DKernel)
      {
         typedef pe_coupling::discrete_particle_methods::AddedMassForceEvaluator<
            FlagField_T, field::KernelFieldInterpolator, field::KernelDistributor >
            IFE_T;
         shared_ptr< IFE_T > forceEvaluatorPtr = make_shared< IFE_T >(
            blocks, amForceFieldID, bodyStorageID, flagFieldID, Fluid_Flag, timeDerivativeVelocityFieldID,
            addedMassCorrelationFunction, bodyVelocityTimeDerivativeEvaluator, selectDPMBodies);
         addedMassEvaluationFunction = std::bind(&IFE_T::operator(), forceEvaluatorPtr);
      }
   }

   // set up effective viscosity calculation
   std::function< real_t(real_t, real_t) > effectiveViscosityFunction;
   if (effVisc == EffectiveViscosity::None)
   { effectiveViscosityFunction = pe_coupling::discrete_particle_methods::calculateUnchangedEffectiveViscosity; }
   else if (effVisc == EffectiveViscosity::Rescaled)
   {
      effectiveViscosityFunction = pe_coupling::discrete_particle_methods::calculateRescaledEffectiveViscosity;
   }
   else if (effVisc == EffectiveViscosity::Eilers)
   {
      effectiveViscosityFunction = pe_coupling::discrete_particle_methods::calculateEilersEffectiveViscosity;
   }
   else
   {
      WALBERLA_ABORT("Effective viscosity not yet implemented!");
   }
   shared_ptr< pe_coupling::discrete_particle_methods::EffectiveViscosityFieldEvaluator > effectiveViscosityEvaluator =
      walberla::make_shared< pe_coupling::discrete_particle_methods::EffectiveViscosityFieldEvaluator >(
         omegaFieldID, svfFieldID, viscosity, effectiveViscosityFunction);

   ///////////////
   // TIME LOOP //
   ///////////////

   // create the timeloop
   SweepTimeloop timeloop(blocks->getBlockStorage(), timesteps);

   shared_ptr< pe_coupling::BodiesForceTorqueContainer > bodiesFTContainer1 =
      make_shared< pe_coupling::BodiesForceTorqueContainer >(blocks, bodyStorageID, selectMEMBodies);
   std::function< void(void) > storeForceTorqueInCont1 =
      std::bind(&pe_coupling::BodiesForceTorqueContainer::store, bodiesFTContainer1);
   shared_ptr< pe_coupling::BodiesForceTorqueContainer > bodiesFTContainer2 =
      make_shared< pe_coupling::BodiesForceTorqueContainer >(blocks, bodyStorageID, selectMEMBodies);
   std::function< void(void) > setForceTorqueOnBodiesFromCont2 =
      std::bind(&pe_coupling::BodiesForceTorqueContainer::setOnBodies, bodiesFTContainer2);

   shared_ptr< pe_coupling::BodiesForceTorqueContainer > bodiesFTContainer3 =
      make_shared< pe_coupling::BodiesForceTorqueContainer >(blocks, bodyStorageID, selectMEMBodies);
   std::function< void(void) > storeForceTorqueInCont3 =
      std::bind(&pe_coupling::BodiesForceTorqueContainer::store, bodiesFTContainer3);
   std::function< void(void) > setForceTorqueOnBodiesFromCont3 =
      std::bind(&pe_coupling::BodiesForceTorqueContainer::setOnBodies, bodiesFTContainer3);

   shared_ptr< pe_coupling::ForceTorqueOnBodiesScaler > forceScaler =
      make_shared< pe_coupling::ForceTorqueOnBodiesScaler >(blocks, bodyStorageID, real_t(1), selectMEMBodies);

   std::function< void(void) > setForceScalingFactorToHalf =
      std::bind(&pe_coupling::ForceTorqueOnBodiesScaler::resetScalingFactor, forceScaler, real_t(0.5));

   // initial svf eval
   if (dist == Distribution::DNearestNeighbor)
   {
      pe_coupling::discrete_particle_methods::SolidVolumeFractionFieldEvaluator< FlagField_T,
                                                                                 field::NearestNeighborDistributor >
         svfEvaluator(blocks, svfFieldID, bodyStorageID, flagFieldID, Fluid_Flag, selectDPMBodies);
      for (auto blockIt = blocks->begin(); blockIt != blocks->end(); ++blockIt)
         svfEvaluator(&(*blockIt));
   }
   else
For faster browsing, not all history is shown. View entire blame