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.
cell.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: Nelson Lafontaine
11 //
12 
13 #pragma once
14 
15 // System includes
16 #include <string>
17 #include <iostream>
18 #include <cmath>
19 #include <algorithm>
20 
21 // External includes
22 
23 // Project includes
24 
25 namespace Kratos
26 {
27 
30 
34 
38 
42 
46 
47 template< class TConfigure>
48 class Cell
49 {
50 public:
53 
55  typedef std::size_t SizeType;
56  typedef typename TConfigure::PointType PointType;
57  typedef typename TConfigure::PointerType PointerType;
62  typedef typename TConfigure::DistanceIteratorType DistanceIteratorType;
63 
64  typedef std::vector<PointerType> LocalContainerType;
65  typedef typename LocalContainerType::iterator LocalIteratorType;
66 
69 
73 
75  Cell()
76  {
77  }
78 
80  virtual ~Cell() {}
81 
82 
83  void Add(const PointerType& ThisObject)
84  {
85  mObjects.push_back(ThisObject);
86  }
87 
88  void Remove(const PointerType& ThisObject)
89  {
90  mObjects.erase(std::remove(mObjects.begin(),mObjects.end(),ThisObject),mObjects.end());
91  }
92 
93  // This is a zero based index of object in local array
94  void Remove(const std::size_t Index)
95  {
96  std::swap(mObjects[Index], mObjects.back());
97  mObjects.pop_back();
98  }
99 
100  void Clear()
101  {
102  mObjects.clear();
103  }
104 
105 
106  void AllocateCell(const std::size_t size)
107  {
108  mObjects.reserve(size);
109  }
110 
111 
113  Cell& operator=(Cell const& rOther)
114  {
115  mObjects = rOther.mObjects;
116  return *this;
117  }
118 
119 
121  Cell(Cell const& rOther) :
122  mObjects(rOther.mObjects)
123  {
124  }
125 
126  void SearchObjects(PointerType& rThisObject, ResultIteratorType& Result, SizeType& NumberOfResults, const SizeType& MaxNumberOfResults)
127  {
128  for(LocalIteratorType i_object = Begin() ; i_object != End() && NumberOfResults < MaxNumberOfResults ; i_object++)
129  {
130  if(TConfigure::Intersection(rThisObject, *i_object))
131  {
132  ResultIteratorType repeated_object = std::find(Result-NumberOfResults, Result, *i_object);
133  if(repeated_object==Result)
134  {
135  *Result = *i_object;
136  Result++;
137  NumberOfResults++;
138  }
139  }
140  }
141  }
142 
143  void SearchObjects(PointerType& rThisObject, ResultContainerType& Result)
144  {
145  for(LocalIteratorType i_object = Begin() ; i_object != End(); i_object++)
146  {
147  if(TConfigure::Intersection(rThisObject, *i_object))
148  {
149  ResultIteratorType repeated_object = std::find(Result.begin(), Result.end(), *i_object);
150  if(repeated_object==Result.end())
151  {
152  Result.push_back(*i_object);
153  }
154  }
155  }
156  }
157 
158  void SearchObjectsExclusive(PointerType& rThisObject, ResultIteratorType& Result, SizeType& NumberOfResults, const SizeType& MaxNumberOfResults)
159  {
160  for(LocalIteratorType i_object = Begin() ; i_object != End() && NumberOfResults < MaxNumberOfResults ; i_object++)
161  {
162  if( rThisObject != *i_object )
163  {
164  if(TConfigure::Intersection(rThisObject, *i_object))
165  {
166  ResultIteratorType repeated_object = std::find(Result-NumberOfResults, Result, *i_object);
167  if(repeated_object==Result)
168  {
169  *Result = *i_object;
170  Result++;
171  NumberOfResults++;
172  }
173  }
174  }
175  }
176  }
177 
179  {
180  for(LocalIteratorType i_object = Begin() ; i_object != End(); i_object++)
181  {
182  if( rThisObject != *i_object )
183  {
184  if(TConfigure::Intersection(rThisObject, *i_object))
185  {
186  ResultIteratorType repeated_object = std::find(Result.begin(), Result.end(), *i_object);
187  if(repeated_object==Result.end())
188  {
189  Result.push_back(*i_object);
190  }
191  }
192  }
193  }
194  }
195 
196  void SearchObjectsInRadius(PointerType& rThisObject, double const& Radius, ResultIteratorType& Result, SizeType& NumberOfResults, const SizeType& MaxNumberOfResults)
197  {
198  for(LocalIteratorType i_object = Begin() ; i_object != End() && NumberOfResults < MaxNumberOfResults ; i_object++)
199  {
200  if(TConfigure::Intersection(rThisObject, *i_object, Radius))
201  {
202  ResultIteratorType repeated_object = std::find(Result-NumberOfResults, Result, *i_object);
203  if(repeated_object==Result)
204  {
205  *Result = *i_object;
206  Result++;
207  NumberOfResults++;
208  }
209  }
210  }
211  }
212 
213  void SearchObjectsInRadiusExclusive(PointerType& rThisObject, double const& Radius, ResultIteratorType& Result, SizeType& NumberOfResults, const SizeType& MaxNumberOfResults)
214  {
215  for(LocalIteratorType i_object = Begin() ; i_object != End() && NumberOfResults < MaxNumberOfResults ; i_object++)
216  {
217  if( rThisObject != *i_object )
218  {
219  if(TConfigure::Intersection(rThisObject, *i_object, Radius))
220  {
221  ResultIteratorType repeated_object = std::find(Result-NumberOfResults, Result, *i_object);
222  if(repeated_object==Result)
223  {
224  *Result = *i_object;
225  Result++;
226  NumberOfResults++;
227  }
228  }
229  }
230  }
231  }
232 
233  void SearchObjectsInRadius(PointerType& rThisObject, double const& Radius, ResultIteratorType& Result, DistanceIteratorType& Distances, SizeType& NumberOfResults, const SizeType& MaxNumberOfResults)
234  {
235  for(LocalIteratorType i_object = Begin() ; i_object != End() && NumberOfResults < MaxNumberOfResults ; i_object++)
236  {
237  if(TConfigure::Intersection(rThisObject, *i_object, Radius))
238  {
239  ResultIteratorType repeated_object = std::find(Result-NumberOfResults, Result, *i_object);
240  if(repeated_object==Result)
241  {
242  double distance = 0;
243  TConfigure::Distance(rThisObject,*i_object,distance); // squared distance function
244  *Result = *i_object;
245  Result++;
246  *Distances = distance;
247  Distances++;
248  NumberOfResults++;
249  }
250  }
251  }
252  }
253 
254  void SearchObjectsInRadiusExclusive(PointerType& rThisObject, double const& Radius, ResultIteratorType& Result, DistanceIteratorType& Distances, SizeType& NumberOfResults, const SizeType& MaxNumberOfResults)
255  {
256  for(LocalIteratorType i_object = Begin() ; i_object != End() && NumberOfResults < MaxNumberOfResults ; i_object++)
257  {
258  if( rThisObject != *i_object )
259  {
260  if(TConfigure::Intersection(rThisObject, *i_object, Radius))
261  {
262  ResultIteratorType repeated_object = std::find(Result-NumberOfResults, Result, *i_object);
263  if(repeated_object==Result)
264  {
265  double distance = 0;
266  TConfigure::Distance(rThisObject,*i_object,distance); // squared distance function
267  *Result = *i_object;
268  Result++;
269  *Distances = distance;
270  Distances++;
271  NumberOfResults++;
272  }
273  }
274  }
275  }
276  }
277 
279  {
280  return mObjects.begin();
281  }
282 
284  {
285  return mObjects.end();
286  }
287 
289  {
290  return mObjects.size();
291  }
292 
294  {
295  return mObjects.begin();
296  }
297 
299  {
300  return mObjects.end();
301  }
302 
303  SizeType Size() const
304  {
305  return mObjects.size();
306  }
307 
309  {
310  return mObjects[Index];
311  }
312 
316 
320 
324 
328 
332 
334  virtual std::string Info() const
335  {
336  return "Cell Class ";
337  }
338 
340  virtual void PrintInfo(std::ostream& rOStream) const
341  {
342  return;
343  }
344 
346  virtual void PrintData(std::ostream& rOStream) const
347  {
348  return;
349  }
350 
354 
356 protected:
359 
363 
367 
371 
375 
379 
383 
385 private:
388 
392 
393  std::vector<PointerType> mObjects;
394 
398 
402 
406 
410 
414 
416 
417 }; // Class Cell
418 
420 
423 
424 
428 
429 
431 template< class TConfigure>
432 inline std::istream& operator >> (std::istream& rIStream,
433  Cell<TConfigure>& rThis)
434 {
435  return rIStream;
436 }
437 
439 template< class TConfigure>
440 inline std::ostream& operator << (std::ostream& rOStream,
441  const Cell<TConfigure>& rThis)
442 {
443  rThis.PrintInfo(rOStream);
444  rOStream << std::endl;
445  rThis.PrintData(rOStream);
446 
447  return rOStream;
448 }
450 
451 
452 } // namespace Kratos.
453 
454 
Definition: cell.h:49
void SearchObjectsExclusive(PointerType &rThisObject, ResultContainerType &Result)
Definition: cell.h:178
Cell(Cell const &rOther)
Copy constructor.
Definition: cell.h:121
void SearchObjectsInRadiusExclusive(PointerType &rThisObject, double const &Radius, ResultIteratorType &Result, SizeType &NumberOfResults, const SizeType &MaxNumberOfResults)
Definition: cell.h:213
void Add(const PointerType &ThisObject)
Definition: cell.h:83
std::size_t SizeType
configure types
Definition: cell.h:55
virtual std::string Info() const
Turn back information as a string.
Definition: cell.h:334
SizeType Size() const
Definition: cell.h:303
TConfigure::ContainerType ContainerType
Definition: cell.h:58
TConfigure::PointType PointType
Definition: cell.h:56
void SearchObjects(PointerType &rThisObject, ResultIteratorType &Result, SizeType &NumberOfResults, const SizeType &MaxNumberOfResults)
Definition: cell.h:126
TConfigure::DistanceIteratorType DistanceIteratorType
Definition: cell.h:62
LocalContainerType::iterator LocalIteratorType
Definition: cell.h:65
void SearchObjectsInRadiusExclusive(PointerType &rThisObject, double const &Radius, ResultIteratorType &Result, DistanceIteratorType &Distances, SizeType &NumberOfResults, const SizeType &MaxNumberOfResults)
Definition: cell.h:254
void Remove(const PointerType &ThisObject)
Definition: cell.h:88
void Remove(const std::size_t Index)
Definition: cell.h:94
TConfigure::IteratorType IteratorType
Definition: cell.h:59
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: cell.h:346
TConfigure::ResultContainerType ResultContainerType
Definition: cell.h:60
void SearchObjectsExclusive(PointerType &rThisObject, ResultIteratorType &Result, SizeType &NumberOfResults, const SizeType &MaxNumberOfResults)
Definition: cell.h:158
LocalIteratorType End()
Definition: cell.h:283
void SearchObjectsInRadius(PointerType &rThisObject, double const &Radius, ResultIteratorType &Result, DistanceIteratorType &Distances, SizeType &NumberOfResults, const SizeType &MaxNumberOfResults)
Definition: cell.h:233
virtual ~Cell()
Destructor.
Definition: cell.h:80
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: cell.h:340
void AllocateCell(const std::size_t size)
Definition: cell.h:106
TConfigure::PointerType PointerType
Definition: cell.h:57
std::vector< PointerType > LocalContainerType
Definition: cell.h:64
Cell()
Default constructor.
Definition: cell.h:75
LocalIteratorType Begin()
Definition: cell.h:278
LocalIteratorType End() const
Definition: cell.h:298
Cell & operator=(Cell const &rOther)
Assignment operator.
Definition: cell.h:113
SizeType Size()
Definition: cell.h:288
KRATOS_CLASS_POINTER_DEFINITION(Cell)
Pointer definition of Cell.
PointerType GetObject(std::size_t Index)
Definition: cell.h:308
void SearchObjects(PointerType &rThisObject, ResultContainerType &Result)
Definition: cell.h:143
LocalIteratorType Begin() const
Definition: cell.h:293
TConfigure::ResultIteratorType ResultIteratorType
Definition: cell.h:61
void SearchObjectsInRadius(PointerType &rThisObject, double const &Radius, ResultIteratorType &Result, SizeType &NumberOfResults, const SizeType &MaxNumberOfResults)
Definition: cell.h:196
void Clear()
Definition: cell.h:100
bool remove(const std::string &rPath)
Definition: kratos_filesystem.cpp:57
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 Index()
Definition: hdf5_io_tools.py:38
Configure::ResultIteratorType ResultIteratorType
Definition: transfer_utility.h:252
Configure::IteratorType IteratorType
Definition: transfer_utility.h:249
Configure::PointType PointType
Definition: transfer_utility.h:245
Configure::ResultContainerType ResultContainerType
Definition: transfer_utility.h:250
Configure::ContainerType ContainerType
Definition: transfer_utility.h:247