Skip to content

Commit

Permalink
allow adding existing geometries
Browse files Browse the repository at this point in the history
  • Loading branch information
philbucher committed Oct 1, 2023
1 parent b652b8e commit cf0f792
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
21 changes: 6 additions & 15 deletions kratos/containers/geometry_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@
//
// Main authors: Pooyan Dadvand
//
//


#if !defined(KRATOS_GEOMETRY_CONTAINER_H_INCLUDED )
#define KRATOS_GEOMETRY_CONTAINER_H_INCLUDED


#pragma once

// System includes

Expand Down Expand Up @@ -129,12 +124,12 @@ class GeometryContainer
GeometryIterator AddGeometry(GeometryPointerType pNewGeometry)
{
auto i = mGeometries.find(pNewGeometry->Id());
if(i == mGeometries.end())
if (i == mGeometries.end()) {
return mGeometries.insert(pNewGeometry);
else
{
KRATOS_ERROR << "Geometry with Id: " << pNewGeometry->Id()
<< " exists already.";
} else if (&(*i) == pNewGeometry.get()) { // check if the pointee coincides
return i;
} else {
KRATOS_ERROR << "Attempting to add Geometry with Id: " << pNewGeometry->Id() << ", unfortunately a (different) geometry with the same Id already exists" << std::endl;
}
}

Expand Down Expand Up @@ -373,7 +368,3 @@ inline std::ostream& operator << (std::ostream& rOStream,
///@}

} // namespace Kratos.

#endif // KRATOS_GEOMETRY_CONTAINER_H_INCLUDED defined


11 changes: 6 additions & 5 deletions kratos/tests/cpp_tests/containers/test_geometry_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@

#include "containers/geometry_container.h"

namespace Kratos {
namespace Testing {
namespace Kratos::Testing {

Line3D2<Point>::Pointer GenerateLineGeometry() {
return Kratos::make_shared<Line3D2<Point>>(
Expand All @@ -40,14 +39,17 @@ namespace Testing {
p_line_1->SetId(1);

geometry_container.AddGeometry(p_line_1);
KRATOS_EXPECT_EQ(geometry_container.NumberOfGeometries(), 1);
geometry_container.AddGeometry(p_line_1); // adding same geomerty does not fails
KRATOS_EXPECT_EQ(geometry_container.NumberOfGeometries(), 1);

auto p_line_2 = GenerateLineGeometry();
p_line_2->SetId(1);

// check correct error if multiple geometries with sam id are added
KRATOS_EXPECT_EXCEPTION_IS_THROWN(
geometry_container.AddGeometry(p_line_2),
"Geometry with Id: 1 exists already.");
"Attempting to add Geometry with Id: 1, unfortunately a (different) geometry with the same Id already exists");

p_line_2->SetId(2);
geometry_container.AddGeometry(p_line_2);
Expand All @@ -72,5 +74,4 @@ namespace Testing {
KRATOS_EXPECT_EQ(geometry_container.NumberOfGeometries(), 1);
KRATOS_EXPECT_FALSE(geometry_container.HasGeometry("GeometryLine1"));
}
} // namespace Testing.
} // namespace Kratos.
} // namespace Kratos::Testing.

0 comments on commit cf0f792

Please sign in to comment.