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.
spatial_search_result.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: Pooyan Dadvand
11 //
12 
13 #pragma once
14 
15 // System includes
16 #include <string>
17 #include <iostream>
18 
19 // External includes
20 
21 // Project includes
22 #include "includes/define.h"
23 
24 namespace Kratos
25 {
28 
31 
33 
38 template <typename TObjectType>
40 {
41 public:
44 
47 
50 
54 
57  : mpObject(nullptr),
58  mDistance(0.0),
59  mIsObjectFound(false),
60  mIsDistanceCalculated(false)
61  {
62  }
63 
66  TObjectType* pObject,
67  const int Rank = 0
68  ) : mpObject(pObject, Rank),
69  mDistance(0.0),
70  mIsObjectFound(false),
71  mIsDistanceCalculated(false)
72  {
73  if (mpObject.get() != nullptr)
74  mIsObjectFound = true;
75  }
76 
78  SpatialSearchResult(SpatialSearchResult const& /* Other */) = default;
79 
81  SpatialSearchResult(SpatialSearchResult&& /* Other */) = default;
82 
85 
89 
91  SpatialSearchResult& operator=(SpatialSearchResult const& /*Other*/) = default;
92 
93 
97 
99  void Reset()
100  {
101  mpObject = nullptr;
102  mDistance = 0.0;
103  mIsObjectFound = false;
104  mIsDistanceCalculated = false;
105  }
106 
110 
113  return mpObject;
114  }
115 
117  TPointerType const Get() const {
118  return mpObject;
119  }
120 
122  void Set(TObjectType* pObject) {
123  mpObject = pObject;
124  mIsObjectFound = true;
125  }
126 
128  double GetDistance() const {
129  return mDistance;
130  }
131 
133  void SetDistance(const double TheDistance) {
134  mDistance = TheDistance;
135  mIsDistanceCalculated = true;
136  }
137 
139  bool GetIsObjectFound() const {
140  return mIsObjectFound;
141  }
142 
144  void SetIsObjectFound(const bool IsObjectFound) {
145  mIsObjectFound = IsObjectFound;
146  }
147 
149  bool GetIsDistanceCalculated() const {
150  return mIsDistanceCalculated;
151  }
152 
155  mIsDistanceCalculated = IsDistanceCalculated;
156  }
157 
161 
163  bool IsObjectFound() const {
164  return mIsObjectFound;
165  }
166 
168  bool IsDistanceCalculated() const {
169  return mIsDistanceCalculated;
170  }
171 
175 
177  virtual std::string Info() const
178  {
179  std::stringstream buffer;
180  buffer << "SpatialSearchResult" ;
181  return buffer.str();
182  }
183 
185  virtual void PrintInfo(std::ostream& rOStream) const {rOStream << "SpatialSearchResult";}
186 
188  virtual void PrintData(std::ostream& rOStream) const {}
189 
191 
192 private:
195 
196  TPointerType mpObject;
197  double mDistance;
198  bool mIsObjectFound;
199  bool mIsDistanceCalculated;
200 
204 
208 
209  friend class Serializer;
210 
211  void save(Serializer& rSerializer) const
212  {
213  rSerializer.save("Object", mpObject);
214  rSerializer.save("Distance", mDistance);
215  rSerializer.save("Is Object Found", mIsObjectFound);
216  rSerializer.save("Is Distance Calculated", mIsDistanceCalculated);
217  }
218 
219  void load(Serializer& rSerializer)
220  {
221  rSerializer.load("Object", mpObject);
222  rSerializer.load("Distance", mDistance);
223  rSerializer.load("Is Object Found", mIsObjectFound);
224  rSerializer.load("Is Distance Calculated", mIsDistanceCalculated);
225  }
226 
228 
229 }; // Class SpatialSearchResult
230 
234 
238 
240 template <typename TObjectType>
241 inline std::istream& operator >> (std::istream& rIStream,
243  return rIStream;
244  }
245 
247 template <typename TObjectType>
248 inline std::ostream& operator << (std::ostream& rOStream,
250 {
251  rThis.PrintInfo(rOStream);
252  rOStream << std::endl;
253  rThis.PrintData(rOStream);
254 
255  return rOStream;
256 }
258 
260 
261 } // namespace Kratos.
262 
263 
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
void load(std::string const &rTag, TDataType &rObject)
Definition: serializer.h:207
void save(std::string const &rTag, std::array< TDataType, TDataSize > const &rObject)
Definition: serializer.h:545
This class is the result of the spatial searches.
Definition: spatial_search_result.h:40
bool IsObjectFound() const
Returns true if the object is set.
Definition: spatial_search_result.h:163
KRATOS_CLASS_POINTER_DEFINITION(SpatialSearchResult)
Pointer definition of SpatialSearchResult.
virtual std::string Info() const
Turn back information as a string.
Definition: spatial_search_result.h:177
double GetDistance() const
Getting the result distance.
Definition: spatial_search_result.h:128
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: spatial_search_result.h:185
virtual ~SpatialSearchResult()
Destructor.
Definition: spatial_search_result.h:84
SpatialSearchResult & operator=(SpatialSearchResult const &)=default
Assignment operator.
SpatialSearchResult(SpatialSearchResult const &)=default
Copy constructor.
void SetIsObjectFound(const bool IsObjectFound)
Getting if the object is found.
Definition: spatial_search_result.h:144
void SetDistance(const double TheDistance)
Setting the result distance.
Definition: spatial_search_result.h:133
bool IsDistanceCalculated() const
Returns true if the distance is set.
Definition: spatial_search_result.h:168
void Reset()
Reset the result.
Definition: spatial_search_result.h:99
void Set(TObjectType *pObject)
Set the object to be pointed.
Definition: spatial_search_result.h:122
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: spatial_search_result.h:188
void SetIsDistanceCalculated(const bool IsDistanceCalculated)
Setting if the distance is calculated.
Definition: spatial_search_result.h:154
SpatialSearchResult()
Default constructor.
Definition: spatial_search_result.h:56
TPointerType Get()
Returns the global pointer to the object.
Definition: spatial_search_result.h:112
SpatialSearchResult(TObjectType *pObject, const int Rank=0)
Constructor with the resulted object.
Definition: spatial_search_result.h:65
bool GetIsDistanceCalculated() const
Getting if the distance is calculated.
Definition: spatial_search_result.h:149
bool GetIsObjectFound() const
Getting if the object is found.
Definition: spatial_search_result.h:139
GlobalPointer< TObjectType > TPointerType
Global pointer definition of TObjectType.
Definition: spatial_search_result.h:49
SpatialSearchResult(SpatialSearchResult &&)=default
Move constructor.
TPointerType const Get() const
Returns a const global pointer to the object.
Definition: spatial_search_result.h:117
TDataType * get()
Get a non-const pointer to the data.
Definition: global_pointer.h:245
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
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
def load(f)
Definition: ode_solve.py:307