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] Extend Proxies to Support MasterSlaveConstraints #12919

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions kratos/includes/global_variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace Kratos::Globals
NodeNonHistorical,
Element,
Condition,
Constraint,
ModelPart,
ProcessInfo
};
Expand Down
28 changes: 18 additions & 10 deletions kratos/utilities/model_part_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Kratos
class ModelPartUtils
{
public:
/// @brief Templated interface for getting nodes, elements, conditions or @ref ProcessInfo from a @ref ModelPart.
/// @brief Templated interface for getting nodes, elements, conditions, @ref MasterSlaveConstraint "constraints" or @ref ProcessInfo from a @ref ModelPart.
template <Globals::DataLocation TLocation>
static const auto& GetContainer(const ModelPart& rModelPart)
{
Expand All @@ -42,14 +42,16 @@ class ModelPartUtils
return rModelPart.Elements();
} else if constexpr (TLocation == Globals::DataLocation::Condition) {
return rModelPart.Conditions();
} else if constexpr (TLocation == Globals::DataLocation::Constraint) {
return rModelPart.MasterSlaveConstraints();
} else if constexpr (TLocation == Globals::DataLocation::ProcessInfo) {
return rModelPart.GetProcessInfo();
} else if constexpr (TLocation == Globals::DataLocation::ModelPart) {
return rModelPart;
}
}

/// @brief Templated interface for getting nodes, elements, conditions or @ref ProcessInfo from a @ref ModelPart.
/// @brief Templated interface for getting nodes, elements, conditions, @ref MasterSlaveConstraint "constraints" or @ref ProcessInfo from a @ref ModelPart.
template <Globals::DataLocation TLocation>
static auto& GetContainer(ModelPart& rModelPart)
{
Expand All @@ -59,14 +61,16 @@ class ModelPartUtils
return rModelPart.Elements();
} else if constexpr (TLocation == Globals::DataLocation::Condition) {
return rModelPart.Conditions();
} else if constexpr (TLocation == Globals::DataLocation::Constraint) {
return rModelPart.MasterSlaveConstraints();
} else if constexpr (TLocation == Globals::DataLocation::ProcessInfo) {
return rModelPart.GetProcessInfo();
} else if constexpr (TLocation == Globals::DataLocation::ModelPart) {
return rModelPart;
}
}

/// @brief Templated interface to get nodes, elements and conditions from a @ref ModelPart
/// @brief Templated interface to get nodes, elements, conditions and @ref MasterSlaveConstraint "constraints" from a @ref ModelPart
template<class TContainerType>
static const auto& GetContainer(const ModelPart& rModelPart)
{
Expand All @@ -76,13 +80,15 @@ class ModelPartUtils
return GetContainer<Globals::DataLocation::Condition>(rModelPart);
} else if constexpr(std::is_same_v<TContainerType, ModelPart::ElementsContainerType>) {
return GetContainer<Globals::DataLocation::Element>(rModelPart);
} else if constexpr(std::is_same_v<TContainerType, ModelPart::MasterSlaveConstraintContainerType>) {
return GetContainer<Globals::DataLocation::Constraint>(rModelPart);
} else {
static_assert(!std::is_same_v<TContainerType, TContainerType>, "Unsupported container type.");
return 0;
}
}

/// @brief Templated interface to get nodes, elements and conditions from a @ref ModelPart
/// @brief Templated interface to get nodes, elements, conditions, @ref MasterSlaveConstraint "constraints" from a @ref ModelPart
template<class TContainerType>
static auto& GetContainer(ModelPart& rModelPart)
{
Expand All @@ -92,14 +98,16 @@ class ModelPartUtils
return GetContainer<Globals::DataLocation::Condition>(rModelPart);
} else if constexpr(std::is_same_v<TContainerType, ModelPart::ElementsContainerType>) {
return GetContainer<Globals::DataLocation::Element>(rModelPart);
} else if constexpr(std::is_same_v<TContainerType, ModelPart::MasterSlaveConstraintContainerType>) {
return GetContainer<Globals::DataLocation::Constraint>(rModelPart);
} else {
static_assert(!std::is_same_v<TContainerType, TContainerType>, "Unsupported container type.");
return 0;
}
}

/**
* @brief Add nodes to ModelPart from an ordered container.
* @brief Add nodes to ModelPart from an ordered container.
* @details By assuming that the input is ordered (by increasing Id), the nodes can be added more efficiently. Note that the function makes no check of the ordering, it is the responsability of the caller to ensure that it is correct.
* @tparam TIteratorType Iterator type for the nodes to add.
* @param rTargetModelPart ModelPart the nodes will be added to.
Expand Down Expand Up @@ -315,9 +323,9 @@ class ModelPartUtils
*/
template<class TIteratorType >
static typename ModelPart::NodesContainerType JoinOrderedNodesContainerType(
TIteratorType iC1Begin,
TIteratorType iC1End,
TIteratorType iC2Begin,
TIteratorType iC1Begin,
TIteratorType iC1End,
TIteratorType iC2Begin,
TIteratorType iC2End
)
{
Expand Down Expand Up @@ -361,14 +369,14 @@ class ModelPartUtils

return aux;
}

/**
* @brief Checks if an entity is registered in Kratos and returns a reference to it.
* @details This function checks if a given entity (either an Element or a Condition) is registered in Kratos. If the entity is registered, it returns a constant reference to it. If the entity is not registered, it throws an error with a descriptive message. Template parameter `TEntity` can be either `Element` or `Condition`. The function utilizes compile-time checks to generate appropriate error messages based on the entity type.
* @tparam TEntity The type of the entity to check. Must be either `Element` or `Condition`.
* @param rEntityName The name of the entity to check.
* @return const TEntity& A constant reference to the entity.
* @throw Kratos::Exception If the entity is not registered in Kratos. The exception message will specify
* @throw Kratos::Exception If the entity is not registered in Kratos. The exception message will specify
* whether the missing entity is an Element or a Condition and remind to check the spelling and registration of the application.
*/
template<class TEntity>
Expand Down
26 changes: 18 additions & 8 deletions kratos/utilities/proxies.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

// Project includes
#include "includes/global_variables.h" // DataLocation
#include "includes/kratos_export_api.h" // KRATOS_API
#include "includes/node.h" // Node
#include "includes/element.h" // Element
#include "includes/condition.h" // Condition
Expand All @@ -24,7 +23,6 @@

// System includes
#include <type_traits> // remove_reference_t, is_const_v, is_same_v, decay_t
#include <optional> // optional


namespace Kratos {
Expand Down Expand Up @@ -67,12 +65,16 @@ class EntityProxy
TLocation == Globals::DataLocation::Condition,
Condition,
std::conditional_t<
TLocation == Globals::DataLocation::ProcessInfo,
ProcessInfo,
TLocation == Globals::DataLocation::Constraint,
MasterSlaveConstraint,
std::conditional_t<
TLocation == Globals::DataLocation::ModelPart,
ModelPart,
void // <== invalid fallback type; will throw a compile-time error
TLocation == Globals::DataLocation::ProcessInfo,
ProcessInfo,
std::conditional_t<
TLocation == Globals::DataLocation::ModelPart,
ModelPart,
void // <== invalid fallback type; will throw a compile-time error
>
>
>
>
Expand Down Expand Up @@ -170,7 +172,11 @@ class ContainerProxy
std::conditional_t<
std::is_same_v<typename TEntityProxy::UnqualifiedEntity,Condition>,
ModelPart::ConditionsContainerType,
void // <== invalid fallback type; will throw a compile-time error
std::conditional_t<
std::is_same_v<typename TEntityProxy::UnqualifiedEntity,MasterSlaveConstraint>,
ModelPart::MasterSlaveConstraintContainerType,
void // <== invalid fallback type; will throw a compile-time error
>
>
>
>;
Expand Down Expand Up @@ -323,6 +329,8 @@ KRATOS_DEFINE_ENTITY_PROXY_FACTORY(Globals::DataLocation::Element, Element)

KRATOS_DEFINE_ENTITY_PROXY_FACTORY(Globals::DataLocation::Condition, Condition)

KRATOS_DEFINE_ENTITY_PROXY_FACTORY(Globals::DataLocation::Constraint, MasterSlaveConstraint)

KRATOS_DEFINE_ENTITY_PROXY_FACTORY(Globals::DataLocation::ProcessInfo, ProcessInfo)

KRATOS_DEFINE_ENTITY_PROXY_FACTORY(Globals::DataLocation::ModelPart, ModelPart)
Expand Down Expand Up @@ -372,6 +380,8 @@ KRATOS_DEFINE_CONTAINER_PROXY_FACTORY(Globals::DataLocation::Element)

KRATOS_DEFINE_CONTAINER_PROXY_FACTORY(Globals::DataLocation::Condition)

KRATOS_DEFINE_CONTAINER_PROXY_FACTORY(Globals::DataLocation::Constraint)

#undef KRATOS_DEFINE_CONTAINER_PROXY_FACTORY


Expand Down
Loading