40 template<
class KeyType,
class ValueType>
61 static bool CheckValidityOfModelPartsForOperations(
63 const std::vector<ModelPart const*>& rCheckModelParts,
64 const bool ThrowError =
false);
91 template<
class TModelPartOperation>
95 const std::vector<ModelPart const*>& rOperands,
96 const bool AddNeighbourEntities)
98 std::vector<ModelPart::NodeType*> output_nodes;
99 std::vector<ModelPart::ConditionType*> output_conditions;
100 std::vector<ModelPart::ElementType*> output_elements;
106 while (p_parent_model_part != &rMainModelPart && p_parent_model_part != &p_parent_model_part->
GetParentModelPart()) {
111 <<
"The given sub model part " << rOutputSubModelPart.
FullName()
112 <<
" is not a sub model part of " << rMainModelPart.
FullName() <<
".\n";
115 ModelPartOperation<TModelPartOperation>(output_nodes, output_conditions, output_elements, *p_parent_model_part, rOperands, AddNeighbourEntities);
118 FillOutputSubModelPart(rOutputSubModelPart, *p_parent_model_part, output_nodes, output_conditions, output_elements);
132 static bool HasIntersection(
const std::vector<ModelPart*>& rIntersectionModelParts);
139 template<
class TUnaryFunc>
140 static void AddNodes(
141 std::vector<ModelPart::NodeType*>& rNodesOutput,
143 TUnaryFunc&& rIsValidEntity)
147 const auto& result = block_for_each<AccumReduction<p_entity_type>>(rNodesContainer, [&rIsValidEntity](
auto& rMainEntity) -> p_entity_type {
149 if (rIsValidEntity(p_entity)) {
156 std::for_each(result.begin(), result.end(), [&rNodesOutput](
auto pEntity) {
157 if (pEntity != nullptr) {
158 rNodesOutput.push_back(pEntity);
163 template<
class TContainerType,
class TUnaryFunc>
164 static void AddEntities(
165 std::vector<typename TContainerType::value_type*>& rEntitiesOutput,
166 TContainerType& rMainEntityContainer,
167 TUnaryFunc&& rIsValidEntity)
169 using p_entity_type =
typename TContainerType::value_type*;
170 const auto& result = block_for_each<AccumReduction<p_entity_type>>(rMainEntityContainer, CNodePointersType(), [&rIsValidEntity](
auto& rMainEntity, CNodePointersType& rTLS) -> p_entity_type {
171 const auto& r_geometry = rMainEntity.GetGeometry();
172 const IndexType number_of_nodes = r_geometry.size();
174 if (rTLS.size() != number_of_nodes) {
175 rTLS.resize(number_of_nodes);
179 rTLS[
i] = &r_geometry[
i];
182 std::sort(rTLS.begin(), rTLS.end());
184 if (rIsValidEntity(rTLS)) {
191 std::for_each(result.begin(), result.end(), [&rEntitiesOutput](
auto pEntity) {
192 if (pEntity != nullptr) {
193 rEntitiesOutput.push_back(pEntity);
198 template<
class TModelPartOperation>
199 static void ModelPartOperation(
200 std::vector<ModelPart::NodeType*>& rOutputNodes,
201 std::vector<ModelPart::ConditionType*>& rOutputConditions,
202 std::vector<ModelPart::ElementType*>& rOutputElements,
203 ModelPart& rMainModelPart,
204 const std::vector<ModelPart const*>& rOperands,
205 const bool AddNeighbourEntities)
207 const IndexType number_of_operation_model_parts = rOperands.size();
209 std::vector<std::set<ModelPart::NodeType const*>> set_operation_node_sets(number_of_operation_model_parts);
210 std::vector<std::set<CNodePointersType>> set_operation_condition_sets(number_of_operation_model_parts);
211 std::vector<std::set<CNodePointersType>> set_operation_element_sets(number_of_operation_model_parts);
214 for (
IndexType i = 0;
i < number_of_operation_model_parts; ++
i) {
215 auto p_model_part = rOperands[
i];
218 FillNodesPointerSet(set_operation_node_sets[
i], p_model_part->Nodes());
221 FillNodePointersForEntities(set_operation_condition_sets[
i], p_model_part->Conditions());
224 FillNodePointersForEntities(set_operation_element_sets[
i], p_model_part->Elements());
227 AddNodes(rOutputNodes, rMainModelPart.Nodes(), [&set_operation_node_sets](
auto& rEntity) {
228 return TModelPartOperation::IsValid(rEntity, set_operation_node_sets);
231 AddEntities(rOutputConditions, rMainModelPart.Conditions(), [&set_operation_condition_sets](
auto& rEntity) {
232 return TModelPartOperation::IsValid(rEntity, set_operation_condition_sets);
235 AddEntities(rOutputElements, rMainModelPart.Elements(), [&set_operation_element_sets](
auto& rEntity) {
236 return TModelPartOperation::IsValid(rEntity, set_operation_element_sets);
240 if (AddNeighbourEntities) {
242 FillNodesFromEntities<ModelPart::ConditionType>(rOutputNodes, rOutputConditions.begin(), rOutputConditions.end());
243 FillNodesFromEntities<ModelPart::ElementType>(rOutputNodes, rOutputElements.begin(), rOutputElements.end());
246 AddNeighbours(rOutputNodes, rOutputConditions, rOutputElements, rMainModelPart);
250 static void FillNodesPointerSet(
251 std::set<ModelPart::NodeType const*>& rOutput,
254 template <
class TContainerType>
255 static void FillNodePointersForEntities(
256 std::set<CNodePointersType>& rOutput,
257 const TContainerType& rEntityContainer);
259 static void FillCommonNodes(
262 const std::set<ModelPart::NodeType const*>& rNodesSet);
264 template<
class TEntityType>
265 static void FillNodesFromEntities(
266 std::vector<ModelPart::NodeType*>& rOutput,
267 typename std::vector<TEntityType*>::iterator pEntityBegin,
268 typename std::vector<TEntityType*>::iterator pEntityEnd);
270 template<
class TContainerType>
271 static void FindNeighbourEntities(
272 std::vector<typename TContainerType::value_type*>& rOutputEntities,
273 const Flags& rNodeSelectionFlag,
274 TContainerType& rMainEntities);
276 static void AddNeighbours(
277 std::vector<ModelPart::NodeType*>& rOutputNodes,
278 std::vector<ModelPart::ConditionType*>& rOutputConditions,
279 std::vector<ModelPart::ElementType*>& rOutputElements,
280 ModelPart& rMainModelPart);
282 static void FillWithMainNodesFromSearchNodes(
287 static void SetCommunicator(
288 ModelPart& rOutputModelPart,
289 ModelPart& rMainModelPart);
291 static void FillOutputSubModelPart(
292 ModelPart& rOutputSubModelPart,
293 ModelPart& rMainModelPart,
294 std::vector<ModelPart::NodeType*>& rOutputNodes,
295 std::vector<ModelPart::ConditionType*>& rOutputConditions,
296 std::vector<ModelPart::ElementType*>& rOutputElements);
298 static void CheckNodes(
299 std::vector<IndexType>& rNodeIdsWithIssues,
301 const std::set<ModelPart::NodeType const*>& rMainNodes);
303 template<
class TContainerType>
304 static void CheckEntities(
305 std::vector<IndexType>& rEntityIdsWithIssues,
306 const TContainerType& rCheckEntities,
307 const std::set<CNodePointersType>& rMainEntities);
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
std::string FullName() const
This method returns the full name of the model part (including the parents model parts)
Definition: model_part.h:1850
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
ModelPart & GetParentModelPart()
Definition: model_part.cpp:2124
Definition: model_part_operation_utilities.h:31
std::unordered_map< KeyType, ValueType, KeyHasherRange< KeyType >, KeyComparorRange< KeyType > > RangedKeyMapType
Definition: model_part_operation_utilities.h:41
std::vector< ModelPart::NodeType const * > CNodePointersType
Definition: model_part_operation_utilities.h:38
std::size_t IndexType
Definition: model_part_operation_utilities.h:36
static void FillSubModelPart(ModelPart &rOutputSubModelPart, const ModelPart &rMainModelPart, const std::vector< ModelPart const * > &rOperands, const bool AddNeighbourEntities)
Fill a sub model part with the specified operation.
Definition: model_part_operation_utilities.h:92
This class defines the node.
Definition: node.h:65
std::size_t IndexType
The definition of the index type.
Definition: key_hash.h:35
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
integer i
Definition: TensorModule.f:17
This is a key comparer of general pourpose between two classes.
Definition: key_hash.h:100