KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
specialized_spatial_search_factory.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Vicente Mataix Ferrandiz
11 //
12 
13 #pragma once
14 
15 // System includes
16 
17 // External includes
18 
19 // Project includes
21 
22 namespace Kratos
23 {
26 
30 
34 
38 
42 
50  : public SpatialSearch
51 {
52 public:
55 
57 
61 
64  {
65  Parameters default_parameters = GetDefaultParameters();
66  Parameters search_parameters(default_parameters["search_parameters"].WriteJsonString());
67  mpSpatialSearch = SpatialSearch::Pointer(new SpecializedSpatialSearch<SpatialContainer::KDTree>(search_parameters));
68  }
69 
72  {
73  Parameters default_parameters = GetDefaultParameters();
74  ThisParameters.RecursivelyValidateAndAssignDefaults(default_parameters);
75  const std::string& r_container_type = ThisParameters["container_type"].GetString();
76  Parameters search_parameters(ThisParameters["search_parameters"].WriteJsonString());
77  if (r_container_type == "KDTree" || r_container_type == "kd_tree") {
78  mpSpatialSearch = SpatialSearch::Pointer(new SpecializedSpatialSearch<SpatialContainer::KDTree>(search_parameters));
79  } else if (r_container_type == "Octree" || r_container_type == "octree") {
80  mpSpatialSearch = SpatialSearch::Pointer(new SpecializedSpatialSearch<SpatialContainer::Octree>(search_parameters));
81  } else if (r_container_type == "BinsStatic" || r_container_type == "bins_static") {
82  mpSpatialSearch = SpatialSearch::Pointer(new SpecializedSpatialSearch<SpatialContainer::BinsStatic>(search_parameters));
83  } else if (r_container_type == "BinsDynamic" || r_container_type == "bins_dynamic") {
84  mpSpatialSearch = SpatialSearch::Pointer(new SpecializedSpatialSearch<SpatialContainer::BinsDynamic>(search_parameters));
85  } else {
86  KRATOS_ERROR << "Unknown container type: " << r_container_type << std::endl;
87  }
88  }
89 
91  ~SpecializedSpatialSearchFactory() override = default;
92 
96 
101  const ElementsContainerType& rStructureElements,
102  const ElementsContainerType& rInputElements,
103  const RadiusArrayType& rRadius,
105  VectorDistanceType& rResultsDistance
106  ) override
107  {
108  mpSpatialSearch->SearchElementsInRadiusExclusive(rStructureElements, rInputElements, rRadius, rResults, rResultsDistance);
109  }
110 
115  const ElementsContainerType& rStructureElements,
116  const ElementsContainerType& rInputElements,
117  const RadiusArrayType& rRadius,
119  ) override
120  {
121  mpSpatialSearch->SearchElementsInRadiusExclusive(rStructureElements, rInputElements, rRadius, rResults);
122  }
123 
128  const NodesContainerType& rStructureNodes,
129  const NodesContainerType& rInputNodes,
130  const RadiusArrayType& rRadius,
132  VectorDistanceType& rResultsDistance
133  ) override
134  {
135  mpSpatialSearch->SearchNodesInRadiusExclusive(rStructureNodes, rInputNodes, rRadius, rResults, rResultsDistance);
136  }
137 
142  const NodesContainerType& rStructureNodes,
143  const NodesContainerType& rInputNodes,
144  const RadiusArrayType& rRadius,
146  ) override
147  {
148  mpSpatialSearch->SearchNodesInRadiusExclusive(rStructureNodes, rInputNodes, rRadius, rResults);
149  }
150 
155  const ConditionsContainerType& rStructureConditions,
156  const ConditionsContainerType& rInputConditions,
157  const RadiusArrayType& rRadius,
159  VectorDistanceType& rResultsDistance
160  ) override
161  {
162  mpSpatialSearch->SearchConditionsInRadiusExclusive(rStructureConditions, rInputConditions, rRadius, rResults, rResultsDistance);
163  }
164 
169  const ConditionsContainerType& rStructureConditions,
170  const ConditionsContainerType& rInputConditions,
171  const RadiusArrayType& rRadius,
173  ) override
174  {
175  mpSpatialSearch->SearchConditionsInRadiusExclusive(rStructureConditions, rInputConditions, rRadius, rResults);
176  }
177 
181 
183  std::string Info() const override
184  {
185  std::stringstream buffer;
186  buffer << "SpecializedSpatialSearchFactory" ;
187 
188  return buffer.str();
189  }
190 
192  void PrintInfo(std::ostream& rOStream) const override
193  {
194  rOStream << "SpecializedSpatialSearchFactory";
195  }
196 
198  void PrintData(std::ostream& rOStream) const override
199  {
200 
201  }
202 
204 private:
207 
208  SpatialSearch::Pointer mpSpatialSearch = nullptr;
209 
213 
218  Parameters GetDefaultParameters() const
219  {
220  Parameters default_parameters = Parameters(R"(
221  { "container_type" : "KDTree",
222  "search_parameters" : {
223  "bucket_size" : 4,
224  "allocation_size" : 1000
225  }
226  })" );
227 
228  return default_parameters;
229  }
230 
232 }; // Class SpecializedSpatialSearchFactory
233 
237 
241 
243 inline std::ostream& operator << (std::ostream& rOStream,
244  const SpecializedSpatialSearchFactory& rThis)
245 {
246  rThis.PrintInfo(rOStream);
247  rOStream << std::endl;
248  rThis.PrintData(rOStream);
249 
250  return rOStream;
251 }
252 
254 
256 
257 } // namespace Kratos.
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
void RecursivelyValidateAndAssignDefaults(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing match the form prescribed by th...
Definition: kratos_parameters.cpp:1389
std::string GetString() const
This method returns the string contained in the current Parameter.
Definition: kratos_parameters.cpp:684
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
This class is used to search for elements, conditions and nodes in a given model part.
Definition: spatial_search.h:50
std::vector< ResultConditionsContainerType > VectorResultConditionsContainerType
Definition: spatial_search.h:92
std::vector< double > RadiusArrayType
Input/output types.
Definition: spatial_search.h:95
std::vector< DistanceType > VectorDistanceType
Definition: spatial_search.h:97
std::vector< ResultNodesContainerType > VectorResultNodesContainerType
Definition: spatial_search.h:82
std::vector< ResultElementsContainerType > VectorResultElementsContainerType
Definition: spatial_search.h:87
Factory for the specialized spatial search.
Definition: specialized_spatial_search_factory.h:51
std::string Info() const override
Turn back information as a string.
Definition: specialized_spatial_search_factory.h:183
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: specialized_spatial_search_factory.h:192
KRATOS_CLASS_POINTER_DEFINITION(SpecializedSpatialSearchFactory)
void SearchElementsInRadiusExclusive(const ElementsContainerType &rStructureElements, const ElementsContainerType &rInputElements, const RadiusArrayType &rRadius, VectorResultElementsContainerType &rResults, VectorDistanceType &rResultsDistance) override
Search neighbours for every element in "rInputElements" excluding itself.
Definition: specialized_spatial_search_factory.h:100
void SearchConditionsInRadiusExclusive(const ConditionsContainerType &rStructureConditions, const ConditionsContainerType &rInputConditions, const RadiusArrayType &rRadius, VectorResultConditionsContainerType &rResults, VectorDistanceType &rResultsDistance) override
Search neighbours for every Condition in "rInputConditions" excluding itself.
Definition: specialized_spatial_search_factory.h:154
SpecializedSpatialSearchFactory()
Default constructor.
Definition: specialized_spatial_search_factory.h:63
void SearchNodesInRadiusExclusive(const NodesContainerType &rStructureNodes, const NodesContainerType &rInputNodes, const RadiusArrayType &rRadius, VectorResultNodesContainerType &rResults) override
Search neighbours for every node in "rInputNodes" excluding itself.
Definition: specialized_spatial_search_factory.h:141
void SearchElementsInRadiusExclusive(const ElementsContainerType &rStructureElements, const ElementsContainerType &rInputElements, const RadiusArrayType &rRadius, VectorResultElementsContainerType &rResults) override
Search neighbours for every element in "rInputElements" excluding itself.
Definition: specialized_spatial_search_factory.h:114
SpecializedSpatialSearchFactory(Parameters ThisParameters)
Constructor with parameters.
Definition: specialized_spatial_search_factory.h:71
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: specialized_spatial_search_factory.h:198
~SpecializedSpatialSearchFactory() override=default
Destructor.
void SearchConditionsInRadiusExclusive(const ConditionsContainerType &rStructureConditions, const ConditionsContainerType &rInputConditions, const RadiusArrayType &rRadius, VectorResultConditionsContainerType &rResults) override
Search neighbours for every Condition in "rInputConditions" excluding itself.
Definition: specialized_spatial_search_factory.h:168
void SearchNodesInRadiusExclusive(const NodesContainerType &rStructureNodes, const NodesContainerType &rInputNodes, const RadiusArrayType &rRadius, VectorResultNodesContainerType &rResults, VectorDistanceType &rResultsDistance) override
Search neighbours for every node in "rInputNodes" excluding itself.
Definition: specialized_spatial_search_factory.h:127
This class is used to search for elements, conditions and nodes in a given model part.
Definition: specialized_spatial_search.h:72
#define KRATOS_ERROR
Definition: exception.h:161
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432