OpenLB 1.7
Loading...
Searching...
No Matches
latticeStokesDragForce.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2021 Nicolas Hafen, Mathias J. Krause
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef LATTICE_STOKES_DRAG_FORCE_HH
25#define LATTICE_STOKES_DRAG_FORCE_HH
26
28
29namespace olb {
30
31
32template<typename T, typename DESCRIPTOR, typename PARTICLETYPE, bool serialize>
34 BlockLattice<T, DESCRIPTOR>& blockLattice,
35 const BlockGeometry<T,DESCRIPTOR::d>& blockGeometry,
37 const UnitConverter<T,DESCRIPTOR>& converter,
40 std::size_t iP0,
41 const std::unordered_set<int>& ignoredMaterials,
42 const F f)
43 : BlockLatticePhysF<T,DESCRIPTOR>(blockLattice, converter,
44 (DESCRIPTOR::d)*(particleSystem.size()-iP0)),
45 _blockGeometry(blockGeometry), _blockLattice(blockLattice),
46 _particleSystem(particleSystem),
47 _cellMin(cellMin), _cellMax(cellMax), _periodic(periodic),
48 _iP0(iP0), _ignoredMaterials(ignoredMaterials), _f(f)
49{
50 this->getName() = "physStokesDragForce";
51 //Calculate precalculated constants
52 _delTinv = 1./this->_converter.getPhysDeltaT();
53 _C1 = 6. * M_PI
54 * converter.getPhysViscosity()
55 * converter.getPhysDensity()
56 * converter.getConversionFactorTime();
57}
58
59template<typename T, typename DESCRIPTOR, typename PARTICLETYPE, bool serialize>
61 T output[], particles::Particle<T,PARTICLETYPE>& particle, int iP)
62{
63 constexpr unsigned D = DESCRIPTOR::d;
64 const int serialSize = D;
65
66 using namespace descriptors;
67
68 //Retrieve particle quantities
69 Vector<T,D> position = particle.template getField<GENERAL,POSITION>();
70 Vector<T,D> velocity = particle.template getField<MOBILITY,VELOCITY>();
71 T radius = particle.template getField<PHYSPROPERTIES,RADIUS>();
72 T mass = particle.template getField<PHYSPROPERTIES,MASS>();
73 T* positionArray = position.data();
74
75 //TODO: check, whether creation can be avoided by using a second _blockF list
76 const auto& cuboid = _blockGeometry.getCuboid();
78 _blockLattice, this->_converter, cuboid);
79
80 //Calculate particle coefficiants
81 T c = _C1 * radius * 1./mass;
82 T C2 = 1. / (1. + c);
83
84 T fluidVelArray[D] = {0.};
85
86 //Check whether inside cuboid (when not parallelized)
87 bool inside = true;
88 if constexpr ( !particles::access::providesParallelization<PARTICLETYPE>() ){
89 inside = cuboid.checkPoint(position);
90 }
91 if (inside){
92
93 //Retrieve interpolated velocity at position
94 blockInterpPhysVelF(fluidVelArray, positionArray);
95
96 //Record interpolated fluid field, if MOBILITY,FLUIDVEL provided
97 if constexpr( PARTICLETYPE::template providesNested<MOBILITY,FLUIDVEL>() ){
98 particle.template setField<MOBILITY, FLUIDVEL>(fluidVelArray);
99 }
100
101 //Calculate stokes force
102 Vector<T,D> tmpForce(0.);
103 for (int iDim = 0; iDim < PARTICLETYPE::d; ++iDim) {
104 tmpForce[iDim] = mass * _delTinv
105 * ((c * fluidVelArray[iDim] + velocity[iDim]) * C2 - velocity[iDim]);
106 }
107
108 _f(particle, position, tmpForce, Vector<T,utilities::dimensions::convert<D>::rotation>(T{0}));
109
110 //Add force and torque to output or apply directly
111 //INFO: serialization only possible to provide analogy to momentumExchange!
112 if constexpr (serialize){
113 std::size_t iPeval = iP-_iP0; //Shifted output index, if iP!=0
114 for (unsigned iDim=0; iDim<D; iDim++) {
115 output[iDim+iPeval*serialSize] += tmpForce[iDim];
116 }
117 } else {
118 //Apply tmpForce as absolute force (no increment, as no empty output[] available)
119 particle.template setField<FORCING,FORCE>( tmpForce );
120 }
121 }
122}
123
124
125
126template<typename T, typename DESCRIPTOR, typename PARTICLETYPE, bool serialize>
128{
129 using namespace descriptors;
130 // iterate over all particles in _indicator //TODO: add periodic treatment analogous to momentum exchange
131 for (std::size_t iP=_iP0; iP!=_particleSystem.size(); iP++) {
132 auto particle = _particleSystem.get(iP);
133 if (particles::access::isValid(particle)){
134 evaluate(output, particle, iP);
135 }
136 }
137 return true;
138}
139
140
141
142}
143#endif
#define M_PI
Representation of a block geometry.
bool operator()(T output[], const int input[]) override
void evaluate(T output[], particles::Particle< T, PARTICLETYPE > &particle, int iP)
BlockLatticeStokesDragForce(BlockLattice< T, DESCRIPTOR > &blockLattice, const BlockGeometry< T, DESCRIPTOR::d > &blockGeometry, particles::ParticleSystem< T, PARTICLETYPE > &particleSystem, const UnitConverter< T, DESCRIPTOR > &converter, PhysR< T, DESCRIPTOR::d > cellMin=PhysR< T, DESCRIPTOR::d >(0.), PhysR< T, DESCRIPTOR::d > cellMax=PhysR< T, DESCRIPTOR::d >(0.), Vector< bool, DESCRIPTOR::d > periodic=Vector< bool, DESCRIPTOR::d >(false), std::size_t iP0=0, const std::unordered_set< int > &ignoredMaterials=std::unordered_set< int >{}, const F f=[](auto &, const auto &, const auto &, const auto &){})
Platform-abstracted block lattice for external access and inter-block interaction.
Conversion between physical and lattice units, as well as discretization.
constexpr T getPhysDensity() const
return density in physical units
constexpr T getPhysViscosity() const
return viscosity in physical units
constexpr T getConversionFactorTime() const
access (read-only) to private member variable
Plain old scalar vector.
Definition vector.h:47
constexpr const T * data() const any_platform
Definition vector.h:161
bool isValid(Particle< T, PARTICLETYPE > particle)
Top level namespace for all of OpenLB.
std::conditional_t< DESCRIPTOR::d==2, BlockLatticeInterpPhysVelocity2D< T, DESCRIPTOR >, BlockLatticeInterpPhysVelocity3D< T, DESCRIPTOR > > BlockLatticeInterpPhysVelocity
Definition aliases.h:360
std::conditional_t< DESCRIPTOR::d==2, BlockLatticePhysF2D< T, DESCRIPTOR >, BlockLatticePhysF3D< T, DESCRIPTOR > > BlockLatticePhysF
Definition aliases.h:339
Converts dimensions by deriving from given cartesian dimension D.