Skip to content
Snippets Groups Projects
Commit 5c8bc357 authored by Anna Wellmann's avatar Anna Wellmann
Browse files

Add Cylinder that can have its axis in all main directions

parent 0eeaa402
No related branches found
No related tags found
1 merge request!307[GPU] Add a cylinder geometry
#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
//=======================================================================================
// ____ ____ __ ______ __________ __ __ __ __
// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
// \ \ | | | | | |_) | | | | | | | / \ | |
// \ \ | | | | | _ / | | | | | | / /\ \ | |
// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
// \ \ | | ________________________________________________________________
// \ \ | | | ______________________________________________________________|
// \ \| | | | __ __ __ __ ______ _______
// \ | | |_____ | | | | | | | | | _ \ / _____)
// \ | | _____| | | | | | | | | | | \ \ \_______
// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
// \ _____| |__| |________| \_______/ |__| |______/ (_______/
//
// 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
#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
......@@ -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;
......
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment