Skip to content

Commit

Permalink
Merge pull request #11308 from KratosMultiphysics/core/clean-up-skin-…
Browse files Browse the repository at this point in the history
…detection-process
  • Loading branch information
loumalouomega authored Jun 23, 2023
2 parents 204489a + 7f8d5f1 commit 991b4b7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 56 deletions.
45 changes: 23 additions & 22 deletions kratos/processes/skin_detection_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// _|\_\_| \__,_|\__|\___/ ____/
// Multi-Physics
//
// License: BSD License
// Kratos default license: kratos/license.txt
// License: BSD License
// Kratos default license: kratos/license.txt
//
// Main authors: Vicente Mataix Ferrandiz
//
Expand Down Expand Up @@ -196,7 +196,7 @@ void SkinDetectionProcess<TDim>::FillAuxiliaryModelPart(
const std::string base_name = pre_name + r_name_condition;

// The number of conditions
ConditionsArrayType& r_condition_array = mrModelPart.GetRootModelPart().Conditions();
auto& r_condition_array = mrModelPart.GetRootModelPart().Conditions();
const auto it_cond_begin = r_condition_array.begin();
for(IndexType i = 0; i < r_condition_array.size(); ++i)
(it_cond_begin + i)->SetId(i + 1);
Expand Down Expand Up @@ -277,24 +277,24 @@ void SkinDetectionProcess<TDim>::SetUpAdditionalSubModelParts(const ModelPart& r
// We build a database of indexes
std::unordered_map<IndexType, std::unordered_set<IndexType>> conditions_nodes_ids_map;

for (auto& cond : rAuxiliaryModelPart.Conditions()) {
auto& geom = cond.GetGeometry();
for (auto& r_cond : rAuxiliaryModelPart.Conditions()) {
auto& r_geom = r_cond.GetGeometry();

for (auto& r_node : geom) {
auto set = conditions_nodes_ids_map.find(r_node.Id());
if(set != conditions_nodes_ids_map.end()) {
conditions_nodes_ids_map[r_node.Id()].insert(cond.Id());
for (auto& r_node : r_geom) {
auto it_set_found = conditions_nodes_ids_map.find(r_node.Id());
if(it_set_found != conditions_nodes_ids_map.end()) {
conditions_nodes_ids_map[r_node.Id()].insert(r_cond.Id());
} else {
std::unordered_set<IndexType> cond_index_ids ( {cond.Id()} );;
std::unordered_set<IndexType> cond_index_ids ( {r_cond.Id()} );;
conditions_nodes_ids_map.insert({r_node.Id(), cond_index_ids});
}
}
}

ModelPart& root_model_part = mrModelPart.GetRootModelPart();
ModelPart& r_root_model_part = mrModelPart.GetRootModelPart();
for (IndexType i_mp = 0; i_mp < n_model_parts; ++i_mp){
const std::string& model_part_name = mThisParameters["list_model_parts_to_assign_conditions"].GetArrayItem(i_mp).GetString();
ModelPart& sub_model_part = root_model_part.GetSubModelPart(model_part_name);
const std::string& r_model_part_name = mThisParameters["list_model_parts_to_assign_conditions"].GetArrayItem(i_mp).GetString();
ModelPart& r_sub_model_part = r_root_model_part.GetSubModelPart(r_model_part_name);

std::vector<IndexType> conditions_ids;

Expand All @@ -304,19 +304,20 @@ void SkinDetectionProcess<TDim>::SetUpAdditionalSubModelParts(const ModelPart& r
std::vector<IndexType> conditions_ids_buffer;

// We iterate over the nodes of this model part
auto& sub_nodes_array = sub_model_part.Nodes();
auto& r_sub_nodes_array = r_sub_model_part.Nodes();
const auto it_node_begin = r_sub_nodes_array.begin();
#pragma omp for
for(int i = 0; i < static_cast<int>(sub_nodes_array.size()); ++i) {
auto it_node = sub_nodes_array.begin() + i;
for(int i = 0; i < static_cast<int>(r_sub_nodes_array.size()); ++i) {
auto it_node = it_node_begin + i;

auto set = conditions_nodes_ids_map.find(it_node->Id());
if(set != conditions_nodes_ids_map.end()) {
auto it_set_found = conditions_nodes_ids_map.find(it_node->Id());
if(it_set_found != conditions_nodes_ids_map.end()) {
for (auto& r_cond_id : conditions_nodes_ids_map[it_node->Id()]) {
auto& r_condition = mrModelPart.GetCondition(r_cond_id);
auto& geom = r_condition.GetGeometry();
auto& r_geom = r_condition.GetGeometry();
bool has_nodes = true;
for (auto& r_node : geom) {
if (!sub_model_part.GetMesh().HasNode(r_node.Id())) {
for (auto& r_node : r_geom) {
if (!r_sub_model_part.GetMesh().HasNode(r_node.Id())) {
has_nodes = false;
break;
}
Expand All @@ -334,7 +335,7 @@ void SkinDetectionProcess<TDim>::SetUpAdditionalSubModelParts(const ModelPart& r
}
}

sub_model_part.AddConditions(conditions_ids);
r_sub_model_part.AddConditions(conditions_ids);
}
}
}
Expand Down
51 changes: 17 additions & 34 deletions kratos/processes/skin_detection_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
// _|\_\_| \__,_|\__|\___/ ____/
// Multi-Physics
//
// License: BSD License
// Kratos default license: kratos/license.txt
// License: BSD License
// Kratos default license: kratos/license.txt
//
// Main authors: Vicente Mataix Ferrandiz
//

#if !defined(KRATOS_SKIN_DETECTION_PROCESS_H_INCLUDED )
#define KRATOS_SKIN_DETECTION_PROCESS_H_INCLUDED
#pragma once

// System includes

Expand All @@ -36,14 +35,13 @@ namespace Kratos
///@{

// General geometry type definitions
typedef Node NodeType;
typedef Geometry<NodeType> GeometryType;
using GeometryType = Geometry<Node>;

/// The definition of the index type
typedef std::size_t IndexType;
using IndexType = std::size_t;

/// The definition of the sizetype
typedef std::size_t SizeType;
using SizeType = std::size_t;

///@}
///@name Enum's
Expand Down Expand Up @@ -76,46 +74,36 @@ class KRATOS_API(KRATOS_CORE) SkinDetectionProcess
/// Pointer definition of SkinDetectionProcess
KRATOS_CLASS_POINTER_DEFINITION(SkinDetectionProcess);

// Containers definition
typedef ModelPart::NodesContainerType NodesArrayType;
typedef ModelPart::ConditionsContainerType ConditionsArrayType;
typedef ModelPart::ElementsContainerType ElementsArrayType;

// Containers iterators definition
typedef NodesArrayType::iterator NodesIterarorType;
typedef ConditionsArrayType::iterator ConditionsIteratorType;
typedef ElementsArrayType::iterator ElementsIteratorType;

// Weak pointers vectors types
typedef GlobalPointersVector<NodeType> NodePointerVector;
typedef GlobalPointersVector<Element> ElementPointerVector;
using NodePointerVector = GlobalPointersVector<Node>;
using ElementPointerVector = GlobalPointersVector<Element>;

/// Definition of the vector indexes considered
typedef std::vector<IndexType> VectorIndexType;
using VectorIndexType = std::vector<IndexType>;

/// Definition of the hasher considered
typedef VectorIndexHasher<VectorIndexType> VectorIndexHasherType;
using VectorIndexHasherType = VectorIndexHasher<VectorIndexType>;

/// Definition of the key comparor considered
typedef VectorIndexComparor<VectorIndexType> VectorIndexComparorType;
using VectorIndexComparorType = VectorIndexComparor<VectorIndexType>;

/// Define the set considered for element pointers
typedef std::unordered_set<VectorIndexType, VectorIndexHasherType, VectorIndexComparorType > HashSetVectorIntType;
using HashSetVectorIntType = std::unordered_set<VectorIndexType, VectorIndexHasherType, VectorIndexComparorType>;

/// Define the HashSetVectorIntTypeIteratorType iterator type
typedef HashSetVectorIntType::iterator HashSetVectorIntTypeIteratorType;
using HashSetVectorIntTypeIteratorType = HashSetVectorIntType::iterator;

/// Define the map considered for face ids
typedef std::unordered_map<VectorIndexType, VectorIndexType, VectorIndexHasherType, VectorIndexComparorType > HashMapVectorIntType;
using HashMapVectorIntType = std::unordered_map<VectorIndexType, VectorIndexType, VectorIndexHasherType, VectorIndexComparorType>;

/// Define the HashMapVectorIntTypeIteratorType iterator type
typedef HashMapVectorIntType::iterator HashMapVectorIntTypeIteratorType;
using HashMapVectorIntTypeIteratorType = HashMapVectorIntType::iterator;

/// Define the map considered for properties ids
typedef std::unordered_map<VectorIndexType, IndexType, VectorIndexHasherType, VectorIndexComparorType > HashMapVectorIntIdsType;
using HashMapVectorIntIdsType = std::unordered_map<VectorIndexType, IndexType, VectorIndexHasherType, VectorIndexComparorType>;

/// Define the HashMapVectorIntIdsType iterator type
typedef HashMapVectorIntIdsType::iterator HashMapVectorIntIdsTypeIteratorType;
using HashMapVectorIntIdsTypeIteratorType = HashMapVectorIntIdsType::iterator;

///@}
///@name Life Cycle
Expand Down Expand Up @@ -332,12 +320,10 @@ class KRATOS_API(KRATOS_CORE) SkinDetectionProcess
///@name Type Definitions
///@{


///@}
///@name Input and output
///@{


/// input stream function
template<SizeType TDim>
inline std::istream& operator >> (std::istream& rIStream,
Expand All @@ -356,7 +342,4 @@ inline std::ostream& operator << (std::ostream& rOStream,
}
///@}


} // namespace Kratos.

#endif // KRATOS_SKIN_DETECTION_PROCESS_H_INCLUDED defined

0 comments on commit 991b4b7

Please sign in to comment.