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

[FastPR][Core] Adding HasPrototypeEntity to EntityIdentifier #11533

Merged
merged 3 commits into from
Sep 3, 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
35 changes: 35 additions & 0 deletions kratos/tests/cpp_tests/utilities/test_entities_utilities.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// | / |
// ' / __| _` | __| _ \ __|
// . \ | ( | | ( |\__ `
// _|\_\_| \__,_|\__|\___/ ____/
// Multi-Physics
//
// License: BSD License
// Kratos default license: kratos/license.txt
//
// Main authors: Ruben Zorrilla
//
//

// Project includes
#include "testing/testing.h"
#include "containers/model.h"
#include "includes/expect.h"
#include "utilities/entities_utilities.h"

namespace Kratos::Testing
{

KRATOS_TEST_CASE_IN_SUITE(EntityIdentifierHasPrototype, KratosCoreFastSuite)
{
Model model;
auto& r_model_part = model.CreateModelPart("MainModelPart");
r_model_part.CreateNewNode(1, 0.0, 0.0, 0.0);
r_model_part.CreateNewNode(2, 1.0, 0.0, 0.0);
r_model_part.CreateNewNode(3, 0.0, 1.0, 0.0);
auto p_tri_geom = r_model_part.CreateNewGeometry("Triangle2D3", 1, {{1, 2, 3}});
auto entity_identifier = EntitiesUtilities::EntitityIdentifier<Element>("Element2D3N");
KRATOS_EXPECT_TRUE(entity_identifier.HasPrototypeEntity(*p_tri_geom));
}

} // namespace Kratos::Testing.
9 changes: 9 additions & 0 deletions kratos/utilities/entities_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ bool EntitityIdentifier<TEntity>::IsInitialized() const
/***********************************************************************************/
/***********************************************************************************/

template<class TEntity>
bool EntitityIdentifier<TEntity>::HasPrototypeEntity(const GeometryType& rGeometry) const
{
return mTypes[static_cast<std::size_t>(rGeometry.GetGeometryType())] != nullptr;
}

/***********************************************************************************/
/***********************************************************************************/

template<class TEntity>
const TEntity& EntitityIdentifier<TEntity>::GetPrototypeEntity(typename GeometryType::Pointer pGeometry) const
{
Expand Down
8 changes: 8 additions & 0 deletions kratos/utilities/entities_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ namespace EntitiesUtilities
*/
bool IsInitialized() const;

/**
* @brief Get the prototype entity.
* @param rGeometry The reference to the geometry.
* @return true there is a prototype for the provided entity.
* @return false there is no prototype for the provided entity.
*/
bool HasPrototypeEntity(const GeometryType& rGeometry) const;

/**
* @brief Get the prototype entity.
* @param pGeometry The pointer to the geometry.
Expand Down
Loading