OpenLB 1.7
Loading...
Searching...
No Matches
latticeVolumeFractionPolygonApproximation2D.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_VOLUME_FRACTION_POLYGON_APPROXIMATION_2D_HH
25#define LATTICE_VOLUME_FRACTION_POLYGON_APPROXIMATION_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>
46 SuperLattice<T,DESCRIPTOR>& sLattice, SuperGeometry<T,2>& superGeometry,
47 IndicatorF2D<T>& indicator, const UnitConverter<T,DESCRIPTOR>& converter, bool insideOut)
48 : SuperLatticeF2D<T, DESCRIPTOR>(sLattice, 1)
49{
50 this->getName() = "volumeFractionPolygonApproximation";
51 int maxC = this->_sLattice.getLoadBalancer().size();
52 this->_blockF.reserve(maxC);
53 for (int iC = 0; iC < maxC; iC++) {
55 superGeometry.getBlockGeometry(iC),
56 indicator, converter, insideOut));
57 }
58}
59
60template<typename T, typename DESCRIPTOR>
62 BlockGeometry<T,2>& blockGeometry,
63 IndicatorF2D<T>& indicator,
64 const UnitConverter<T,DESCRIPTOR>& converter,
65 bool insideOut)
66 : BlockLatticeF2D<T, DESCRIPTOR>(blockLattice, 1),
67 _blockGeometry(blockGeometry), _indicator(indicator), _converter(converter), _insideOut(insideOut)
68{
69 this->getName() = "volumeFractionPolygonApproximation";
70}
71
72template<typename T, typename DESCRIPTOR>
74{
75 output[0] = 0.;
76 T physR[2];
77
78 bool cornerXMYM_inside[1];
79 bool cornerXMYP_inside[1];
80 bool cornerXPYM_inside[1];
81 bool cornerXPYP_inside[1];
82 _blockGeometry.getPhysR(physR, {input[0], input[1]});
83
84 T cornerXMYM[2];
85 T cornerXMYP[2];
86 T cornerXPYM[2];
87 T cornerXPYP[2];
88
89 cornerXMYM[0] = physR[0] - 0.5*_converter.getPhysDeltaX();
90 cornerXMYM[1] = physR[1] - 0.5*_converter.getPhysDeltaX();
91
92 cornerXMYP[0] = physR[0] - 0.5*_converter.getPhysDeltaX();
93 cornerXMYP[1] = physR[1] + 0.5*_converter.getPhysDeltaX();
94
95 cornerXPYM[0] = physR[0] + 0.5*_converter.getPhysDeltaX();
96 cornerXPYM[1] = physR[1] - 0.5*_converter.getPhysDeltaX();
97
98 cornerXPYP[0] = physR[0] + 0.5*_converter.getPhysDeltaX();
99 cornerXPYP[1] = physR[1] + 0.5*_converter.getPhysDeltaX();
100
101 _indicator(cornerXMYM_inside, cornerXMYM);
102 _indicator(cornerXMYP_inside, cornerXMYP);
103 _indicator(cornerXPYM_inside, cornerXPYM);
104 _indicator(cornerXPYP_inside, cornerXPYP);
105
106 if ((cornerXMYM_inside[0] && cornerXMYP_inside[0] && cornerXPYM_inside[0] && cornerXPYP_inside[0]) ||
107 (!cornerXMYM_inside[0] && !cornerXMYP_inside[0] && !cornerXPYM_inside[0] && !cornerXPYP_inside[0]) ) {
108 if (!_insideOut) {
109 if (cornerXMYM_inside[0]) {
110 output[0] = 1.0;
111 }
112 }
113 else {
114 if (!cornerXMYM_inside[0]) {
115 output[0] = 1.0;
116 }
117 }
118 }
119 else {
120 Vector<T,2> cornerXMYM_vec(physR[0] - 0.5*_converter.getPhysDeltaX(), physR[1] - 0.5*_converter.getPhysDeltaX());
121 Vector<T,2> cornerXPYP_vec(physR[0] + 0.5*_converter.getPhysDeltaX(), physR[1] + 0.5*_converter.getPhysDeltaX());
122
123 Vector<T,2> directionXP(_converter.getPhysDeltaX(), 0);
124 Vector<T,2> directionXM(-_converter.getPhysDeltaX(), 0);
125 Vector<T,2> directionYP(0, _converter.getPhysDeltaX());
126 Vector<T,2> directionYM(0, -_converter.getPhysDeltaX());
127
128 T distanceXP = 1.01 * _converter.getPhysDeltaX();
129 T distanceXM = 1.01 * _converter.getPhysDeltaX();
130 T distanceYP = 1.01 * _converter.getPhysDeltaX();
131 T distanceYM = 1.01 * _converter.getPhysDeltaX();
132
133 if ((cornerXMYM_inside[0] && !cornerXMYP_inside[0]) ||
134 (!cornerXMYM_inside[0] && cornerXMYP_inside[0]) ) {
135 _indicator.distance(distanceYP, cornerXMYM, directionYP);
136 }
137
138 if ((cornerXMYM_inside[0] && !cornerXPYM_inside[0]) ||
139 (!cornerXMYM_inside[0] && cornerXPYM_inside[0]) ) {
140 _indicator.distance(distanceXP, cornerXMYM, directionXP);
141 }
142
143 if ((cornerXPYP_inside[0] && !cornerXMYP_inside[0]) ||
144 (!cornerXPYP_inside[0] && cornerXMYP_inside[0]) ) {
145 _indicator.distance(distanceXM, cornerXPYP, directionXM);
146 }
147
148 if ((cornerXPYP_inside[0] && !cornerXPYM_inside[0]) ||
149 (!cornerXPYP_inside[0] && cornerXPYM_inside[0]) ) {
150 _indicator.distance(distanceYM, cornerXPYP, directionYM);
151 }
152
153 T volumeFraction = 0.0;
154
155 if (distanceXP < _converter.getPhysDeltaX() && distanceXM < _converter.getPhysDeltaX()) {
156 volumeFraction = distanceXP * _converter.getPhysDeltaX();
157 volumeFraction += 0.5 * (_converter.getPhysDeltaX() - distanceXM - distanceXP) * _converter.getPhysDeltaX();
158 volumeFraction /= _converter.getPhysDeltaX() * _converter.getPhysDeltaX();
159 if (!cornerXMYM_inside[0]) {
160 volumeFraction = 1.0 - volumeFraction;
161 }
162 }
163
164 if (distanceYP < _converter.getPhysDeltaX() && distanceYM < _converter.getPhysDeltaX()) {
165 volumeFraction = distanceYP * _converter.getPhysDeltaX();
166 volumeFraction += 0.5 * (_converter.getPhysDeltaX() - distanceYM - distanceYP) * _converter.getPhysDeltaX();
167 volumeFraction /= _converter.getPhysDeltaX() * _converter.getPhysDeltaX();
168 if (!cornerXMYM_inside[0]) {
169 volumeFraction = 1.0 - volumeFraction;
170 }
171 }
172
173 if (distanceXP < _converter.getPhysDeltaX() && distanceYP < _converter.getPhysDeltaX()) {
174 volumeFraction = 0.5 * distanceXP * distanceYP;
175 volumeFraction /= _converter.getPhysDeltaX() * _converter.getPhysDeltaX();
176 if (!cornerXMYM_inside[0]) {
177 volumeFraction = 1.0 - volumeFraction;
178 }
179 }
180
181 if (distanceXM < _converter.getPhysDeltaX() && distanceYM < _converter.getPhysDeltaX()) {
182 volumeFraction = 0.5 * distanceXM * distanceYM;
183 volumeFraction /= _converter.getPhysDeltaX() * _converter.getPhysDeltaX();
184 if (!cornerXPYP_inside[0]) {
185 volumeFraction = 1.0 - volumeFraction;
186 }
187 }
188
189 if (distanceXM < _converter.getPhysDeltaX() && distanceYP < _converter.getPhysDeltaX()) {
190 volumeFraction = 0.5 * (_converter.getPhysDeltaX() - distanceXM) * (_converter.getPhysDeltaX() - distanceYP);
191 volumeFraction /= _converter.getPhysDeltaX() * _converter.getPhysDeltaX();
192 if (!cornerXMYP_inside[0]) {
193 volumeFraction = 1.0 - volumeFraction;
194 }
195 }
196
197 if (distanceYM < _converter.getPhysDeltaX() && distanceXP < _converter.getPhysDeltaX()) {
198 volumeFraction = 0.5 * (_converter.getPhysDeltaX() - distanceXP) * (_converter.getPhysDeltaX() - distanceYM);
199 volumeFraction /= _converter.getPhysDeltaX() * _converter.getPhysDeltaX();
200 if (!cornerXPYM_inside[0]) {
201 volumeFraction = 1.0 - volumeFraction;
202 }
203 }
204
205 if (!_insideOut) {
206 output[0] = volumeFraction;
207 }
208 else {
209 output[0] = 1.0 - volumeFraction;
210 }
211
212 }
213 return true;
214}
215
216}
217#endif
Representation of a block geometry.
represents all functors that operate on a DESCRIPTOR in general, e.g. getVelocity(),...
functor returns pointwise an approximation for the volume fraction
bool operator()(T output[], const int input[])
has to be implemented for 'every' derived class
BlockLatticeVolumeFractionPolygonApproximation2D(BlockLattice< T, DESCRIPTOR > &blockLattice, BlockGeometry< T, 2 > &blockGeometry, IndicatorF2D< T > &indicator, const UnitConverter< T, DESCRIPTOR > &converter, bool insideOut)
Platform-abstracted block lattice for external access and inter-block interaction.
std::string & getName()
read and write access to name
Definition genericF.hh:51
IndicatorF2D is an application from .
std::vector< std::unique_ptr< BlockF2D< T > > > _blockF
Super functors may consist of several BlockF2D<W> derived functors.
Representation of a statistic for a parallel 2D geometry.
BlockGeometry< T, D > & getBlockGeometry(int locIC)
Read and write access to a single block geometry.
represents all functors that operate on a SuperLattice in general, e.g. getVelocity(),...
SuperLattice< T, DESCRIPTOR > & _sLattice
SuperLatticeVolumeFractionPolygonApproximation2D(SuperLattice< T, DESCRIPTOR > &sLattice, SuperGeometry< T, 2 > &superGeometry, IndicatorF2D< T > &indicator, const UnitConverter< T, DESCRIPTOR > &converter, bool insideOut=false)
Super class maintaining block lattices for a cuboid decomposition.
Conversion between physical and lattice units, as well as discretization.
Plain old scalar vector.
Definition vector.h:47
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.