OpenLB 1.7
Loading...
Searching...
No Matches
blockLatticeRefinementMetricF2D.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2018 Adrian Kummerlaender
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 BLOCK_LATTICE_REFINEMENT_METRIC_F_2D_HH
25#define BLOCK_LATTICE_REFINEMENT_METRIC_F_2D_HH
26
28#include "dynamics/lbm.h"
29
30
31namespace olb {
32
33
34template<typename T, typename DESCRIPTOR>
36 BlockLattice<T, DESCRIPTOR>& blockLattice)
37 : BlockLatticeF2D<T, DESCRIPTOR>(blockLattice, 1)
38{
39 this->getName() = "knudsen";
40}
41
42template<typename T, typename DESCRIPTOR>
43bool BlockLatticeKnudsen2D<T, DESCRIPTOR>::operator()(T output[], const int input[])
44{
45 ConstCell<T,DESCRIPTOR> cell = this->_blockLattice.get(input[0], input[1]);
46
47 T rho = { };
48 T u[2] = { };
49 cell.computeRhoU(rho, u);
50
51 const T uSqr = u[0]*u[0] + u[1]*u[1];
52
53 T sum = 0.;
54
55 for (int iPop = 0; iPop < DESCRIPTOR::q; ++iPop) {
56 const T fEq = olb::equilibrium<DESCRIPTOR>::secondOrder(iPop, rho, u, uSqr);
57
58 sum += util::abs((cell[iPop] - fEq) / (fEq + descriptors::t<T,DESCRIPTOR>(iPop)));
59 }
60
61 output[0] = sum / (DESCRIPTOR::q);
62
63 return true;
64}
65
66
67template<typename T, typename DESCRIPTOR>
69 BlockLattice<T, DESCRIPTOR>& blockLattice,
70 const UnitConverter<T, DESCRIPTOR>& converter)
71 : BlockLatticeKnudsen2D<T, DESCRIPTOR>(blockLattice),
72 _knudsen(converter.getKnudsenNumber())
73{
74 this->getName() = "refinementMetricKnudsen";
75}
76
77template<typename T, typename DESCRIPTOR>
79{
80 const std::size_t cellCount = this->_blockLattice.getNx() * this->_blockLattice.getNy();
81
82 T blockSum = 0.;
83
84 T localOutput[1] = { };
85 int localInput[2] = { };
86
87 for (localInput[0] = 0; localInput[0] < this->_blockLattice.getNx(); ++localInput[0]) {
88 for (localInput[1] = 0; localInput[1] < this->_blockLattice.getNy(); ++localInput[1]) {
90
91 blockSum += localOutput[0];
92 }
93 }
94
95 const T blockC = blockSum / cellCount;
96
97 output[0] = std::log2(blockC / _knudsen);
98
99 if ( output[0] <= 0. || blockC <= 0. ) {
100 output[0] = 0.;
101 }
102
103 return true;
104}
105
106template<typename T, typename DESCRIPTOR>
108 T output[], const int input[])
109{
110 T measuredKnudsen[1] { };
112
113 output[0] = std::log2(measuredKnudsen[0] / _knudsen);
114
115 if ( output[0] <= 0. || measuredKnudsen[0] <= 0. ) {
116 output[0] = 0.;
117 }
118
119 return true;
120}
121
122
123}
124
125#endif
represents all functors that operate on a DESCRIPTOR in general, e.g. getVelocity(),...
BlockLatticeKnudsen2D(BlockLattice< T, DESCRIPTOR > &blockLattice)
bool operator()(T output[], const int input[]) override
has to be implemented for 'every' derived class
BlockLatticeRefinementMetricKnudsen2D(BlockLattice< T, DESCRIPTOR > &blockLattice, const UnitConverter< T, DESCRIPTOR > &converter)
Platform-abstracted block lattice for external access and inter-block interaction.
Highest-level interface to read-only Cell data.
Definition cell.h:53
void computeRhoU(T &rho, T u[descriptors::d< DESCRIPTOR >()]) const
Compute fluid velocity and particle density on the cell.
Definition cell.hh:232
std::string & getName()
read and write access to name
Definition genericF.hh:51
Conversion between physical and lattice units, as well as discretization.
ADf< T, DIM > abs(const ADf< T, DIM > &a)
Definition aDiff.h:1019
Top level namespace for all of OpenLB.
static V secondOrder(int iPop, const RHO &rho, const U &u, const USQR &uSqr) any_platform
Computation of equilibrium distribution, second order in u.
Definition lbm.h:51