26 #include <type_traits>
33 template <
class TEntityProxy>
51 template <Globals::DataLocation TLocation,
bool TMutable>
57 constexpr
static bool IsMutable = TMutable;
60 using UnqualifiedEntity = std::conditional_t<
83 using QualifiedEntity = std::conditional_t<TMutable,
85 const UnqualifiedEntity>;
98 EntityProxy(QualifiedEntity& rEntity) noexcept : mpEntity(&rEntity) {}
101 template <
class TValue>
104 return VariableUtils::HasValue<TLocation>(*mpEntity, rVariable);
108 template <
class TValue>
109 std::conditional_t<std::is_integral_v<TValue> || std::is_floating_point_v<TValue>,
114 return VariableUtils::GetValue<TLocation>(*mpEntity, rVariable);
118 template <
class TValue, std::enable_if_t<!std::is_same_v<TValue,void> && TMutable,
bool> =
true>
121 return VariableUtils::GetValue<TLocation>(*mpEntity, rVariable);
125 template <
class TValue, std::enable_if_t<!std::is_same_v<TValue,void> && TMutable,
bool> =
true>
127 std::conditional_t<std::is_integral_v<TValue> || std::is_floating_point_v<TValue>,
129 const TValue&> Value)
131 VariableUtils::SetValue<TLocation>(*mpEntity, rVariable, Value);
147 QualifiedEntity* mpEntity;
160 template <
class TEntityProxy>
164 using UnqualifiedContainer = std::conditional_t<
165 std::is_same_v<typename TEntityProxy::UnqualifiedEntity,Node>,
168 std::is_same_v<typename TEntityProxy::UnqualifiedEntity,Element>,
171 std::is_same_v<typename TEntityProxy::UnqualifiedEntity,Condition>,
178 constexpr
static bool IsMutable = TEntityProxy::IsMutable;
180 using WrappedIterator = std::conditional_t<IsMutable,
181 typename UnqualifiedContainer::iterator,
182 typename UnqualifiedContainer::const_iterator>;
184 template <
bool TMutable>
188 using Wrapped = std::conditional_t<TMutable,
189 typename UnqualifiedContainer::iterator,
190 typename UnqualifiedContainer::const_iterator>;
195 using pointer = std::conditional_t<TMutable,
199 using reference = std::conditional_t<TMutable,
203 using difference_type = std::ptrdiff_t;
205 using iterator_category = std::random_access_iterator_tag;
207 Iterator() noexcept =
default;
209 Iterator(Wrapped It) noexcept : mWrapped(It) {}
213 Iterator& operator++() noexcept {++mWrapped;
return *
this;}
215 Iterator operator++(
int) noexcept {Iterator copy(mWrapped); ++mWrapped;
return copy;}
217 Iterator& operator--() noexcept {--mWrapped;
return *
this;}
219 Iterator operator--(
int) noexcept {Iterator copy(mWrapped); --mWrapped;
return copy;}
221 Iterator& operator+=(difference_type Rhs) noexcept {mWrapped += Rhs;
return *
this;}
223 Iterator& operator-=(difference_type Rhs) noexcept {mWrapped -= Rhs;
return *
this;}
225 Iterator
operator+(difference_type Rhs)
const noexcept {Iterator copy(mWrapped); copy += Rhs;
return copy;}
227 Iterator
operator-(difference_type Rhs)
const noexcept {Iterator copy(mWrapped); copy -= Rhs;
return copy;}
229 difference_type
operator-(Iterator Rhs)
const noexcept {
return mWrapped - Rhs.mWrapped;}
231 bool operator==(Iterator Rhs)
const noexcept {
return mWrapped == Rhs.mWrapped;}
233 bool operator!=(Iterator Rhs)
const noexcept {
return mWrapped != Rhs.mWrapped;}
235 bool operator<(Iterator Rhs)
const noexcept {
return mWrapped < Rhs.mWrapped;}
237 bool operator>(Iterator Rhs)
const noexcept {
return mWrapped > Rhs.mWrapped;}
239 bool operator<=(Iterator Rhs)
const noexcept {
return mWrapped <= Rhs.mWrapped;}
241 bool operator>=(Iterator Rhs)
const noexcept {
return mWrapped >= Rhs.mWrapped;}
287 WrappedIterator mBegin, mEnd;
293 template <Globals::DataLocation TLocation,
class TEntity>
296 static_assert(std::is_same_v<TEntity,void>,
"Invalid DataLocation-Entity combination");
301 template <Globals::DataLocation TLocation,
class TEntity>
304 static_assert(std::is_same_v<TEntity,void>,
"Invalid DataLocation-Entity combination");
308 #define KRATOS_DEFINE_ENTITY_PROXY_FACTORY(TLocation, TEntity) \
311 inline auto MakeProxy<TLocation,TEntity>(const TEntity& rEntity) \
312 {return EntityProxy<TLocation,false>(rEntity);} \
315 inline auto MakeProxy<TLocation,TEntity>(TEntity& rEntity) \
316 {return EntityProxy<TLocation,true>(rEntity);}
330 #undef KRATOS_DEFINE_ENTITY_PROXY_FACTORY
335 inline auto MakeProxy<Globals::DataLocation::ProcessInfo,ModelPart>(
const ModelPart& rModelPart)
343 inline auto MakeProxy<Globals::DataLocation::ProcessInfo,ModelPart>(
ModelPart& rModelPart)
349 #define KRATOS_DEFINE_CONTAINER_PROXY_FACTORY(TLocation) \
352 inline auto MakeProxy<TLocation,ModelPart>(const ModelPart& rModelPart) \
354 const auto& r_container = ModelPartUtils::GetContainer<TLocation>(rModelPart); \
355 return ContainerProxy<EntityProxy<TLocation,false>>(r_container.begin(), \
356 r_container.end()); \
360 inline auto MakeProxy<TLocation,ModelPart>(ModelPart& rModelPart) \
362 auto& r_container = ModelPartUtils::GetContainer<TLocation>(rModelPart); \
363 return ContainerProxy<EntityProxy<TLocation,true>>(r_container.begin(), \
364 r_container.end()); \
375 #undef KRATOS_DEFINE_CONTAINER_PROXY_FACTORY
Base class for all Conditions.
Definition: condition.h:59
A view with a uniform interface for ModelPart::NodesContainerType, ModelPart::ElementsContainerType,...
Definition: proxies.h:162
const_iterator end() const noexcept
Definition: proxies.h:282
const_iterator cend() const noexcept
Definition: proxies.h:280
size_type size() const noexcept
Definition: proxies.h:270
iterator::value_type at(size_type Index) noexcept
Definition: proxies.h:268
const_iterator::value_type at(size_type Index) const noexcept
Definition: proxies.h:266
Iterator< false > const_iterator
Definition: proxies.h:249
bool empty() const noexcept
Definition: proxies.h:272
const_iterator::value_type operator[](size_type Index) const noexcept
Definition: proxies.h:262
Iterator< IsMutable > iterator
Definition: proxies.h:247
const_iterator begin() const noexcept
Definition: proxies.h:276
typename iterator::value_type value_type
Definition: proxies.h:253
ContainerProxy() noexcept=default
std::size_t size_type
Definition: proxies.h:251
iterator end() noexcept
Definition: proxies.h:284
iterator::value_type operator[](size_type Index) noexcept
Definition: proxies.h:264
const_iterator cbegin() const noexcept
Definition: proxies.h:274
iterator begin() noexcept
Definition: proxies.h:278
Base class for all Elements.
Definition: element.h:60
Wrapper class providing a uniform interface for historical/non-historical Node, Element,...
Definition: proxies.h:53
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: proxies.h:112
QualifiedEntity & GetEntity()
Mutable or immutable access to the wrapped entity, depending on TMutable.
Definition: proxies.h:141
TValue & GetValue(const Variable< TValue > &rVariable)
Fetch the value corresponding to the input variable in the wrapped entity.
Definition: proxies.h:119
const UnqualifiedEntity & GetEntity() const
Immutable access to the wrapped entity.
Definition: proxies.h:135
EntityProxy(QualifiedEntity &rEntity) noexcept
Constructor creating a valid proxy, wrapping the input entity.
Definition: proxies.h:98
bool HasValue(const Variable< TValue > &rVariable) const noexcept
Check whether the entity has a value for the provided variable.
Definition: proxies.h:102
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: proxies.h:126
EntityProxy()=delete
Delete the default constructor to prevent storing nullptr.
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
MeshType::ConditionsContainerType ConditionsContainerType
Condintions container. A vector set of Conditions with their Id's as key.
Definition: model_part.h:183
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
This class defines the node.
Definition: node.h:65
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
DataLocation
Enum for location of data.
Definition: global_variables.h:48
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
bool operator<=(Dof< TDataType > const &First, Dof< TDataType > const &Second)
Less equal operator.
Definition: dof.h:606
Expression::Pointer operator*(const Expression::ConstPointer &rpLeft, const double Right)
Expression::Pointer operator-(const Expression::ConstPointer &rpLeft, const double Right)
bool operator<(Dof< TDataType > const &First, Dof< TDataType > const &Second)
Less than operator.
Definition: dof.h:584
bool operator==(const Flags &Left, const Flags &Right)
Definition: flags.cpp:45
auto MakeProxy(const TEntity &rEntity)
Invalid template base to be specialized for valid template parameters.
Definition: proxies.h:294
bool operator>(Dof< TDataType > const &First, Dof< TDataType > const &Second)
Greater than operator.
Definition: dof.h:573
bool operator!=(const Flags &Left, const Flags &Right)
Definition: flags.cpp:50
Expression::Pointer operator+(const Expression::ConstPointer &rpLeft, const double Right)
bool operator>=(Dof< TDataType > const &First, Dof< TDataType > const &Second)
Greater equal operator.
Definition: dof.h:595
default
Definition: generate_gid_list_file.py:35
tuple const
Definition: ode_solve.py:403
#define KRATOS_DEFINE_CONTAINER_PROXY_FACTORY(TLocation)
Definition: proxies.h:349
#define KRATOS_DEFINE_ENTITY_PROXY_FACTORY(TLocation, TEntity)
Definition: proxies.h:308