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] Introducing proper insert method to PointerVectorSet #12087

Merged
merged 31 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e1702fd
implement set_address_identity_function
sunethwarna Feb 19, 2024
0520260
use set_address_identity_function
sunethwarna Feb 19, 2024
abaeedd
add insert methods to ptrvecset
sunethwarna Feb 19, 2024
4b34963
add insert tests
sunethwarna Feb 19, 2024
1a226e4
set mSortedPartSize = mData.size()
sunethwarna Feb 19, 2024
770d666
add the inserts to the end
sunethwarna Feb 19, 2024
b3a9a76
revert elimination builder and solver changes
sunethwarna Feb 19, 2024
b0ef86b
change dofarraytype
sunethwarna Feb 19, 2024
f5a7f05
fix ranged insert bug with end
sunethwarna Feb 19, 2024
8dfbe09
fix mmg reordering
sunethwarna Feb 20, 2024
f2f3dcc
fix dof updater
sunethwarna Feb 20, 2024
1c9af8e
add additional reserve
sunethwarna Feb 20, 2024
d0ef0e7
add another insertion method
sunethwarna Feb 20, 2024
3544a66
Merge remote-tracking branch 'origin/master' into core/pointer_vector…
sunethwarna Feb 22, 2024
9c00f71
introduce set function
sunethwarna Feb 22, 2024
8b04cec
define IndexedObject operators
sunethwarna Feb 22, 2024
e86088b
use set function in PointerVectorSet
sunethwarna Feb 22, 2024
5760f73
add operator== to closest_point
sunethwarna Feb 23, 2024
bc46807
Merge remote-tracking branch 'origin/master' into core/pointer_vector…
sunethwarna Feb 26, 2024
6e7a68f
use cbegin()
sunethwarna Feb 26, 2024
f604617
add additional insert mechanism and test
sunethwarna Feb 27, 2024
b1bc015
Merge remote-tracking branch 'origin/master' into core/pointer_vector…
sunethwarna Mar 6, 2024
1437a25
remove use of *::base()
sunethwarna Mar 6, 2024
8c58384
Merge remote-tracking branch 'origin/master' into core/pointer_vector…
sunethwarna May 29, 2024
f84b135
add reserve
sunethwarna May 29, 2024
b82885c
avoid calling insert
sunethwarna May 29, 2024
0555c33
change name
sunethwarna Jun 5, 2024
4e5f741
add additional iterator tests
sunethwarna Jun 5, 2024
2cfaa7b
remove operator def
sunethwarna Jun 5, 2024
ebea638
Merge remote-tracking branch 'origin/master' into core/pointer_vector…
sunethwarna Jun 5, 2024
359f87e
revert
sunethwarna Jun 5, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/* The mappers includes */
#include "spaces/ublas_space.h"
#include "mappers/mapper_flags.h"
#include "factories/mapper_factory.h"
#include "factories/mapper_factory.h"

// NOTE: The following contains the license of the MMG library
/* =============================================================================
Expand Down Expand Up @@ -366,6 +366,10 @@ void MmgProcess<TMMGLibrary>::InitializeMeshData()
for (auto it_dof = mDofs.begin(); it_dof != mDofs.end(); ++it_dof)
(**it_dof).FreeDof();

mrThisModelPart.Nodes().Unique();
mrThisModelPart.Conditions().Unique();
mrThisModelPart.Elements().Unique();

// Generate the maps of reference
mMmgUtilities.GenerateReferenceMaps(mrThisModelPart, aux_ref_cond, aux_ref_elem, mpRefCondition, mpRefElement);

Expand Down Expand Up @@ -590,7 +594,7 @@ void MmgProcess<TMMGLibrary>::ExecuteRemeshing()
ModelPart& r_old_auxiliar_model_part = r_old_model_part.GetSubModelPart("AUXILIAR_COLLAPSED_PRISMS");
ModelPart& r_auxiliary_model_part = mrThisModelPart.GetSubModelPart("AUXILIAR_COLLAPSED_PRISMS");

// Define mapper factory
// Define mapper factory
DEFINE_MAPPER_FACTORY_SERIAL
if (MapperFactoryType::HasMapper("nearest_element") && mThisParameters["use_mapper_if_available"].GetBool()) {
KRATOS_INFO_IF("MmgProcess", mEchoLevel > 0) << "Using MappingApplication to interpolate values" << std::endl;
Expand Down Expand Up @@ -1504,7 +1508,7 @@ const Parameters MmgProcess<TMMGLibrary>::GetDefaultParameters() const
"max_num_search_iterations" : 8,
"echo_level" : 0
}
},
},
"extrapolate_contour_values" : true,
"surface_elements" : false,
"search_parameters" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2854,7 +2854,7 @@ void MmgUtilities<MMGLibrary::MMG2D>::SetLocalParameter(
double HMin,
double HMax,
double HausdorffValue
)
)
{
if ( MMG2D_Set_localParameter(mMmgMesh, mMmgMet, MMG5_Edg, rColor, HMin, HMax, HausdorffValue) != 1)
KRATOS_ERROR << "Unable to set local parameter" << std::endl;
Expand All @@ -2869,7 +2869,7 @@ void MmgUtilities<MMGLibrary::MMG3D>::SetLocalParameter(
double HMin,
double HMax,
double HausdorffValue
)
)
{
if ( MMG3D_Set_localParameter(mMmgMesh, mMmgMet, MMG5_Triangle, rColor, HMin, HMax, HausdorffValue) != 1)
KRATOS_ERROR << "Unable to set local parameter" << std::endl;
Expand All @@ -2884,7 +2884,7 @@ void MmgUtilities<MMGLibrary::MMGS>::SetLocalParameter(
double HMin,
double HMax,
double HausdorffValue
)
)
{
if ( MMGS_Set_localParameter(mMmgMesh, mMmgMet, MMG5_Triangle, rColor, HMin, HMax, HausdorffValue) != 1)
KRATOS_ERROR << "Unable to set local parameter" << std::endl;
Expand Down Expand Up @@ -3578,6 +3578,10 @@ void MmgUtilities<TMMGLibrary>::ReorderAllIds(ModelPart& rModelPart)
for(IndexType i = 0; i < r_elements_array.size(); ++i)
(it_elem_begin + i)->SetId(i + 1);

r_nodes_array.Unique();
r_conditions_array.Unique();
r_elements_array.Unique();

KRATOS_CATCH("");
}

Expand Down Expand Up @@ -3801,6 +3805,8 @@ void MmgUtilities<TMMGLibrary>::GenerateMeshDataFromModelPart(
}
}

r_nodes_array.Unique();

/* Conditions */
counter_to_remesh = block_for_each<SumReduction<IndexType>>(
r_conditions_array,
Expand Down Expand Up @@ -3829,6 +3835,8 @@ void MmgUtilities<TMMGLibrary>::GenerateMeshDataFromModelPart(
}
}

r_conditions_array.Unique();

/* Elements */
counter_to_remesh = block_for_each<SumReduction<IndexType>>(
r_elements_array,
Expand Down Expand Up @@ -3857,6 +3865,8 @@ void MmgUtilities<TMMGLibrary>::GenerateMeshDataFromModelPart(
}
}

r_elements_array.Unique();

// Now we compute the colors
rColors.clear();
ColorsMapType nodes_colors, cond_colors, elem_colors;
Expand Down
115 changes: 115 additions & 0 deletions kratos/containers/key_generator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// | / |
// ' / __| _` | __| _ \ __|
// . \ | ( | | ( |\__ `
// _|\_\_| \__,_|\__|\___/ ____/
// Multi-Physics
//
// License: BSD License
// Kratos default license: kratos/license.txt
//
// Main authors: Suneth Warnakulasuriya
//

#pragma once

// System includes
#include <functional>
#include <type_traits>
#include <utility>

// External includes

// Project includes

namespace Kratos
{
///@name Kratos Classes
///@{

/**
* @class TestOperators
* @brief Operator class to test whether operators "<" and "==" is defined for given TDataType.
*/
struct TestOperators
{
template<class TDataType>
static auto TestEqual(TDataType*) -> decltype(std::declval<TDataType>() == std::declval<TDataType>());
template<typename>
static auto TestEqual(...) -> std::false_type;

template<class TDataType>
static auto TestLess(TDataType*) -> decltype(std::declval<TDataType>() < std::declval<TDataType>());
template<typename>
static auto TestLess(...) -> std::false_type;
};

/**
* @class KeyGenerator
* @brief A functor that serves as the identity function if "<" and "==" operators are defined, otherwise, returns memory location.
* @details This class provides two overloaded operator() functions, one for non-const objects
* and another for const objects. The operator() returns the input objects memory location as it is,
* effectively acting as an identity function for address if the operators "<" and "==" is not defined. Otherwise,
* this returns the exact input object.
*
* The purpose of this functor is to allow objects' memory locations or exact object to be used as keys in sets or other
* containers that require comparison. By using this functor, you can avoid defining
* custom comparison functions or operators when the object itself can be considered
* for comparison.
* @tparam TDataType The data type of the object that the functor operates on.
* @author Suneth Warnakulasuriya
*/
template<class TDataType>
class KeyGenerator
{
private:
///@name Private static variables
///@{

static constexpr bool HasOperatorEqual = std::is_same_v<bool, decltype(TestOperators::TestEqual<TDataType>(0))>;

static constexpr bool HasOperatorLess = std::is_same_v<bool, decltype(TestOperators::TestLess<TDataType>(0))>;

static constexpr bool HasOperatorsDefined = HasOperatorEqual && HasOperatorLess;

///@}

public:
///@name Public operators
///@{

/**
* @brief Operator that returns a non-const reference to the input object if "<" and "==" operators are defined.
* Otherwise this returns a pointer to the input object.
* @param data The input object of type TDataType.
* @return A non-const reference or pointer to the same object as provided in the parameter.
*/
std::conditional_t<HasOperatorsDefined, TDataType&, TDataType*> operator()(TDataType& rData)
{
if constexpr(HasOperatorsDefined) {
return rData;
} else {
return &rData;
}
}

/**
* @brief Operator that returns a const reference to the input object if "<" and "==" operators are defined.
* Otherwise this returns a pointer to the const input object.
* @param data The input object of type TDataType.
* @return A const reference or pointer to the same object as provided in the parameter.
*/
std::conditional_t<HasOperatorsDefined, TDataType const&, TDataType const*> operator()(const TDataType& rData) const
{
if constexpr(HasOperatorsDefined) {
return rData;
} else {
return &rData;
}
}

///@}
};

///@}

} // namespace Kratos.
Loading
Loading