6 #include "includes/global_variables.h"
7 #include "includes/kratos_export_api.h"
8 #include "includes/node.h"
9 #include "includes/element.h"
10 #include "includes/condition.h"
11 #include "utilities/variable_utils.h"
17 #include <type_traits>
23 template <
class TEntityProxy>
46 template <Globals::DataLocation TLocation,
bool TMutable>
50 constexpr
static Globals::DataLocation Location = TLocation;
52 constexpr
static bool IsMutable = TMutable;
55 using UnqualifiedEntity = std::conditional_t<
56 TLocation == Globals::DataLocation::NodeHistorical || TLocation == Globals::DataLocation::NodeNonHistorical,
59 TLocation == Globals::DataLocation::Element,
62 TLocation == Globals::DataLocation::Condition,
65 TLocation == Globals::DataLocation::ProcessInfo,
68 TLocation == Globals::DataLocation::ModelPart,
78 using QualifiedEntity = std::conditional_t<TMutable,
80 const UnqualifiedEntity>;
95 EntityProxy(QualifiedEntity& rEntity) noexcept : mrEntity(rEntity) {}
98 template <
class TValue>
99 bool HasValue(
const Variable<TValue>& rVariable)
const noexcept
101 return VariableUtils::HasValue<TLocation>(mrEntity.value(), rVariable);
105 template <
class TValue>
106 std::conditional_t<std::is_integral_v<TValue> || std::is_floating_point_v<TValue>,
111 return VariableUtils::GetValue<TLocation>(mrEntity.value(), rVariable);
115 template <
class TValue, std::enable_if_t<!std::is_same_v<TValue,void> && TMutable,
bool> =
true>
116 TValue&
GetValue(
const Variable<TValue>& rVariable)
118 return VariableUtils::GetValue<TLocation>(mrEntity.value(), rVariable);
122 template <
class TValue, std::enable_if_t<!std::is_same_v<TValue,void> && TMutable,
bool> =
true>
124 std::conditional_t<std::is_integral_v<TValue> || std::is_floating_point_v<TValue>,
126 const TValue&> Value)
128 VariableUtils::SetValue<TLocation>(mrEntity.value(), rVariable, Value);
134 return mrEntity.value();
140 return mrEntity.value();
150 template <Globals::DataLocation TLocation,
class TEntity>
153 static_assert(std::is_same_v<TEntity,void>,
"Invalid DataLocation-Entity combination");
158 template <Globals::DataLocation TLocation,
class TEntity>
161 static_assert(std::is_same_v<TEntity,void>,
"Invalid DataLocation-Entity combination");
165 #define WRAPP_DEFINE_ENTITY_PROXY_FACTORY(TLocation, TEntity) \
168 inline auto MakeProxy<TLocation,TEntity>(const TEntity& rEntity) \
169 {return EntityProxy<TLocation,false>(rEntity);} \
172 inline auto MakeProxy<TLocation,TEntity>(TEntity& rEntity) \
173 {return EntityProxy<TLocation,true>(rEntity);}
187 #undef WRAPP_DEFINE_ENTITY_PROXY_FACTORY
192 inline auto MakeProxy<Globals::DataLocation::ProcessInfo,ModelPart>(
const ModelPart& rModelPart)
200 inline auto MakeProxy<Globals::DataLocation::ProcessInfo,ModelPart>(ModelPart& rModelPart)
A view with a uniform interface for ModelPart::NodesContainerType, ModelPart::ElementsContainerType,...
Definition: ContainerProxy.hpp:28
Wrapper class providing a uniform interface for historical/non-historical Node, Element,...
Definition: EntityProxy.hpp:48
bool HasValue(const Variable< TValue > &rVariable) const noexcept
Check whether the entity has a value for the provided variable.
Definition: EntityProxy.hpp:99
std::conditional_t< std::is_integral_v< TValue >||std::is_floating_point_v< TValue >, TValue, const TValue & > GetValue(const Variable< TValue > &rVariable) const
Fetch the value corresponding to the input variable in the wrapped entity.
Definition: EntityProxy.hpp:109
QualifiedEntity & GetEntity()
Mutable or immutable access to the wrapped entity, depending on TMutable.
Definition: EntityProxy.hpp:138
void SetValue(const Variable< TValue > &rVariable, std::conditional_t< std::is_integral_v< TValue >||std::is_floating_point_v< TValue >, TValue, const TValue & > Value)
Overwrite the value corresponding to the input variable in the wrapped entity.
Definition: EntityProxy.hpp:123
EntityProxy() noexcept=default
Default constructor that leaves the instance in an invalid state.
const UnqualifiedEntity & GetEntity() const
Immutable access to the wrapped entity.
Definition: EntityProxy.hpp:132
TValue & GetValue(const Variable< TValue > &rVariable)
Fetch the value corresponding to the input variable in the wrapped entity.
Definition: EntityProxy.hpp:116
auto MakeProxy(const TEntity &rEntity)
Invalid template base to be specialized for valid template parameters.
Definition: EntityProxy.hpp:151
#define WRAPP_DEFINE_ENTITY_PROXY_FACTORY(TLocation, TEntity)
Definition: EntityProxy.hpp:165
Definition: MPIUtils.hpp:9