10 #if !defined(KRATOS_ELEMENTAL_NEIGHBOURS_SEARCH_PROCESS_H_INCLUDED )
11 #define KRATOS_ELEMENTAL_NEIGHBOURS_SEARCH_PROCESS_H_INCLUDED
77 int AverageElements = 10)
78 : mrModelPart(rModelPart)
80 mAverageElements = AverageElements;
81 mDimension = Dimension;
116 success=KratosSearch();
121 success=LohnerSearch();
126 std::cout<<
" ERROR: Element Neighbours Search FAILED !!! "<<std::endl;
144 for(
auto& i_node: mrModelPart.
Nodes())
149 for(
auto& i_elem : mrModelPart.
Elements())
171 std::string
Info()
const override
173 return "ElementalNeighboursSearchProcess";
179 rOStream <<
"ElementalNeighboursSearchProcess";
222 int mAverageElements;
229 template<
class TDataType>
void AddUniquePointer
234 while (
i != endit && (
i)->Id() != (candidate.lock())->Id())
240 v.push_back(candidate);
248 for(
auto i_nelem(nElements.begin()); i_nelem != nElements.end(); ++i_nelem)
251 Geometry<Node >& nGeometry = i_nelem->GetGeometry();
252 if(nGeometry.LocalSpaceDimension() == 1){
253 for(
unsigned int node_i = 0; node_i < nGeometry.size(); ++node_i)
255 if(nGeometry[node_i].Id() == Id_1)
257 if(i_nelem->Id() != i_elem->Id())
259 return Element::WeakPointer(*i_nelem.base());
265 return Element::WeakPointer(*i_elem.base());
272 for(
auto i_nelem(nElements.begin()); i_nelem != nElements.end(); ++i_nelem)
275 Geometry<Node >& nGeometry = i_nelem->GetGeometry();
276 if(nGeometry.LocalSpaceDimension() == 2){
277 for(
unsigned int node_i = 0; node_i < nGeometry.size(); ++node_i)
279 if (nGeometry[node_i].Id() == Id_2)
281 if(i_nelem->Id() != i_elem->Id())
283 return *i_nelem.base();
289 return *i_elem.base();
295 for(
auto i_nelem(nElements.begin()); i_nelem != nElements.end(); ++i_nelem)
298 Geometry<Node >& nGeometry = i_nelem->GetGeometry();
299 if(nGeometry.LocalSpaceDimension() == 3){
300 for(
unsigned int node_i = 0; node_i < nGeometry.size(); ++node_i)
302 if(nGeometry[node_i].Id() == Id_2)
304 for(
unsigned int node_j = 0; node_j < nGeometry.size(); ++node_j)
306 if (nGeometry[node_j].Id() == Id_3)
307 if(i_nelem->Id() != i_elem->Id())
309 return *i_nelem.base();
316 return *i_elem.base();
320 void ResetFlagOptions (Node& rNode)
322 rNode.Reset(BOUNDARY);
325 void ResetFlagOptions (Element& rElement)
327 rElement.Reset(BOUNDARY);
331 void CleanElementNeighbours()
340 for(
auto& i_node : mrModelPart.Nodes())
342 auto& nElements = i_node.GetValue(NEIGHBOUR_ELEMENTS);
344 nElements.reserve(mAverageElements);
346 ResetFlagOptions(i_node);
350 for(
auto& i_elem : mrModelPart.Elements())
352 auto& nElements = i_elem.GetValue(NEIGHBOUR_ELEMENTS);
354 nElements.resize(i_elem.GetGeometry().FacesNumber());
356 ResetFlagOptions(i_elem);
363 void PrintElementNeighbours()
367 std::cout<<
" NODES: neighbour elems: "<<std::endl;
368 for(
auto& i_node : mrModelPart.Nodes())
370 std::cout<<
"["<<i_node.Id()<<
"]:"<<std::endl;
372 auto& nElements = i_node.GetValue(NEIGHBOUR_ELEMENTS);
373 for(
const auto& i_nelem : nElements)
375 std::cout<< i_nelem.Id()<<
", ";
377 std::cout<<
" )"<<std::endl;
380 std::cout<<std::endl;
382 std::cout<<
" ELEMENTS: neighbour elems: "<<std::endl;
384 for(
auto& i_elem : mrModelPart.Elements())
386 std::cout<<
"["<<i_elem.Id()<<
"]:"<<std::endl;
388 auto& nElements = i_elem.GetValue(NEIGHBOUR_ELEMENTS);
389 for(
auto& i_nelem : nElements)
391 std::cout<< i_nelem.Id()<<
", ";
393 std::cout<<
" )"<<std::endl;
397 std::cout<<std::endl;
415 CleanElementNeighbours();
420 for(
auto i_elem(rElements.begin()); i_elem != rElements.end(); ++i_elem)
423 for(
unsigned int i = 0;
i < rGeometry.size(); ++
i)
425 rGeometry[
i].GetValue(NEIGHBOUR_ELEMENTS).push_back(*i_elem.base());
432 unsigned int search_performed =
false;
437 for(
auto i_elem(rElements.begin()); i_elem != rElements.end(); ++i_elem)
440 Geometry<Node >& rGeometry = i_elem->GetGeometry();
442 if( rGeometry.FacesNumber() == 3 ){
444 auto& nElements = i_elem->GetValue(NEIGHBOUR_ELEMENTS);
446 if(nElements.size() != 3 )
452 nElements(0) = CheckForNeighbourElems2D(rGeometry[1].Id(), rGeometry[2].Id(), rGeometry[1].
GetValue(NEIGHBOUR_ELEMENTS), i_elem);
454 nElements(1) = CheckForNeighbourElems2D(rGeometry[2].Id(), rGeometry[0].Id(), rGeometry[2].
GetValue(NEIGHBOUR_ELEMENTS), i_elem);
456 nElements(2) = CheckForNeighbourElems2D(rGeometry[0].Id(), rGeometry[1].Id(), rGeometry[0].
GetValue(NEIGHBOUR_ELEMENTS), i_elem);
458 unsigned int iface=0;
459 for(
auto& i_nelem : nElements)
461 if (i_nelem.Id() == i_elem->Id())
463 i_elem->Set(BOUNDARY);
465 DenseMatrix<unsigned int> lpofa;
466 rGeometry.NodesInFaces(lpofa);
468 for(
unsigned int i = 1;
i < rGeometry.FacesNumber(); ++
i)
470 rGeometry[lpofa(
i,iface)].Set(BOUNDARY);
477 else if( rGeometry.FacesNumber() == 2 ){
479 auto& nElements = i_elem->GetValue(NEIGHBOUR_ELEMENTS);
482 if( nElements.size() != 2 )
488 nElements(0) = CheckForNeighbourElems1D(rGeometry[0].Id(), rGeometry[0].
GetValue(NEIGHBOUR_ELEMENTS), i_elem);
490 nElements(1) = CheckForNeighbourElems1D(rGeometry[1].Id(), rGeometry[1].
GetValue(NEIGHBOUR_ELEMENTS), i_elem);
492 unsigned int iface=0;
493 for(
auto& i_nelem : nElements)
495 if(i_nelem.Id() == i_elem->Id())
497 i_elem->Set(BOUNDARY);
499 DenseMatrix<unsigned int> lpofa;
500 rGeometry.NodesInFaces(lpofa);
502 for(
unsigned int i = 1;
i < rGeometry.FacesNumber(); ++
i)
504 rGeometry[lpofa(
i,iface)].Set(BOUNDARY);
512 search_performed =
true;
517 for(
auto i_elem(rElements.begin()); i_elem != rElements.end(); ++i_elem)
520 Geometry<Node >& rGeometry = i_elem->GetGeometry();
522 if(rGeometry.FacesNumber() == 4){
525 auto& nElements = i_elem->GetValue(NEIGHBOUR_ELEMENTS);
527 if(nElements.size() != 4)
533 nElements(0) = CheckForNeighbourElems3D(rGeometry[1].Id(), rGeometry[2].Id(), rGeometry[3].Id(), rGeometry[1].
GetValue(NEIGHBOUR_ELEMENTS), i_elem);
535 nElements(1) = CheckForNeighbourElems3D(rGeometry[2].Id(), rGeometry[3].Id(), rGeometry[0].Id(), rGeometry[2].
GetValue(NEIGHBOUR_ELEMENTS), i_elem);
537 nElements(2) = CheckForNeighbourElems3D(rGeometry[3].Id(), rGeometry[0].Id(), rGeometry[1].Id(), rGeometry[3].
GetValue(NEIGHBOUR_ELEMENTS), i_elem);
539 nElements(3) = CheckForNeighbourElems3D(rGeometry[0].Id(), rGeometry[1].Id(), rGeometry[2].Id(), rGeometry[0].
GetValue(NEIGHBOUR_ELEMENTS), i_elem);
542 unsigned int iface=0;
543 for(
auto& i_nelem : nElements)
545 if(i_nelem.Id() == i_elem->Id())
547 i_elem->Set(BOUNDARY);
549 DenseMatrix<unsigned int> lpofa;
550 rGeometry.NodesInFaces(lpofa);
552 for(
unsigned int i = 1;
i < rGeometry.FacesNumber(); ++
i)
554 rGeometry[lpofa(
i,iface)].Set(BOUNDARY);
562 else if(rGeometry.FacesNumber() == 3){
565 auto& nElements = i_elem->GetValue(NEIGHBOUR_ELEMENTS);
567 if(nElements.size() != 3)
573 nElements(0) = CheckForNeighbourElems2D(rGeometry[1].Id(), rGeometry[2].Id(), rGeometry[1].
GetValue(NEIGHBOUR_ELEMENTS), i_elem);
575 nElements(1) = CheckForNeighbourElems2D(rGeometry[2].Id(), rGeometry[0].Id(), rGeometry[2].
GetValue(NEIGHBOUR_ELEMENTS), i_elem);
577 nElements(2) = CheckForNeighbourElems2D(rGeometry[0].Id(), rGeometry[1].Id(), rGeometry[0].
GetValue(NEIGHBOUR_ELEMENTS), i_elem);
579 unsigned int iface=0;
580 for(
auto& i_nelem : nElements)
582 if(i_nelem.Id() == i_elem->Id())
584 i_elem->Set(BOUNDARY);
586 Geometry<Node >& rGeometry = (i_elem)->GetGeometry();
588 DenseMatrix<unsigned int> lpofa;
589 rGeometry.NodesInFaces(lpofa);
591 for(
unsigned int i = 1;
i < rGeometry.FacesNumber(); ++
i)
593 rGeometry[lpofa(
i,iface)].Set(BOUNDARY);
601 search_performed =
true;
604 if( mrModelPart.NumberOfElements()>0 && search_performed )
622 unsigned int Ne=rElements.size();
623 unsigned int Np=rNodes.size();
626 CleanElementNeighbours();
631 for(
auto i_elem(rElements.begin()); i_elem != rElements.end(); ++i_elem)
634 if(rGeometry.LocalSpaceDimension() == mrModelPart.GetProcessInfo()[SPACE_DIMENSION]){
635 for(
unsigned int i = 0;
i < rGeometry.size(); ++
i)
637 rGeometry[
i].GetValue(NEIGHBOUR_ELEMENTS).push_back(*i_elem.base());
646 unsigned int ipoin=0;
647 unsigned int nnofa=0;
648 unsigned int jelem=0;
649 unsigned int icoun=0;
650 unsigned int jpoin=0;
651 unsigned int nnofj=0;
652 unsigned int nface=0;
654 DenseVector<unsigned int> lnofa;
655 DenseMatrix<unsigned int> lpofa;
658 unsigned int Nf= rGeometry.FacesNumber();
661 rGeometry.NumberNodesInFaces(lnofa);
662 rGeometry.NodesInFaces(lpofa);
665 DenseVector<unsigned int> lhelp (Nf-1);
667 DenseVector<unsigned int> lpoin (Np+1);
673 #pragma omp parallel for reduction(+:nface) private(el,ipoin,nnofa,jelem,icoun,jpoin,nnofj) firstprivate(lhelp,lpoin)
677 for (
unsigned int nf=0; nf<Nf; ++nf)
682 rElements[
el].GetValue(NEIGHBOUR_ELEMENTS)(nf) = rElements(
el);
685 for (
unsigned int t=0;
t<nnofa; ++
t)
687 lhelp(
t)=rElements[
el].GetGeometry()[lpofa(
t,nf)].Id();
693 auto& nElements = rNodes[ipoin].GetValue(NEIGHBOUR_ELEMENTS);
695 for(
auto& i_nelem : nElements)
698 unsigned int ielem =rElements[
el].Id();
703 for(
unsigned int fel=0; fel<Nf; ++fel)
711 for (
unsigned int jnofa=0; jnofa<nnofa; ++jnofa)
713 jpoin= rElements[jelem].GetGeometry()[lpofa(jnofa,fel)].Id();
714 icoun= icoun+lpoin(jpoin);
720 rElements[
el].GetValue(NEIGHBOUR_ELEMENTS)(nf) = rElements(jelem);
729 if (rElements[
el].
GetValue(NEIGHBOUR_ELEMENTS)[nf].Id() == rElements[
el].Id())
732 rElements[
el].Set(BOUNDARY);
735 for (
unsigned int t=0;
t<nnofa; ++
t)
737 rNodes[lhelp(
t)].Set(BOUNDARY);
746 for (
unsigned int r=0; r<nnofa; ++r)
756 for(
auto& i_elem : rElements)
759 for(
unsigned int i = 0;
i < rGeometry.size(); ++
i)
761 if(rGeometry[
i].
Is(BOUNDARY))
763 i_elem.Set(BOUNDARY);
824 rOStream << std::endl;
Geometry< NodeType > GeometryType
definition of the geometry type with given NodeType
Definition: element.h:83
Short class definition.
Definition: elemental_neighbours_search_process.hpp:48
void ClearNeighbours()
Definition: elemental_neighbours_search_process.hpp:142
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: elemental_neighbours_search_process.hpp:105
std::string Info() const override
Turn back information as a string.
Definition: elemental_neighbours_search_process.hpp:171
GlobalPointersVector< Condition > ConditionWeakPtrVectorType
Definition: elemental_neighbours_search_process.hpp:64
KRATOS_CLASS_POINTER_DEFINITION(ElementalNeighboursSearchProcess)
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: elemental_neighbours_search_process.hpp:183
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: elemental_neighbours_search_process.hpp:177
virtual ~ElementalNeighboursSearchProcess()
Destructor.
Definition: elemental_neighbours_search_process.hpp:86
ElementalNeighboursSearchProcess(ModelPart &rModelPart, int Dimension, int EchoLevel=0, int AverageElements=10)
Definition: elemental_neighbours_search_process.hpp:74
Node::WeakPointer NodeWeakPtrType
Definition: elemental_neighbours_search_process.hpp:58
Element::WeakPointer ElementWeakPtrType
Definition: elemental_neighbours_search_process.hpp:59
GlobalPointersVector< Node > NodeWeakPtrVectorType
Definition: elemental_neighbours_search_process.hpp:62
void operator()()
Definition: elemental_neighbours_search_process.hpp:95
ModelPart::ElementsContainerType ElementsContainerType
Definition: elemental_neighbours_search_process.hpp:56
ModelPart::NodesContainerType NodesContainerType
Definition: elemental_neighbours_search_process.hpp:55
GlobalPointersVector< Element > ElementWeakPtrVectorType
Definition: elemental_neighbours_search_process.hpp:63
Condition::WeakPointer ConditionWeakPtrType
Definition: elemental_neighbours_search_process.hpp:60
bool Is(Flags const &rOther) const
Definition: flags.h:274
This class is a vector which stores global pointers.
Definition: global_pointers_vector.h:61
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: global_pointers_vector.h:79
void clear()
Definition: global_pointers_vector.h:361
The base class for processes passed to the solution scheme.
Definition: mesher_process.hpp:37
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
static int EchoLevel
Definition: co_sim_EMPIRE_API.h:42
Parameters GetValue(Parameters &rParameters, const std::string &rEntry)
Definition: add_kratos_parameters_to_python.cpp:53
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
REACTION_CHECK_STIFFNESS_FACTOR int
Definition: contact_structural_mechanics_application_variables.h:75
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
v
Definition: generate_convection_diffusion_explicit_element.py:114
int t
Definition: ode_solve.py:392
el
Definition: read_stl.py:25
integer i
Definition: TensorModule.f:17