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] Remove push_back from ModelPart #12903

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
dd02fc8
add additional insert and typecheck to PVS
sunethwarna Dec 5, 2024
2bf1e96
remove push_backs from ModelPart
sunethwarna Dec 5, 2024
2c5d23f
include reduction_utils
sunethwarna Dec 5, 2024
d5521ba
minor
sunethwarna Dec 5, 2024
2f72e0c
func name change
sunethwarna Dec 5, 2024
1e98ea3
fix embedded_skin_utility for Id Change
sunethwarna Dec 10, 2024
9c05b31
allow insertion from const vectors
sunethwarna Dec 10, 2024
abbce15
allow insertion from parent entity ranges
sunethwarna Dec 10, 2024
71ae35f
fix for iterator invalidation
sunethwarna Dec 10, 2024
6d34602
add comments
sunethwarna Dec 10, 2024
f1c4a6f
minor signature modification
sunethwarna Dec 10, 2024
35c1874
fix assign_ms_const_to_neigh_utils
sunethwarna Dec 11, 2024
13e87e7
fix error msg tests
sunethwarna Dec 11, 2024
a50fd2b
fix hdf5
sunethwarna Dec 11, 2024
8a42759
generalize addition from ids
sunethwarna Dec 11, 2024
93293e0
simplify
sunethwarna Dec 11, 2024
6adabf4
fix ranged id addition
sunethwarna Dec 11, 2024
9082f96
Merge remote-tracking branch 'origin/master' into pvs/remove_push_bac…
sunethwarna Dec 12, 2024
d7d4734
fix parmmg
sunethwarna Dec 16, 2024
d718a9a
add benchmarks for modelpart
sunethwarna Dec 16, 2024
4430f5e
minor for comparison
sunethwarna Dec 16, 2024
d7e05de
add type_traits
sunethwarna Dec 18, 2024
fedc6b3
allow rvalue containers in pvs insert
sunethwarna Dec 18, 2024
d642295
allow rvalue containers in model part
sunethwarna Dec 18, 2024
ee29e90
tests for rvalue containers in PVS
sunethwarna Dec 18, 2024
71e3074
more performance improvements
sunethwarna Dec 18, 2024
1024156
fix tests
sunethwarna Dec 18, 2024
a9e8219
minor
sunethwarna Dec 18, 2024
abfdcab
bug fix
sunethwarna Dec 18, 2024
a00437f
fix sub range addition
sunethwarna Jan 2, 2025
36fd864
add a test to subrange addition
sunethwarna Jan 2, 2025
88a5f51
fix test
sunethwarna Jan 2, 2025
22ff3e1
expose shrink_to_fit
sunethwarna Jan 2, 2025
99aca1d
change test
sunethwarna Jan 2, 2025
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
39 changes: 22 additions & 17 deletions kratos/includes/model_part.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class KRATOS_API(KRATOS_CORE) ModelPart final
///@name Class definitions
///@{

/// @brief Templated class to get corresponding container and its information from a mesh.
/// @tparam TContainerType The type of the container to be retrieved.
template<class TContainerType>
struct Container {};

Expand Down Expand Up @@ -383,7 +385,7 @@ class KRATOS_API(KRATOS_CORE) ModelPart final
if constexpr(!std::is_same_v<BaseType<TContainer>, std::vector<IndexType>>) {
EntityRangeChecker<NodesContainerType>()(this, rInputContainer.begin(), rInputContainer.end());

InsertEntityRValuedContainer([](ModelPart* pModelPart) {
InsertEntities([](ModelPart* pModelPart) {
return &(pModelPart->GetMesh().Nodes());
}, std::move(rInputContainer));
} else {
Expand Down Expand Up @@ -703,7 +705,7 @@ class KRATOS_API(KRATOS_CORE) ModelPart final
if constexpr(!std::is_same_v<BaseType<TContainer>, std::vector<IndexType>>) {
EntityRangeChecker<MasterSlaveConstraintContainerType>()(this, rInputContainer.begin(), rInputContainer.end());

InsertEntityRValuedContainer([](ModelPart* pModelPart) {
InsertEntities([](ModelPart* pModelPart) {
return &(pModelPart->GetMesh().MasterSlaveConstraints());
}, std::move(rInputContainer));
} else {
Expand Down Expand Up @@ -1034,7 +1036,7 @@ class KRATOS_API(KRATOS_CORE) ModelPart final
if constexpr(!std::is_same_v<BaseType<TContainer>, std::vector<IndexType>>) {
EntityRangeChecker<ElementsContainerType>()(this, rInputContainer.begin(), rInputContainer.end());

InsertEntityRValuedContainer([](ModelPart* pModelPart) {
InsertEntities([](ModelPart* pModelPart) {
return &(pModelPart->GetMesh().Elements());
}, std::move(rInputContainer));
} else {
Expand Down Expand Up @@ -1208,7 +1210,7 @@ class KRATOS_API(KRATOS_CORE) ModelPart final
if constexpr(!std::is_same_v<BaseType<TContainer>, std::vector<IndexType>>) {
EntityRangeChecker<ConditionsContainerType>()(this, rInputContainer.begin(), rInputContainer.end());

InsertEntityRValuedContainer([](ModelPart* pModelPart) {
InsertEntities([](ModelPart* pModelPart) {
return &(pModelPart->GetMesh().Conditions());
}, std::move(rInputContainer));
} else {
Expand Down Expand Up @@ -1519,7 +1521,7 @@ class KRATOS_API(KRATOS_CORE) ModelPart final
}
});

InsertEntityRValuedContainer([](ModelPart* pModelPart) {
InsertEntities([](ModelPart* pModelPart) {
return &(pModelPart->Geometries());
}, std::move(rInputContainer));
} else {
Expand Down Expand Up @@ -2012,23 +2014,23 @@ class KRATOS_API(KRATOS_CORE) ModelPart final
}
};

template<class TContainerType, class TIterator>
template<class TContainerType>
static bool IsSubSet(
const TContainerType& rContainer,
TIterator begin,
TIterator end)
typename TContainerType::iterator begin,
typename TContainerType::iterator end)
sunethwarna marked this conversation as resolved.
Show resolved Hide resolved
{
// do nothing if the given range is empty.
if (std::distance(begin, end) == 0) {
return true;
}

// check if the given [begin, end) range is a subset of the given PointerVectorSet.
auto current_pvs_begin_it = rContainer.find(*begin->Id());
if (current_pvs_begin_it != rContainer.end() && &current_pvs_begin_it->base() == &begin->base()) {
auto current_pvs_begin_it = rContainer.find(begin->Id());
if (current_pvs_begin_it != rContainer.end() && &*(current_pvs_begin_it.base()) == &*(begin.base())) {
// memory location pointing to begin is in the rContainer. then check the same for the end.
auto current_pvs_end_it = rContainer.find(*(end - 1)->Id());
return current_pvs_end_it != rContainer.end() && &current_pvs_end_it->base() == &end->base();
auto current_pvs_end_it = rContainer.find((end - 1)->Id());
return current_pvs_end_it != rContainer.end() && &*(current_pvs_end_it.base()) == &*((end - 1).base());
}

return false;
Expand Down Expand Up @@ -2074,12 +2076,13 @@ class KRATOS_API(KRATOS_CORE) ModelPart final
{
KRATOS_TRY

using container_type = std::remove_pointer_t<decltype(std::declval<TContainerGetter>()(std::declval<ModelPart*>()))>;

ModelPart* p_current_part = this;

if constexpr(!std::is_same_v<iterator, std::remove_cv<TIterator>>) {
if constexpr(!std::is_same_v<typename container_type::iterator, std::remove_cv_t<TIterator>> &&
!std::is_same_v<typename container_type::const_iterator, std::remove_cv_t<TIterator>>) {
// this represents the case 1.
using container_type = std::remove_pointer_t<decltype(std::declval<TContainerGetter>()(std::declval<ModelPart*>()))>;
container_type aux;
aux.insert(begin, end);

Expand All @@ -2094,13 +2097,15 @@ class KRATOS_API(KRATOS_CORE) ModelPart final
} else {
// this represents the case 2.
// now the iterators belong to PVS::iterator, hence no sorting or making them to unique will occur.
while (p_current_part->IsSubModelPart() && !IsSubSet(*rContainerGetter(p_current_part), begin, end)) {
bool is_sub_set = IsSubSet(*rContainerGetter(p_current_part), begin, end);
while (p_current_part->IsSubModelPart() && !is_sub_set) {
rContainerGetter(p_current_part)->insert(begin, end);
p_current_part = &(p_current_part->GetParentModelPart());
is_sub_set = IsSubSet(*rContainerGetter(p_current_part), begin, end);
}

// now we do the same for the root model part
if (!IsSubSet(*rContainerGetter(p_current_part), begin, end)) {
if (!is_sub_set) {
rContainerGetter(p_current_part)->insert(begin, end);
}
}
Expand All @@ -2109,7 +2114,7 @@ class KRATOS_API(KRATOS_CORE) ModelPart final
}

template<class TContainerGetter, class TInputContainer, std::enable_if_t<IsRValueContainer<TInputContainer>::value, bool> = true>
void InsertEntityRValuedContainer(
void InsertEntities(
const TContainerGetter& rContainerGetter,
TInputContainer&& rInputContainer)
{
Expand Down
Loading