OpenLB 1.7
Loading...
Searching...
No Matches
indicatorBaseF3D.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2014-2016 Cyril Masquelier, Albert Mink, Mathias J. Krause, Benjamin Förster
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 INDICATOR_BASE_F_3D_H
25#define INDICATOR_BASE_F_3D_H
26
27#include <functional>
28#include <vector>
29
30#include "core/vector.h"
31#include "functors/genericF.h"
32#include "indicatorBase.h"
33
34namespace olb {
35
36
41template <typename S>
42class IndicatorF3D : public GenericF<bool,S> {
43protected:
47public:
48 virtual Vector<S,3>& getMin();
49 virtual Vector<S,3>& getMax();
53 virtual bool distance(S& distance, const Vector<S,3>& origin, S precision, const Vector<S,3>& direction);
54 virtual bool distance(S& distance, const Vector<S,3>& origin, const Vector<S,3>& direction, S precision, S pitch);
55 virtual bool distance(S& distance, const Vector<S,3>& origin, const Vector<S,3>& direction, int iC=-1);
56 virtual bool distance(S& distance, const Vector<S,3>& origin);
57 virtual bool distance(S& distance, const S input[]);
59
62 virtual bool normal(Vector<S,3>& normal, const Vector<S,3>& origin, const Vector<S,3>& direction, int iC=-1);
64 virtual bool rotOnAxis(Vector<S,3>& vec_rot, const Vector<S,3>& vec, const Vector<S,3>& axis, S& theta);
66 virtual bool operator() (bool output[1], const S input[3]);
68 virtual S signedDistance(const Vector<S,3>& input);
70 virtual Vector<S,3> surfaceNormal(const Vector<S,3>& pos, const S meshSize);
72 Vector<S,3> surfaceNormal(const Vector<S,3>& pos, const S meshSize,
73 std::function<Vector<S,3>(const Vector<S,3>&)> transformPos);
75 bool isInsideBox(Vector<S,3> point);
76
77 // Returns random position in indicator domain
81 virtual Vector<S,3> getSample(const std::function<S()>& randomness) const {
82 throw std::runtime_error("Indicator doesn't support random sampling");
83 }
84};
85
86template <typename S>
88private:
89 IndicatorF3D<S>& _indicatorF;
90 const S _deltaR;
91
92 Cuboid3D<S> _cacheCuboid;
93 BlockStructureD<3> _cacheBlock;
95
96public:
98 _indicatorF(indicatorF),
99 _deltaR(deltaR),
100 _cacheCuboid(indicatorF.getMin()[0], indicatorF.getMin()[1], indicatorF.getMin()[2], deltaR,
101 (int)((indicatorF.getMax()[0] - indicatorF.getMin()[0]) / deltaR + 1.5),
102 (int)((indicatorF.getMax()[1] - indicatorF.getMin()[1]) / deltaR + 1.5),
103 (int)((indicatorF.getMax()[2] - indicatorF.getMin()[2]) / deltaR + 1.5)),
104 _cacheBlock(_cacheCuboid.getExtent(), 0),
105 _cache(_cacheBlock.getNcells())
106 { }
107
108 bool operator() (bool output[1], const S input[3]) override {
109 Vector<int,3> latticeR{};
110 if (_cacheCuboid.getLatticeR(input, latticeR)) {
111 std::size_t iCell = _cacheBlock.getCellId(latticeR);
112 if (_cache[iCell] == 0) {
113 bool result;
114 _indicatorF(&result, input);
115 _cache[iCell] = result ? 1 : 2;
116 output[0] = result;
117 return true;
118 } else {
119 output[0] = _cache[iCell] == 1;
120 return true;
121 }
122 } else {
123 return _indicatorF(output, input);
124 }
125 }
126
127 bool save(std::string fileName) {
128 return _cache.save(fileName);
129 }
130 bool load(std::string fileName) {
131 return _cache.load(fileName);
132 }
133
134 Vector<S,3>& getMin() override {
135 return _indicatorF.getMin();
136 }
137 Vector<S,3>& getMax() override {
138 return _indicatorF.getMax();
139 }
140 bool distance(S& distance, const Vector<S,3>& origin, S precision, const Vector<S,3>& direction) override {
141 return _indicatorF.distance(distance, origin, precision, direction);
142 }
143 bool distance(S& distance, const Vector<S,3>& origin, const Vector<S,3>& direction, S precision, S pitch) override {
144 return _indicatorF.distance(distance, origin, direction, precision, pitch);
145 }
146 bool distance(S& distance, const Vector<S,3>& origin, const Vector<S,3>& direction, int iC=-1) override {
147 return _indicatorF.distance(distance, origin, direction, iC);
148 }
149 bool distance(S& distance, const Vector<S,3>& origin) override {
150 return _indicatorF.distance(distance, origin);
151 }
152 bool distance(S& distance, const S input[]) override {
153 return _indicatorF.distance(distance, input);
154 }
155 bool normal(Vector<S,3>& normal, const Vector<S,3>& origin, const Vector<S,3>& direction, int iC=-1) override {
156 return _indicatorF.normal(normal, origin, direction, iC);
157 }
158 bool rotOnAxis(Vector<S,3>& vec_rot, const Vector<S,3>& vec, const Vector<S,3>& axis, S& theta) override {
159 return _indicatorF.rotOnAxis(vec_rot, vec, axis, theta);
160 }
161
162 S signedDistance(const Vector<S,3>& input) override {
163 return _indicatorF.signedDistance(input);
164 }
165 Vector<S,3> surfaceNormal(const Vector<S,3>& pos, const S meshSize) override {
166 return _indicatorF.surfaceNormal(pos, meshSize);
167 }
168
169};
170
171template <typename S>
173public:
174 std::shared_ptr<IndicatorF3D<S>> _f;
175
176 IndicatorIdentity3D(std::shared_ptr<IndicatorF3D<S>> f);
177 bool operator() (bool output[1], const S input[3]);
178};
179
180
181}
182
183#endif
Base of a regular block.
CellID getCellId(LatticeR< D > latticeR) const
Get 1D cell ID.
A regular single 3D cuboid is the basic component of a 3D cuboid structure which defines the grid.
Definition cuboid3D.h:58
bool getLatticeR(Vector< T, 3 > physR, Vector< int, 3 > &latticeR, T eps=1e-5)
Definition cuboid3D.h:128
GenericF is a base class, that can represent continuous as well as discrete functions.
Definition genericF.h:50
IndicatorF3D is an application from .
virtual bool operator()(bool output[1], const S input[3])
Returns true if input is inside the indicator.
virtual bool distance(S &distance, const Vector< S, 3 > &origin, S precision, const Vector< S, 3 > &direction)
virtual Vector< S, 3 > & getMax()
Vector< S, 3 > _myMin
virtual Vector< S, 3 > & getMin()
virtual bool normal(Vector< S, 3 > &normal, const Vector< S, 3 > &origin, const Vector< S, 3 > &direction, int iC=-1)
returns true and the normal if there was one found for an given origin and direction
bool isInsideBox(Vector< S, 3 > point)
Returns true if point is inside a cube with corners _myMin and _myMax
virtual S signedDistance(const Vector< S, 3 > &input)
Returns signed distance to the nearest point on the indicator surface.
virtual Vector< S, 3 > surfaceNormal(const Vector< S, 3 > &pos, const S meshSize)
Return surface normal.
virtual Vector< S, 3 > getSample(const std::function< S()> &randomness) const
virtual bool rotOnAxis(Vector< S, 3 > &vec_rot, const Vector< S, 3 > &vec, const Vector< S, 3 > &axis, S &theta)
Rotate vector around axis by angle theta.
Vector< S, 3 > _myMax
IndicatorIdentity3D(std::shared_ptr< IndicatorF3D< S > > f)
bool operator()(bool output[1], const S input[3])
Returns true if input is inside the indicator.
std::shared_ptr< IndicatorF3D< S > > _f
bool distance(S &distance, const S input[]) override
Vector< S, 3 > & getMin() override
bool distance(S &distance, const Vector< S, 3 > &origin) override
Vector< S, 3 > surfaceNormal(const Vector< S, 3 > &pos, const S meshSize) override
Return surface normal.
bool rotOnAxis(Vector< S, 3 > &vec_rot, const Vector< S, 3 > &vec, const Vector< S, 3 > &axis, S &theta) override
Rotate vector around axis by angle theta.
bool load(std::string fileName)
bool operator()(bool output[1], const S input[3]) override
Returns true if input is inside the indicator.
RegularCachedIndicatorF3D(IndicatorF3D< S > &indicatorF, S deltaR)
S signedDistance(const Vector< S, 3 > &input) override
Returns signed distance to the nearest point on the indicator surface.
bool save(std::string fileName)
bool distance(S &distance, const Vector< S, 3 > &origin, const Vector< S, 3 > &direction, int iC=-1) override
bool distance(S &distance, const Vector< S, 3 > &origin, S precision, const Vector< S, 3 > &direction) override
bool normal(Vector< S, 3 > &normal, const Vector< S, 3 > &origin, const Vector< S, 3 > &direction, int iC=-1) override
returns true and the normal if there was one found for an given origin and direction
bool distance(S &distance, const Vector< S, 3 > &origin, const Vector< S, 3 > &direction, S precision, S pitch) override
Vector< S, 3 > & getMax() override
bool save(std::string fileName="", const bool enforceUint=false)
Save Serializable into file fileName
bool load(std::string fileName="", const bool enforceUint=false)
Load Serializable from file fileName
Plain old scalar vector.
Definition vector.h:47
Plain column for SISD CPU targets (default)
Definition column.h:45
The description of a generic interface for all functor classes – header file.
Top level namespace for all of OpenLB.
efficient implementation of a vector class