VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
Cylinder.cpp
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
32//=======================================================================================
33#include "Cylinder.h"
34#include "UbEqual.h"
35#include <numeric>
36
37using namespace axis;
38
39namespace vf::gpu {
40
41Cylinder::Cylinder(double centerX, double centerY, double centerZ, double radius, double height, Axis rotationalAxis)
42 : center({ centerX, centerY, centerZ }), radius(radius), height(height), rotationalAxis(rotationalAxis)
43{
44}
45
46Cylinder::Cylinder(std::array<double, 3> center, double radius, double height, Axis axis)
47 : center(center), radius(radius), height(height), rotationalAxis(axis)
48{
49}
50
51Cylinder::Cylinder(std::array<double, 3> minOfAxis, std::array<double, 3> maxOfAxis, double radius)
52 : center(calculateCenter(minOfAxis, maxOfAxis)), radius(radius)
53{
54 std::array<double, 3> differencesBetweenAxisCoords;
55 std::transform(maxOfAxis.begin(), maxOfAxis.end(), minOfAxis.begin(), differencesBetweenAxisCoords.begin(),
56 std::minus<>());
57
58 std::function isNotZero = [](double number) { return !isUbEqual<double, double>(number, 0.); };
59
60 // when the cylinder is parallel to an axis, the difference between min and max is non-zero in exactly one direction
64 throw std::runtime_error("The cylinder is not parallel to one axis. This is currently not supported");
65 }
66
67 this->rotationalAxis =
68 static_cast<Axis>(std::find_if(differencesBetweenAxisCoords.begin(), differencesBetweenAxisCoords.end(), isNotZero) -
70 this->height = std::abs(differencesBetweenAxisCoords.at(rotationalAxis)); // absolute value to handle swapped min and max
71}
72
73std::array<double, 3> Cylinder::calculateCenter(const std::array<double, 3>& minOfAxis,
74 const std::array<double, 3>& maxOfAxis)
75{
76 return { 0.5 * (maxOfAxis[0] + minOfAxis[0]),
77 0.5 * (maxOfAxis[1] + minOfAxis[1]),
78 0.5 * (maxOfAxis[2] + minOfAxis[2]) };
79}
80
82{
83 return std::make_shared<Cylinder>(center, radius, height, rotationalAxis);
84}
85
86double Cylinder::getCentroidCoordinate(Axis coordinateDirection) const
87{
88 return center.at(coordinateDirection);
89}
90
91double Cylinder::getMinimunCoordinate(Axis coordinateDirection) const
92{
93 const auto unitVector = unitVectors.at(rotationalAxis);
94 return center.at(coordinateDirection) - 0.5 * height * unitVector.at(coordinateDirection) +
95 radius * (unitVector.at(coordinateDirection) - 1);
96}
97
98double Cylinder::getMaximumCoordinate(Axis coordinateDirection) const
99{
100 const auto unitVector = unitVectors.at(rotationalAxis);
101 return center.at(coordinateDirection) + 0.5 * height * unitVector.at(coordinateDirection) -
102 radius * (unitVector.at(coordinateDirection) - 1);
103}
104
106{
107 return getCentroidCoordinate(x);
108}
109
111{
112 return getMinimunCoordinate(x);
113}
114
116{
117 return getMaximumCoordinate(x);
118}
119
121{
122 return getCentroidCoordinate(y);
123}
124
126{
127 return getMinimunCoordinate(y);
128}
129
131{
132 return getMaximumCoordinate(y);
133}
134
136{
137 return getCentroidCoordinate(z);
138}
139
141{
142 return getMinimunCoordinate(z);
143}
144
146{
147 return getMaximumCoordinate(z);
148}
149
151{
152 return radius;
153}
154
156{
157 return height;
158}
159
161{
162 return rotationalAxis;
163}
164
165bool Cylinder::isInCircle(double delta1, double delta2, double offset) const
166{
167 return (delta1 * delta1 + delta2 * delta2) < ((this->radius - offset) * (this->radius - offset));
168}
169
170bool Cylinder::isPointInObject(const double &x1, const double &x2, const double &x3, const double &minOffset,
171 const double &maxOffset)
172{
173 double offset = maxOffset;
174 if (x1 < center.at(x) || x2 < center.at(y) || x3 < center.at(z)) offset = minOffset;
175
176 const double deltaX1 = x1 - center.at(x);
177 const double deltaX2 = x2 - center.at(y);
178 const double deltaX3 = x3 - center.at(z);
179
180 switch (rotationalAxis) {
181 case x:
182 if (deltaX1 > 0.5 * height || deltaX1 < -0.5 * height) return false;
183 return isInCircle(deltaX2, deltaX3, offset);
184 case y:
185 if (deltaX2 > 0.5 * height || deltaX2 < -0.5 * height) return false;
186 return isInCircle(deltaX1, deltaX3, offset);
187 case z:
188 if (deltaX3 > 0.5 * height || deltaX3 < -0.5 * height) return false;
189 return isInCircle(deltaX1, deltaX2, offset);
190 }
191
192 VF_LOG_CRITICAL("Unknown rotational axis in Cylinder.");
193 return false;
194}
195
197{
198 this->radius += delta;
199 this->height += 2 * delta;
200}
201
202}
#define VF_LOG_CRITICAL(...)
Definition Logger.h:52
double getX1Centroid() const override
Definition Cylinder.cpp:105
double getHeight() const
Definition Cylinder.cpp:155
double getRadius() const
Definition Cylinder.cpp:150
double getX2Maximum() const override
Definition Cylinder.cpp:130
void changeSizeByDelta(double delta) override
Definition Cylinder.cpp:196
double getX2Minimum() const override
Definition Cylinder.cpp:125
bool isPointInObject(const double &x1, const double &x2, const double &x3, const double &minOffset, const double &maxOffset) override
Definition Cylinder.cpp:170
double getX1Minimum() const override
Definition Cylinder.cpp:110
double getX1Maximum() const override
Definition Cylinder.cpp:115
Axis getRotationalAxis() const
Definition Cylinder.cpp:160
double getX2Centroid() const override
Definition Cylinder.cpp:120
SPtr< Object > clone() const override
Definition Cylinder.cpp:81
Cylinder(double centerX, double centerY, double centerZ, double radius, double height, Axis rotationalAxis)
Definition Cylinder.cpp:41
double getX3Minimum() const override
Definition Cylinder.cpp:140
double getX3Maximum() const override
Definition Cylinder.cpp:145
double getX3Centroid() const override
Definition Cylinder.cpp:135
std::shared_ptr< T > SPtr
Axis
Definition Axis.h:41
@ z
Definition Axis.h:44
@ x
Definition Axis.h:42
@ y
Definition Axis.h:43
Definition Axis.h:48
const std::map< Axis, std::array< double, 3 > > unitVectors
Definition Axis.h:50