Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Defines ObjectType and PointType in GeometricalObjectsBins #11731

Merged
merged 3 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions kratos/spatial_containers/geometrical_objects_bins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ GeometricalObjectsBins::CellType& GeometricalObjectsBins::GetCell(
/***********************************************************************************/
/***********************************************************************************/

BoundingBox<Point> GeometricalObjectsBins::GetCellBoundingBox(
BoundingBox<GeometricalObjectsBins::PointType> GeometricalObjectsBins::GetCellBoundingBox(
const std::size_t I,
const std::size_t J,
const std::size_t K
Expand All @@ -49,7 +49,7 @@ BoundingBox<Point> GeometricalObjectsBins::GetCellBoundingBox(
KRATOS_DEBUG_ERROR_IF(J > mNumberOfCells[1]) << "Index " << J << " is larger than number of cells in y direction : " << mNumberOfCells[1] << std::endl;
KRATOS_DEBUG_ERROR_IF(K > mNumberOfCells[2]) << "Index " << K << " is larger than number of cells in z direction : " << mNumberOfCells[2] << std::endl;

BoundingBox<Point> result;
BoundingBox<PointType> result;

result.GetMinPoint()[0] = mBoundingBox.GetMinPoint()[0] + I * mCellSizes[0];
result.GetMinPoint()[1] = mBoundingBox.GetMinPoint()[1] + J * mCellSizes[1];
Expand All @@ -66,7 +66,7 @@ BoundingBox<Point> GeometricalObjectsBins::GetCellBoundingBox(
/***********************************************************************************/

void GeometricalObjectsBins::SearchInRadius(
const Point& rPoint,
const PointType& rPoint,
const double Radius,
std::vector<ResultType>& rResults
)
Expand Down Expand Up @@ -99,7 +99,7 @@ void GeometricalObjectsBins::SearchInRadius(
/***********************************************************************************/

GeometricalObjectsBins::ResultType GeometricalObjectsBins::SearchNearestInRadius(
const Point& rPoint,
const PointType& rPoint,
const double Radius
)
{
Expand Down Expand Up @@ -140,7 +140,7 @@ GeometricalObjectsBins::ResultType GeometricalObjectsBins::SearchNearestInRadius
/***********************************************************************************/
/***********************************************************************************/

GeometricalObjectsBins::ResultType GeometricalObjectsBins::SearchNearest(const Point& rPoint)
GeometricalObjectsBins::ResultType GeometricalObjectsBins::SearchNearest(const PointType& rPoint)
{
ResultType current_result;

Expand All @@ -153,7 +153,7 @@ GeometricalObjectsBins::ResultType GeometricalObjectsBins::SearchNearest(const P
/***********************************************************************************/
/***********************************************************************************/

GeometricalObjectsBins::ResultType GeometricalObjectsBins::SearchIsInside(const Point& rPoint)
GeometricalObjectsBins::ResultType GeometricalObjectsBins::SearchIsInside(const PointType& rPoint)
{
ResultType current_result;
current_result.SetDistance(std::numeric_limits<double>::max());
Expand Down Expand Up @@ -268,7 +268,7 @@ std::size_t GeometricalObjectsBins::CalculatePosition(

void GeometricalObjectsBins::SearchInRadiusInCell(
const CellType& rCell,
const Point& rPoint,
const PointType& rPoint,
const double Radius,
std::unordered_set<GeometricalObject*>& rResults
)
Expand All @@ -288,7 +288,7 @@ void GeometricalObjectsBins::SearchInRadiusInCell(

void GeometricalObjectsBins::SearchNearestInCell(
const CellType& rCell,
const Point& rPoint,
const PointType& rPoint,
ResultType& rResult,
const double MaxRadius
)
Expand All @@ -309,7 +309,7 @@ void GeometricalObjectsBins::SearchNearestInCell(

void GeometricalObjectsBins::SearchIsInsideInCell(
const CellType& rCell,
const Point& rPoint,
const PointType& rPoint,
ResultType& rResult
)
{
Expand Down
36 changes: 21 additions & 15 deletions kratos/spatial_containers/geometrical_objects_bins.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class GeometricalObject; // forward declaration, to be included in the cpp. This
* @class GeometricalObjectsBins
* @ingroup KratosCore
* @brief A bins container for 3 dimensional GeometricalObject entities.
* @details It provides efficent search in radius and search nearest methods.
* @details It provides efficient search in radius and search nearest methods.
* All of the geometries should be given at construction time. After
* constructing the bins the geometries cannot be modified. In case of
* any modification, the bins should be reconstructed.
Expand All @@ -51,6 +51,12 @@ class KRATOS_API(KRATOS_CORE) GeometricalObjectsBins
/// Pointer definition of GeometricalObjectsBins
KRATOS_CLASS_POINTER_DEFINITION(GeometricalObjectsBins);

/// The point type definition
using PointType = Point;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will approve, but I don't understand. Why do you want to make this type an alias, if you are hard-coding it here?

I assume it is because you are going to use this as a base of another bins?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically that


/// The type of geometrical object to be stored in the bins
using ObjectType = GeometricalObject;

/// The type of geometrical object to be stored in the bins
using CellType = std::vector<GeometricalObject*>;
using ResultType = SpatialSearchResult<GeometricalObject>;
Expand Down Expand Up @@ -131,7 +137,7 @@ class KRATOS_API(KRATOS_CORE) GeometricalObjectsBins
* @param K The index in z direction
* @return The bounding box of the cell
*/
BoundingBox<Point> GetCellBoundingBox(
BoundingBox<PointType> GetCellBoundingBox(
const std::size_t I,
const std::size_t J,
const std::size_t K
Expand All @@ -145,7 +151,7 @@ class KRATOS_API(KRATOS_CORE) GeometricalObjectsBins
* @param rResults The results of the search
*/
void SearchInRadius(
const Point& rPoint,
const PointType& rPoint,
const double Radius,
std::vector<ResultType>& rResults
);
Expand Down Expand Up @@ -184,7 +190,7 @@ class KRATOS_API(KRATOS_CORE) GeometricalObjectsBins
* @return ResultType The result of the search
*/
ResultType SearchNearestInRadius(
const Point& rPoint,
const PointType& rPoint,
const double Radius
);

Expand Down Expand Up @@ -223,7 +229,7 @@ class KRATOS_API(KRATOS_CORE) GeometricalObjectsBins
* @param rPoint The point to be checked
* @return ResultType The result of the search
*/
ResultType SearchNearest(const Point& rPoint);
ResultType SearchNearest(const PointType& rPoint);

/**
* @brief This method takes a point and finds the nearest object to it (iterative version).
Expand Down Expand Up @@ -259,7 +265,7 @@ class KRATOS_API(KRATOS_CORE) GeometricalObjectsBins
* @param rPoint The point to be checked
* @return ResultType The result of the search
*/
ResultType SearchIsInside(const Point& rPoint);
ResultType SearchIsInside(const PointType& rPoint);

/**
* @brief This method takes a point and search if it's inside an geometrical object of the domain (iterative version).
Expand Down Expand Up @@ -296,7 +302,7 @@ class KRATOS_API(KRATOS_CORE) GeometricalObjectsBins
* @brief Getting the bins bounding box
* @return The bounding box of the bins
*/
const BoundingBox<Point>& GetBoundingBox() const {
const BoundingBox<PointType>& GetBoundingBox() const {
return mBoundingBox;
}

Expand Down Expand Up @@ -369,7 +375,7 @@ class KRATOS_API(KRATOS_CORE) GeometricalObjectsBins
///@name Protected Member Variables
///@{

BoundingBox<Point> mBoundingBox; /// The bounding box of the domain
BoundingBox<PointType> mBoundingBox; /// The bounding box of the domain
array_1d<std::size_t, Dimension> mNumberOfCells; /// The number of cells in each direction
array_1d<double, 3> mCellSizes; /// The size of each cell in each direction
array_1d<double, 3> mInverseOfCellSize; /// The inverse of the size of each cell in each direction
Expand Down Expand Up @@ -463,7 +469,7 @@ class KRATOS_API(KRATOS_CORE) GeometricalObjectsBins
if(rGeometry.empty())
return;

BoundingBox<Point> bounding_box(rGeometry.begin(), rGeometry.end());
BoundingBox<PointType> bounding_box(rGeometry.begin(), rGeometry.end());

for(unsigned int i = 0; i < 3; i++ ) {
rMinPosition[i] = CalculatePosition( bounding_box.GetMinPoint()[i], i );
Expand Down Expand Up @@ -494,12 +500,12 @@ class KRATOS_API(KRATOS_CORE) GeometricalObjectsBins
template<typename TGeometryType>
static inline bool IsIntersected(
TGeometryType& rGeometry,
const BoundingBox<Point>& rBox,
const BoundingBox<PointType>& rBox,
const double ThisTolerance
)
{
Point low_point_tolerance;
Point high_point_tolerance;
PointType low_point_tolerance;
PointType high_point_tolerance;

for(unsigned int i = 0; i<3; i++) {
low_point_tolerance[i] = rBox.GetMinPoint()[i] - ThisTolerance;
Expand All @@ -519,7 +525,7 @@ class KRATOS_API(KRATOS_CORE) GeometricalObjectsBins
*/
void SearchInRadiusInCell(
const CellType& rCell,
const Point& rPoint,
const PointType& rPoint,
const double Radius,
std::unordered_set<GeometricalObject*>& rResults
);
Expand All @@ -534,7 +540,7 @@ class KRATOS_API(KRATOS_CORE) GeometricalObjectsBins
*/
void SearchNearestInCell(
const CellType& rCell,
const Point& rPoint,
const PointType& rPoint,
ResultType& rResult,
const double MaxRadius
);
Expand All @@ -548,7 +554,7 @@ class KRATOS_API(KRATOS_CORE) GeometricalObjectsBins
*/
void SearchIsInsideInCell(
const CellType& rCell,
const Point& rPoint,
const PointType& rPoint,
ResultType& rResult
);

Expand Down
Loading