summaryrefslogtreecommitdiff
path: root/src/functors/analytical/indicator/indicatorF3D.h
blob: 17f0f92d0b2f1b993457b2d625f8b4dd5b35c257 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*  This file is part of the OpenLB library
 *
 *  Copyright (C) 2014-2016 Cyril Masquelier, Mathias J. Krause, Albert Mink
 *  E-mail contact: info@openlb.net
 *  The most recent release of OpenLB can be downloaded at
 *  <http://www.openlb.net/>
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public
 *  License along with this program; if not, write to the Free
 *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA  02110-1301, USA.
*/

#ifndef INDICATOR_F_3D_H
#define INDICATOR_F_3D_H

#include<vector>
#include "indicatorBaseF3D.h"
#include "io/xmlReader.h"


/** \file
 * This file contains indicator functions. These return 1 if the given
 * coordinates are inside, and 0 if they are outside of the defined set.
 * Implemented are :
 - Sphere
 - Cylinder
 - Cone
 - Pipe (not yet)
 - Cube (not yet)
 - Cuboid
 - Circle

 * The smoothIndicator functors return values in [0,1]. In particular there is
 * an epsilon enclosure of the set, wherein the return values are smooth and do
 * not jump from 0 to 1.

 Boolean operators allow to create unions and intersections. They can be used
 for example for initialization of a SuperGeometry.
*/

namespace olb {


template <typename S>
class IndicatorTranslate3D : public IndicatorF3D<S> {
private:
  std::array<S,3> _translate;
  IndicatorF3D<S>& _indicator;
public:
  IndicatorTranslate3D(std::array<S,3> translate, IndicatorF3D<S>& indicator);
  bool operator() (bool output[], const S input[]) override;
};


/// indicator function for a 3D circle
template <typename S>
class IndicatorCircle3D : public IndicatorF3D<S> {
private:
  Vector<S,3> _center;
  Vector<S,3> _normal;
  S _radius2;
public:
  IndicatorCircle3D(Vector<S,3> center, Vector<S,3> normal, S radius);
  IndicatorCircle3D(S center0, S center1, S center2, S normal0, S normal1,
                    S normal2, S radius);
  bool operator() (bool output[], const S input[]) override;
  Vector<S,3> const& getCenter() const;
  Vector<S,3> const& getNormal() const;
  S getRadius() const;
  //virtual bool distance(S& distance, Vector<S,3> origin, Vector<S,3> direction, int iC=-1);
};



/// indicator function for a 3D-sphere
template <typename S>
class IndicatorSphere3D : public IndicatorF3D<S> {
private:
  Vector<S,3> _center;
  S _radius2;
public:
  IndicatorSphere3D(Vector<S,3> center, S radius);
  IndicatorSphere3D(const IndicatorSphere3D&);
  bool operator() (bool output[], const S input[]) override;
  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);
};

/// indicator function for a layer
template <typename S>
class IndicatorLayer3D : public IndicatorF3D<S> {
private:
  IndicatorF3D<S>& _indicatorF;
  S _layerSize;
public:
  IndicatorLayer3D(IndicatorF3D<S>& indicatorF, S layerSize);
  bool operator() (bool output[], const S input[]) override;
};

/// indicator function for the internal part of an input indicator
template <typename S>
class IndicatorInternal3D : public IndicatorF3D<S> {
private:
  IndicatorF3D<S>& _indicatorF;
  S _layerSize;
public:
  IndicatorInternal3D(IndicatorF3D<S>& indicatorF, S layerSize);
  bool operator() (bool output[], const S input[]) override;
};

/// indicator function for a 3d-cylinder
template <typename S>
class IndicatorCylinder3D : public IndicatorF3D<S> {
private:
  Vector<S,3> _center1;
  Vector<S,3> _center2;
  Vector<S,3> _I;
  Vector<S,3> _J;
  Vector<S,3> _K;
  S _length;
  S _radius2;
  void init();
public:
  IndicatorCylinder3D(Vector<S,3> center1, Vector<S,3> center2, S radius);
  // eps is length of cylinder
  IndicatorCylinder3D(Vector<S,3> center1, Vector<S,3> normal, S radius, S eps);
  IndicatorCylinder3D(IndicatorCircle3D<S> const& circleF, S eps);
  bool operator() (bool output[], const S input[]) override;
  Vector<S,3> const& getCenter1() const;
  Vector<S,3> const& getCenter2() const;
  S getRadius() const;
};

/// indicator function for a 3d frustum
template <typename S>
class IndicatorCone3D : public IndicatorF3D<S> {
private:
  Vector<S,3> _center1;
  Vector<S,3> _center2;
  Vector<S,3> _I;
  Vector<S,3> _J;
  Vector<S,3> _K;
  S _length;
  S _radius1;
  S _radius2; // The 2nd radius is optional: if not defined, _center2 is the vertex of the cone
public:
  IndicatorCone3D(Vector<S,3> center1, Vector<S,3> center2, S radius1, S radius2=0);
  bool operator() (bool output[], const S input[]) override;
};

/** indicator function for a 3d-cuboid, parallel to the planes x=0, y=0, z=0.
 * \param extend must have only positive elements
 * \param xLength must be positive
 */
template <typename S>
class IndicatorCuboid3D : public IndicatorF3D<S> {
private:
  const Vector<S,3> _center;
  const S _xLength;
  const S _yLength;
  const S _zLength;
public:
  /// constructs an cuboid with x axis dimension 0 to extend[0], ...
  IndicatorCuboid3D(Vector<S,3> extend, Vector<S,3> origin);
  /// constructs an cuboid with x axis dimension -xlength/2 to xlength/2
  IndicatorCuboid3D(S xlength, S ylength, S zlength, Vector<S,3> center);
  /// returns true if input is inside, otherwise false
  bool operator() (bool output[], const S input[]) override;
};


/** \brief indicator function for a 3d-cuboid, turned by an angle theta around an axis of rotation
 *
 * The cuboid is turned along the axis going through the point "centerRotation" and being orthogonal to either x=0 or y=0 or z=0 respectively
 * \param theta angle (rad) by which the cuboid is turned
 * \param plane the axis of rotation is orthogonal to the plane i=0, where 0 corresponds to the plane x=0, 1 to the plane y=0, and 2 to z=0
 * \param centerRotation vector of coordinates which defines, with "plane", the axis of rotation; centerRotation is a point on th axis of rotation
 *
 */
template <typename S>
class IndicatorCuboidRotate3D : public IndicatorCuboid3D<S> {
private:
    S _theta;
    int _plane;
    Vector<S,3> _centerRotation;
public:
    // constructs an cuboid turned by some angle theta around a given center of rotation
    IndicatorCuboidRotate3D(Vector<S,3> extend, Vector<S,3> origin, S theta, int plane, Vector<S,3> centerRotation);
    IndicatorCuboidRotate3D(S xlength, S ylength, S zlength, Vector<S,3> origin, S theta, int plane, Vector<S,3> centerRotation);
    bool operator() (bool output[], const S input[]);
};

/////////creatorFunctions//////////////////////
// creator function for geometric primitives
template <typename S>
std::shared_ptr<IndicatorF3D<S>> createIndicatorCircle3D(XMLreader const& params, bool verbose=false);

template <typename S>
std::shared_ptr<IndicatorF3D<S>> createIndicatorSphere3D(XMLreader const& params, bool verbose=false);

template <typename S>
std::shared_ptr<IndicatorF3D<S>> createIndicatorCylinder3D(XMLreader const& params, bool verbose=false);

template <typename S>
std::shared_ptr<IndicatorF3D<S>> createIndicatorCone3D(XMLreader const& params, bool verbose=false);

template <typename S>
std::shared_ptr<IndicatorF3D<S>> createIndicatorCuboid3D(XMLreader const& params, bool verbose=false);

// arithmetic creator functions
template <typename S>
std::shared_ptr<IndicatorF3D<S>> createIndicatorUnion3D(XMLreader const& params, bool verbose=false);

template <typename S>
std::shared_ptr<IndicatorF3D<S>> createIndicatorWithout3D(XMLreader const& params, bool verbose=false);

template <typename S>
std::shared_ptr<IndicatorF3D<S>> createIndicatorIntersection3D(XMLreader const&params, bool verbose=false);

// godfather
template <typename S>
std::shared_ptr<IndicatorF3D<S>> createIndicatorF3D(XMLreader const& params, bool verbose=false);



}

#endif