OpenLB 1.7
Loading...
Searching...
No Matches
blockLatticeRefinementMetricF3D.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_3D_HH
25#define BLOCK_LATTICE_REFINEMENT_METRIC_F_3D_HH
26
28#include "dynamics/lbm.h"
29
30
31namespace olb {
32
33
34template<typename T, typename DESCRIPTOR>
36 BlockLattice<T, DESCRIPTOR>& blockLattice)
37 : BlockLatticeF3D<T, DESCRIPTOR>(blockLattice, 1)
38{
39 this->getName() = "knudsen";
40}
41
42template<typename T, typename DESCRIPTOR>
43bool BlockLatticeKnudsen3D<T, DESCRIPTOR>::operator()(T output[], const int input[])
44{
45 ConstCell<T,DESCRIPTOR> cell = this->_blockLattice.get(input[0], input[1], input[2]);
46
47 T rho = { };
48 T u[3] = { };
49 cell.computeRhoU(rho, u);
50
51 const T uSqr = u[0]*u[0] + u[1]*u[1] + u[2]*u[2];
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 : BlockLatticeKnudsen3D<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() * this->_blockLattice.getNz();
81
82 T blockSum = 0.;
83
84 T localOutput[1] = { };
85 int localInput[3] = { };
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]) {
89 for (localInput[2]=0; localInput[2] < this->_blockLattice.getNz(); ++localInput[2]) {
91
92 blockSum += localOutput[0];
93 }
94 }
95 }
96
97 const T blockC = blockSum / cellCount;
98
99 output[0] = std::log2(blockC / _knudsen);
100
101 if ( output[0] <= 0. || blockC <= 0. ) {
102 output[0] = 0.;
103 }
104
105 return true;
106}
107
108template<typename T, typename DESCRIPTOR>
110 T output[], const int input[])
111{
112 T measuredKnudsen[1] { };
114
115 output[0] = std::log2(measuredKnudsen[0] / _knudsen);
116
117
118 if ( output[0] <= 0. || measuredKnudsen[0] <= 0. ) {
119 output[0] = 0.;
120 }
121
122
123 return true;
124}
125
126
127template<typename T, typename DESCRIPTOR>
129 BlockLattice<T, DESCRIPTOR>& blockLattice)
130 : BlockLatticeF3D<T, DESCRIPTOR>(blockLattice, 1)
131{
132 this->getName() = "high_order_knudsen";
133}
134
135template<typename T, typename DESCRIPTOR>
137{
138 ConstCell<T,DESCRIPTOR> cell = this->_blockLattice.get(input[0], input[1], input[2]);
139
140 T rho = { };
141 T u[3] = { };
143 cell.computeAllMomenta(rho, u, pi);
144
145 const T uSqr = u[0]*u[0] + u[1]*u[1] + u[2]*u[2];
146
147 T sum = 0.;
148
149 for (int iPop = 0; iPop < DESCRIPTOR::q; ++iPop) {
150 const T fEq = olb::equilibrium<DESCRIPTOR>::secondOrder(iPop, rho, u, uSqr);
151 const T fNeqFromPi = olb::lbm< DESCRIPTOR>::fromPiToFneq(iPop, pi);
152
153 sum += util::abs((cell[iPop] - fEq - fNeqFromPi) / (fEq + descriptors::t<T,DESCRIPTOR>(iPop)));
154 }
155
156 output[0] = sum / (DESCRIPTOR::q);
157
158 return true;
159}
160
161}
162
163#endif
represents all functors that operate on a DESCRIPTOR in general, e.g. getVelocity(),...
bool operator()(T output[], const int input[]) override
has to be implemented for 'every' derived class
BlockLatticeHighOrderKnudsen3D(BlockLattice< T, DESCRIPTOR > &blockLattice)
BlockLatticeKnudsen3D(BlockLattice< T, DESCRIPTOR > &blockLattice)
bool operator()(T output[], const int input[]) override
has to be implemented for 'every' derived class
BlockLatticeRefinementMetricKnudsen3D(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 computeAllMomenta(T &rho, T u[descriptors::d< DESCRIPTOR >()], T pi[util::TensorVal< DESCRIPTOR >::n]) const
Compute all momenta on the celll, up to second order.
Definition cell.hh:259
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
Collection of common computations for LBM.
Definition lbm.h:182
Compute number of elements of a symmetric d-dimensional tensor.
Definition util.h:210