OpenLB 1.7
Loading...
Searching...
No Matches
interpolationF2D.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2012-2018 Lukas Baron, Tim Dornieden, Mathias J. Krause,
4 * Albert Mink, Adrian Kummerlaender
5 * E-mail contact: info@openlb.net
6 * The most recent release of OpenLB can be downloaded at
7 * <http://www.openlb.net/>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23*/
24
25#ifndef INTERPOLATION_F_2D_HH
26#define INTERPOLATION_F_2D_HH
27
28#include "interpolationF2D.h"
29#include "core/superLattice2D.h"
30#include "dynamics/lbm.h"
31
32namespace olb {
33
34
35template <typename T, typename W>
37 BlockF2D<W>& f, Cuboid2D<T>& cuboid)
38 : AnalyticalF2D<T,W>(f.getTargetDim()),
39 _f(f), _cuboid(cuboid)
40{
41 this->getName() = "fromBlockF";
42}
43
44template <typename T, typename W>
45bool AnalyticalFfromBlockF2D<T,W>::operator()(W output[], const T physC[])
46{
47 int latticeC[2];
48 int latticeR[2];
49 _cuboid.getFloorLatticeR(latticeR, physC);
50
51 auto& block = _f.getBlockStructure();
52 auto padding = std::min(1, block.getPadding());
53
54 if (LatticeR<2>(latticeR) >= -padding && LatticeR<2>(latticeR) < block.getExtent()+padding-1) {
55 const int& locX = latticeR[0];
56 const int& locY = latticeR[1];
57
58 Vector<T,2> physRiC;
59 Vector<T,2> physCv(physC);
60 _cuboid.getPhysR(physRiC.data(), {locX, locY});
61
62 // compute weights
63 Vector<W,2> d = (physCv - physRiC) * (1. / _cuboid.getDeltaR());
64 Vector<W,2> e = 1. - d;
65
66 T output_tmp[_f.getTargetDim()];
67 for (int iD = 0; iD < _f.getTargetDim(); ++iD) {
68 output_tmp[iD] = T();
69 }
70
71 latticeC[0] = locX;
72 latticeC[1] = locY;
73 _f(output_tmp,latticeC);
74 for (int iD = 0; iD < _f.getTargetDim(); ++iD) {
75 output[iD] += output_tmp[iD] * e[0] * e[1];
76 output_tmp[iD] = T();
77 }
78
79 latticeC[0] = locX;
80 latticeC[1] = locY + 1;
81 _f(output_tmp,latticeC);
82 for (int iD = 0; iD < _f.getTargetDim(); ++iD) {
83 output[iD] += output_tmp[iD] * e[0] * d[1];
84 output_tmp[iD] = T();
85 }
86
87 latticeC[0] = locX + 1;
88 latticeC[1] = locY;
89 _f(output_tmp,latticeC);
90 for (int iD = 0; iD < _f.getTargetDim(); ++iD) {
91 output[iD] += output_tmp[iD] * d[0] * e[1];
92 output_tmp[iD] = T();
93 }
94
95 latticeC[0] = locX + 1;
96 latticeC[1] = locY + 1;
97 _f(output_tmp,latticeC);
98 for (int iD = 0; iD < _f.getTargetDim(); ++iD) {
99 output[iD] += output_tmp[iD] * d[0] * d[1];
100 output_tmp[iD] = T();
101 }
102
103 return true;
104 }
105 else {
106 return false;
107 }
108}
109
110template <typename T, typename W>
112 bool communicateToAll, bool communicateOverlap)
113 : AnalyticalF2D<T,W>(f.getTargetDim()),
114 _communicateToAll(communicateToAll),
115 _communicateOverlap(communicateOverlap),
116 _f(f),
117 _cuboidGeometry(_f.getSuperStructure().getCuboidGeometry())
118{
119 this->getName() = "fromSuperF";
120
121 LoadBalancer<T>& load = _f.getSuperStructure().getLoadBalancer();
122 for (int iC = 0; iC < load.size(); ++iC) {
123 this->_blockF.emplace_back(
124 new AnalyticalFfromBlockF2D<T>(_f.getBlockF(iC),
125 _cuboidGeometry.get(load.glob(iC)))
126 );
127 }
128}
129
130template <typename T, typename W>
131bool AnalyticalFfromSuperF2D<T,W>::operator() (T output[], const T physC[])
132{
133 for (int iD = 0; iD < _f.getTargetDim(); ++iD) {
134 output[iD] = W();
135 }
136
137 int latticeR[3];
138 if (!_cuboidGeometry.getLatticeR(latticeR, physC)) {
139 return false;
140 }
141
142 if (_communicateOverlap) {
143 _f.getSuperStructure().communicate();
144 }
145
146 int dataSize = 0;
147 int dataFound = 0;
148
149 LoadBalancer<T>& load = _f.getSuperStructure().getLoadBalancer();
150 for (int iC = 0; iC < load.size(); ++iC) {
151 if (_blockF[iC]->operator()(output, physC)) {
152 dataSize += _f.getTargetDim();
153 ++dataFound;
154 }
155 }
156
157 if (_communicateToAll) {
158#ifdef PARALLEL_MODE_MPI
159 singleton::mpi().reduceAndBcast(dataFound, MPI_SUM);
160 singleton::mpi().reduceAndBcast(dataSize, MPI_SUM);
161#endif
162 dataSize /= dataFound;
163#ifdef PARALLEL_MODE_MPI
164 for (int iD = 0; iD < dataSize; ++iD) {
165 singleton::mpi().reduceAndBcast(output[iD], MPI_SUM);
166 }
167#endif
168 for (int iD = 0; iD < dataSize; ++iD) {
169 output[iD]/=dataFound;
170 }
171 }
172 else {
173 if (dataFound!=0) {
174 dataSize /= dataFound;
175 for (int iD = 0; iD < dataSize; ++iD) {
176 output[iD]/=dataFound;
177 }
178 }
179 }
180
181 if (dataFound>0) {
182 return true;
183 }
184 return false;
185}
186
187template <typename T, typename W>
189{
190 OLB_ASSERT(_blockF.size() < UINT32_MAX,
191 "it is safe to cast std::size_t to int");
192 return _blockF.size();
193}
194
195template <typename T, typename W>
197{
198 OLB_ASSERT(size_t(iCloc) < _blockF.size() && iCloc >= 0,
199 "block functor index within bounds");
200 return *(_blockF[iCloc]);
201}
202
203
204} // end namespace olb
205
206#endif
AnalyticalF are applications from DD to XD, where X is set by the constructor.
Converts block functors to analytical functors.
bool operator()(W output[], const T physC[]) override
AnalyticalFfromBlockF2D(BlockF2D< W > &f, Cuboid2D< T > &cuboid)
CuboidGeometry2D< T > & _cuboidGeometry
AnalyticalFfromSuperF2D(SuperF2D< T > &f, bool communicateToAll=false, bool communicateOverlap=true)
AnalyticalFfromBlockF2D< T, W > & getBlockF(int iCloc)
std::vector< std::unique_ptr< AnalyticalFfromBlockF2D< T, W > > > _blockF
bool operator()(T output[], const T physC[]) override
represents all functors that operate on a cuboid in general, mother class of BlockLatticeF,...
A regular single 2D cuboid is the basic component of a 2D cuboid structure which defines the grid.
Definition cuboid2D.h:54
std::string & getName()
read and write access to name
Definition genericF.hh:51
Base class for all LoadBalancer.
int glob(int loc) const
represents all functors that operate on a SuperStructure<T,2> in general
Plain old scalar vector.
Definition vector.h:47
constexpr const T * data() const any_platform
Definition vector.h:161
void reduceAndBcast(T &reductVal, MPI_Op op, int root=0, MPI_Comm comm=MPI_COMM_WORLD)
Reduction operation, followed by a broadcast.
MpiManager & mpi()
Top level namespace for all of OpenLB.
#define OLB_ASSERT(COND, MESSAGE)
Definition olbDebug.h:45
The description of a 2D super lattice – header file.