diff --git a/src/gpu/GridGenerator/geometries/Cylinder/Cylinder.cpp b/src/gpu/GridGenerator/geometries/Cylinder/Cylinder.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ed7a2f04eb62b4596332060bb0f6fa2bc460e32a --- /dev/null +++ b/src/gpu/GridGenerator/geometries/Cylinder/Cylinder.cpp @@ -0,0 +1,93 @@ +#include "Cylinder.h" +#include <numeric> + +Cylinder::Cylinder(double centerX, double centerY, double centerZ, double radius, double height, PrincipalAxis axis) + : center({ centerX, centerY, centerZ }), radius(radius), height(height), principalAxis(axis) +{ +} + +Cylinder::Cylinder(std::array<double, 3> center, double radius, double height, PrincipalAxis axis) + : center(center), radius(radius), height(height), principalAxis(axis) +{ +} + +SPtr<Object> Cylinder::clone() const +{ + return std::make_shared<Cylinder>(center, radius, height, principalAxis); +} + +double Cylinder::getCentroidCoordinate(PrincipalAxis coordinateDirection) const +{ + return center.at(coordinateDirection); +} + +double Cylinder::getMinimunCoordinate(PrincipalAxis coordinateDirection) const +{ + const auto unitVector = unitVectors.at(principalAxis); + return center.at(coordinateDirection) - 0.5 * height * unitVector.at(coordinateDirection) + + radius * (unitVector.at(coordinateDirection) - 1); +} + +double Cylinder::getMaximumCoordinate(PrincipalAxis coordinateDirection) const +{ + const auto unitVector = unitVectors.at(principalAxis); + return center.at(coordinateDirection) + 0.5 * height * unitVector.at(coordinateDirection) - + radius * (unitVector.at(coordinateDirection) - 1); +} + +double Cylinder::getX1Centroid() +{ + return getCentroidCoordinate(x); +} + +double Cylinder::getX1Minimum() +{ + return getMinimunCoordinate(x); +} + +double Cylinder::getX1Maximum() +{ + return getMaximumCoordinate(x); +} + +double Cylinder::getX2Centroid() +{ + return getCentroidCoordinate(y); +} + +double Cylinder::getX2Minimum() +{ + return getMinimunCoordinate(y); +} + +double Cylinder::getX2Maximum() +{ + return getMaximumCoordinate(y); +} + +double Cylinder::getX3Centroid() +{ + return getCentroidCoordinate(z); +} + +double Cylinder::getX3Minimum() +{ + return getMinimunCoordinate(z); +} + +double Cylinder::getX3Maximum() +{ + return getMaximumCoordinate(z); +} + +////////////////// #TODO + +bool Cylinder::isPointInObject(const double& x1, const double& x2, const double& x3, const double& minOffset, const double& maxOffset) +{ + return false; +} + + +void Cylinder::scale(double delta) +{ +} \ No newline at end of file diff --git a/src/gpu/GridGenerator/geometries/Cylinder/Cylinder.h b/src/gpu/GridGenerator/geometries/Cylinder/Cylinder.h new file mode 100644 index 0000000000000000000000000000000000000000..0bbb22ab22de07cb1a90f5aca08d36c0b687167c --- /dev/null +++ b/src/gpu/GridGenerator/geometries/Cylinder/Cylinder.h @@ -0,0 +1,86 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids 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 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file Cylinder.h +//! \ingroup geometries +//! \author Anna Wellmann +//======================================================================================= + + +#ifndef CYLINDER_H +#define CYLINDER_H + +#include "geometries/Object.h" +#include <basics/geometry3d/GbCylinder3D.h> +#include <map> + +class GRIDGENERATOR_EXPORT Cylinder : public Object +{ +public: + enum PrincipalAxis { + x = 0, + y = 1, + z = 2, + }; + + Cylinder(double centerX, double centerY, double centerZ, double radius, double height, PrincipalAxis axis); + Cylinder(std::array<double, 3> center, double radius, double height, PrincipalAxis axis); + + SPtr<Object> clone() const override; + + double getX1Centroid() override; + double getX1Minimum() override; + double getX1Maximum() override; + double getX2Centroid() override; + double getX2Minimum() override; + double getX2Maximum() override; + double getX3Centroid() override; + double getX3Minimum() override; + double getX3Maximum() override; + + bool isPointInObject(const double &x1, const double &x2, const double &x3, const double &minOffset, + const double &maxOffset) override; + void scale(double delta) override; + +private: + double getCentroidCoordinate(PrincipalAxis coordinateDirection) const; + double getMinimunCoordinate(PrincipalAxis coordinateDirection) const; + double getMaximumCoordinate(PrincipalAxis coordinateDirection) const; + + const std::map<PrincipalAxis, std::array<double, 3>> unitVectors{ { x, { 1, 0, 0 } }, + { y, { 0, 1, 0 } }, + { z, { 0, 0, 1 } } }; + + PrincipalAxis principalAxis; + const std::array<double, 3> center; + + double radius; + double height; +}; + +#endif \ No newline at end of file diff --git a/src/gpu/GridGenerator/geometries/Cylinder/CylinderTest.cpp b/src/gpu/GridGenerator/geometries/Cylinder/CylinderTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..32e6fcc1e47e069e0a36847a5bb0a6b470eab9df --- /dev/null +++ b/src/gpu/GridGenerator/geometries/Cylinder/CylinderTest.cpp @@ -0,0 +1,90 @@ +#include <gmock/gmock.h> + +#include "Cylinder.h" + +// CylinderTestAxisNormalToX //////////////////////////////////////////////// + +class CylinderTestAxisNormalToX : public testing::Test +{ +protected: + Cylinder cylinder = Cylinder({ 0.1, 0.2, 0.3 }, 2.0, 8.0, Cylinder::PrincipalAxis::x); +}; + +TEST_F(CylinderTestAxisNormalToX, getCentroid) +{ + EXPECT_THAT(cylinder.getX1Centroid(), testing::Eq(0.1)); + EXPECT_THAT(cylinder.getX2Centroid(), testing::Eq(0.2)); + EXPECT_THAT(cylinder.getX3Centroid(), testing::Eq(0.3)); +} + +TEST_F(CylinderTestAxisNormalToX, getMinimum) +{ + EXPECT_THAT(cylinder.getX1Minimum(), testing::Eq(-4.0 + 0.1)); + EXPECT_THAT(cylinder.getX2Minimum(), testing::Eq(-2.0 + 0.2)); + EXPECT_THAT(cylinder.getX3Minimum(), testing::Eq(-2.0 + 0.3)); +} + +TEST_F(CylinderTestAxisNormalToX, getMaximum) +{ + EXPECT_THAT(cylinder.getX1Maximum(), testing::Eq(4.0 + 0.1)); + EXPECT_THAT(cylinder.getX2Maximum(), testing::Eq(2.0 + 0.2)); + EXPECT_THAT(cylinder.getX3Maximum(), testing::Eq(2.0 + 0.3)); +} + +// CylinderTestAxisNormalToY //////////////////////////////////////////////// + +class CylinderTestAxisNormalToY : public testing::Test +{ +protected: + Cylinder cylinder = Cylinder({ 0.1, 0.2, 0.3 }, 2.0, 8.0, Cylinder::PrincipalAxis::y); +}; + +TEST_F(CylinderTestAxisNormalToY, getCentroid) +{ + EXPECT_THAT(cylinder.getX1Centroid(), testing::Eq(0.1)); + EXPECT_THAT(cylinder.getX2Centroid(), testing::Eq(0.2)); + EXPECT_THAT(cylinder.getX3Centroid(), testing::Eq(0.3)); +} + +TEST_F(CylinderTestAxisNormalToY, getMinimum) +{ + EXPECT_THAT(cylinder.getX1Minimum(), testing::Eq(-2.0 + 0.1)); + EXPECT_THAT(cylinder.getX2Minimum(), testing::Eq(-4.0 + 0.2)); + EXPECT_THAT(cylinder.getX3Minimum(), testing::Eq(-2.0 + 0.3)); +} + +TEST_F(CylinderTestAxisNormalToY, getMaximum) +{ + EXPECT_THAT(cylinder.getX1Maximum(), testing::Eq(2.0 + 0.1)); + EXPECT_THAT(cylinder.getX2Maximum(), testing::Eq(4.0 + 0.2)); + EXPECT_THAT(cylinder.getX3Maximum(), testing::Eq(2.0 + 0.3)); +} + +// CylinderTestAxisNormalToZ //////////////////////////////////////////////// + +class CylinderTestAxisNormalToZ : public testing::Test +{ +protected: + Cylinder cylinder = Cylinder({ 0.1, 0.2, 0.3 }, 2.0, 8.0, Cylinder::PrincipalAxis::z); +}; + +TEST_F(CylinderTestAxisNormalToZ, getCentroid) +{ + EXPECT_THAT(cylinder.getX1Centroid(), testing::Eq(0.1)); + EXPECT_THAT(cylinder.getX2Centroid(), testing::Eq(0.2)); + EXPECT_THAT(cylinder.getX3Centroid(), testing::Eq(0.3)); +} + +TEST_F(CylinderTestAxisNormalToZ, getMinimum) +{ + EXPECT_THAT(cylinder.getX1Minimum(), testing::Eq(-2.0 + 0.1)); + EXPECT_THAT(cylinder.getX2Minimum(), testing::Eq(-2.0 + 0.2)); + EXPECT_THAT(cylinder.getX3Minimum(), testing::Eq(-4.0 + 0.3)); +} + +TEST_F(CylinderTestAxisNormalToZ, getMaximum) +{ + EXPECT_THAT(cylinder.getX1Maximum(), testing::Eq(2.0 + 0.1)); + EXPECT_THAT(cylinder.getX2Maximum(), testing::Eq(2.0 + 0.2)); + EXPECT_THAT(cylinder.getX3Maximum(), testing::Eq(4.0 + 0.3)); +} \ No newline at end of file diff --git a/src/gpu/GridGenerator/geometries/VerticalCylinder/VerticalCylinder.h b/src/gpu/GridGenerator/geometries/VerticalCylinder/VerticalCylinder.h index 8e4fae42ba4b18be725f8b7abe06b0fbffc417f7..b6676cdc3f3de9b0222b45651aef3cc1e94219db 100644 --- a/src/gpu/GridGenerator/geometries/VerticalCylinder/VerticalCylinder.h +++ b/src/gpu/GridGenerator/geometries/VerticalCylinder/VerticalCylinder.h @@ -40,6 +40,7 @@ class GRIDGENERATOR_EXPORT VerticalCylinder : public Object { public: VerticalCylinder(const double& centerX, const double& centerY, const double& centerZ, const double& radius, const double& height); + // the axis is in the z-direction static SPtr<VerticalCylinder> makeShared(double centerX, double centerY, double centerZ, double radius, double height); @@ -62,7 +63,7 @@ public: void scale(double delta) override; - + protected: double centerX; double centerY; diff --git a/src/gpu/GridGenerator/geometries/VerticalCylinder/VerticalCylinderTest.cpp b/src/gpu/GridGenerator/geometries/VerticalCylinder/VerticalCylinderTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fd7bccef5f08af821af20030ae6b4ddc961846ce --- /dev/null +++ b/src/gpu/GridGenerator/geometries/VerticalCylinder/VerticalCylinderTest.cpp @@ -0,0 +1,30 @@ +#include <gmock/gmock.h> + +#include "VerticalCylinder.h" + +class VerticalCylinderTest : public testing::Test +{ +protected: + VerticalCylinder cylinder = VerticalCylinder(0.1, 0.2, 0.3, 2.0, 8.0); +}; + +TEST_F(VerticalCylinderTest, getCentroid) +{ + EXPECT_THAT(cylinder.getX1Centroid(), testing::Eq(0.1)); + EXPECT_THAT(cylinder.getX2Centroid(), testing::Eq(0.2)); + EXPECT_THAT(cylinder.getX3Centroid(), testing::Eq(0.3)); +} + +TEST_F(VerticalCylinderTest, getMinimum) +{ + EXPECT_THAT(cylinder.getX1Minimum(), testing::Eq(-2.0 + 0.1)); + EXPECT_THAT(cylinder.getX2Minimum(), testing::Eq(-2.0 + 0.2)); + EXPECT_THAT(cylinder.getX3Minimum(), testing::Eq(-4.0 + 0.3)); +} + +TEST_F(VerticalCylinderTest, getMaximum) +{ + EXPECT_THAT(cylinder.getX1Maximum(), testing::Eq(2.0 + 0.1)); + EXPECT_THAT(cylinder.getX2Maximum(), testing::Eq(2.0 + 0.2)); + EXPECT_THAT(cylinder.getX3Maximum(), testing::Eq(4.0 + 0.3)); +} \ No newline at end of file