How to Search neighbors

From KratosWiki
Revision as of 20:33, 18 July 2015 by Roigcarlo (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

Search neighbours

Kratos has several process and utilities already defined so the code one needs to develop is very small. We can divide this in two groups, neighbour searches, and spatial searches. In this page we are going to present the main characteristics of each method and how to use them. Also, you can find a more comprehensive guide of our spatial search implementation if you want to perform advance operations based on them.

Neighbour searches

We understand by neighbour search the operation that found all entities that are adjacent to our search target. In this sense, inside Kratos we distinguish three diferent types of neighbour searches: nodes, elements and conditions. You can find a more detailed information about these entities in PUT LINK HERE.

If this kind of search is desired, Kratos provides some processes that perform this functions. Concretely, you can use one of this four processes located in "$KRATOS_ROOT/kratos/processes/":

  • Search nodal h: IDK
  • Search neighbour nodes: Used to search the neighbours of nodes
  • Search neighbour elements: Used to search the neighbours of elements
  • Search neighbour conditions: Used to search the neighbour of conditions

Once the method Execute() of the process is called it fill the selected neighbour information for all entities of a given modelpart. To use these processes one must call its constructor with the ModelPart desired. additionally one could also add a guess of how much neighbours one expects to find Below you can find a list with some useful examples:

Search neighbour nodes

 #include "includes/model_part.h"
 #include "processes/find_nodal_neighbours_process.h"
 
 ModelPart example_modelpart;
 
 // Some usefull code...
 
 // Create the process
 FindNodalNeighboursProcess findNodesProcess(
     example_modelpart,                           // Modelpart
     10,                                          // OPTIONAL Number of expected neighbour elements per node
     10                                           // OPTIONAL Number of expected neighbour nodes per node
 )
 
 // Execute the process
 findNodesProcess.Execute()
 
 for(ModelPart::NodesContainerType::iterator n_it = example_modelpart.Nodes().begin(); n_it != example_modelpart.Nodes().end(); n_it++) {
     int neighbour_size = n_it->GetValue(NEIGHBOUR_NODES).size()
 
     std::cout << "Node: " << n_it->Id() << " has " << neighbour_size << " neighbours: " << std::endl
 
     for( WeakPointerVector< Node<3> >::iterator i = n_it->GetValue(NEIGHBOUR_NODES).begin(); i != n_it->GetValue(NEIGHBOUR_NODES).end(); i++) {
         std::cout << "\tNode: " << i->Id() std::endl
     } 
 }

Search neighbour elements

 #include "includes/model_part.h"
 #include "processes/find_elements_neighbours_process.h"
 
 ModelPart example_modelpart;
 
 // Some usefull code...
 
 // Create the process
 FindElementalNeighboursProcess findElementsProcess(
     example_modelpart,                           // Modelpart
     10                                           // OPTIONAL Number of expected neighbour elements per element
 )
 
 // Execute the process
 findElementsProcess.Execute()
 
 for(ModelPart::ElementsContainerType::iterator e_it = example_modelpart.Elements().begin(); e_it != example_modelpart.Elements().end(); e_it++) {
     int neighbour_size = e_it->GetValue(NEIGHBOUR_ELEMENTS).size()
 
     std::cout << "Element: " << n_it->Id() << " has " << neighbour_size << " neighbours: " << std::endl
 
     for( WeakPointerVector< Element >::iterator i = e_it->GetValue(NEIGHBOUR_ELEMENTS).begin(); i != e_it->GetValue(NEIGHBOUR_ELEMENTS).end(); i++) {
         std::cout << "\tElement: " << i->Id() std::endl
     } 
 }

Search neighbour conditions

 #include "includes/model_part.h"
 #include "processes/find_conditions_neighbours_process.h"
 
 ModelPart example_modelpart;
 
 // Some usefull code...
 
 // Create the process
 FindConditionsNeighboursProcess findConditionProcess(
     example_modelpart,                           // Modelpart
     10                                           // OPTIONAL Number of expected neighbour conditions per conditions
 )
 
 // Execute the process
 findConditionProcess.Execute()
 
 for(ModelPart::ConditionsContainerType::iterator c_it = example_modelpart.Conditions().begin(); c_it != example_modelpart.Conditions().end(); c_it++) {
     int neighbour_size = c_it->GetValue(NEIGHBOUR_CONDITIONS).size()
 
     std::cout << "Condition: " << n_it->Id() << " has " << neighbour_size << " neighbours: " << std::endl
 
     for( WeakPointerVector< Condition >::iterator i = e_it->GetValue(NEIGHBOUR_CONDITIONS).begin(); i != e_it->GetValue(NEIGHBOUR_CONDITIONS).end(); i++) {
         std::cout << "\tCondition: " << i->Id() std::endl
     } 
 }

Advanced use

Along with the predefined search methods explained in the previous sections it is possible to directly use the spatial containers if a more advanced use is desired. A detailed information can be found in X

Personal tools
Categories