OpenLB 1.7
Loading...
Searching...
No Matches
latticePorousMomentumLossForce2D.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2019 Albert Mink, Mathias J. Krause, Lukas Baron
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_POROUS_MOMENTUM_LOSS_FORCE_2D_HH
25#define LATTICE_POROUS_MOMENTUM_LOSS_FORCE_2D_HH
26
27#include <vector>
28#include "utilities/omath.h"
29#include <limits>
30
32#include "dynamics/lbm.h" // for computation of lattice rho and velocity
35#include "blockBaseF2D.h"
36#include "functors/genericF.h"
40
41
42namespace olb {
43/*
44template <typename T, typename DESCRIPTOR>
45SuperLatticePorousMomentumLossForce2D<T,DESCRIPTOR>::SuperLatticePorousMomentumLossForce2D
46(SuperLattice<T,DESCRIPTOR>& sLattice, SuperGeometry<T,2>& superGeometry,
47 std::vector<SmoothIndicatorF2D<T,T,true>* >& indicator, const UnitConverter<T,DESCRIPTOR>& converter)
48 : SuperLatticePhysF2D<T,DESCRIPTOR>(sLattice,converter,4*indicator.size())
49{
50 this->getName() = "physPorousMomentumLossForce";
51 int maxC = this->_sLattice.getLoadBalancer().size();
52 this->_blockF.reserve(maxC);
53 for (int iC = 0; iC < maxC; iC++) {
54 this->_blockF.emplace_back( new BlockLatticePorousMomentumLossForce2D<T,DESCRIPTOR>(this->_sLattice.getBlock(iC), superGeometry.getBlockGeometry(iC), indicator, converter));
55 }
56}
57
58template <typename T, typename DESCRIPTOR>
59bool SuperLatticePorousMomentumLossForce2D<T,DESCRIPTOR>::operator() (T output[],
60 const int input[])
61{
62 for (int i=0; i<this->getTargetDim(); i++) {
63 output[i] = 0.;
64 }
65 for (int iC = 0; iC < this->_sLattice.getLoadBalancer().size(); ++iC) {
66 int globiC = this->_sLattice.getLoadBalancer().glob(iC);
67 if ( this->_sLattice.getLoadBalancer().rank(globiC) == singleton::mpi().getRank() ) {
68 this->getBlockF(iC)(output,&input[1]);
69 }
70 }
71
72#ifdef PARALLEL_MODE_MPI
73 for (int i = 0; i < this->getTargetDim(); ++i) {
74 singleton::mpi().reduceAndBcast(output[i], MPI_SUM);
75 }
76#endif
77 return true;
78
79}
80
81template<typename T, typename DESCRIPTOR>
82BlockLatticePorousMomentumLossForce2D<T, DESCRIPTOR>::BlockLatticePorousMomentumLossForce2D(
83 BlockLattice<T, DESCRIPTOR>& blockLattice, BlockGeometry<T,2>& blockGeometry,
84 std::vector<SmoothIndicatorF2D<T,T,true>* >& indicator, const UnitConverter<T,DESCRIPTOR>& converter)
85 : BlockLatticePhysF2D<T, DESCRIPTOR>(blockLattice, converter, 4*indicator.size()), _blockGeometry(blockGeometry), _vectorOfIndicator(indicator)
86{
87 this->getName() = "physPorousMomentumLossForce";
88}
89
90template<typename T, typename DESCRIPTOR>
91bool BlockLatticePorousMomentumLossForce2D<T, DESCRIPTOR>::operator()(T output[], const int input[])
92{
93 // iterate over all particles in _indicator
94 for (size_t iInd=0; iInd!=_vectorOfIndicator.size(); iInd++) {
95
96 int numVoxels = 0;
97 std::vector<int> start{0,0};
98 std::vector<int> end{0,0};
99 T invDeltaX = 1./this->_converter.getPhysDeltaX();
100
101 if (getRangeBlockGeometrySmoothIndicatorIntersection2D(_blockGeometry, *(_vectorOfIndicator[iInd]), invDeltaX, start, end)) {
102
103 // iterate over cells in the constructed intersection box
104 for (int iX = start[0]; iX < end[0]; iX++) {
105 for (int iY = start[1]; iY < end[1]; iY++) {
106 // check if cell belongs to particle
107 T inside[1] = {0.};
108 T posIn[2] = {0.};
109 _blockGeometry.getPhysR(posIn, {iX, iY});
110 (*(_vectorOfIndicator[iInd]))( inside, posIn);
111 if ( !util::nearZero(inside[0]) && this->_blockGeometry.get({iX,iY})==1) {
112 // compute momentum exchange force on particle
113 T tmpForce[2] = {0.,0.};
114 tmpForce[0] += this->_blockLattice.get(iX, iY).template getFieldComponent<descriptors::VELOCITY_NUMERATOR>(0);
115 tmpForce[1] += this->_blockLattice.get(iX, iY).template getFieldComponent<descriptors::VELOCITY_NUMERATOR>(1);
116 // reset external field for next timestep
117 T reset_to_zero[2] = {0.,0.};
118 this->_blockLattice.get(iX, iY).template setField<descriptors::VELOCITY_NUMERATOR>(reset_to_zero);
119 // convert force to SI units and compute torque
120 numVoxels++;
121 // division bei length of lattice cell necessary due to converter handling of force
122 tmpForce[0] = this->_converter.getPhysForce(tmpForce[0])*invDeltaX;
123 tmpForce[1] = this->_converter.getPhysForce(tmpForce[1])*invDeltaX;
124 output[0+iInd*4] += tmpForce[0];
125 output[1+iInd*4] += tmpForce[1];
126 output[2+iInd*4] += (posIn[0]-_vectorOfIndicator[iInd]->getPos()[0])*tmpForce[1] - (posIn[1]-_vectorOfIndicator[iInd]->getPos()[1])*tmpForce[0];
127 }
128 }
129 }
130
131 }
132 output[3+iInd*4] = numVoxels;
133
134 }
135 return true;
136}
137*/
138}
139#endif
The description of a generic interface for all functor classes – header file.
This file contains indicator functions.
Wrapper functions that simplify the use of MPI.
Top level namespace for all of OpenLB.
Representation of a parallel 2D geometry – header file.