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.
point.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: Riccardo Rossi
11 // Janosch Stascheit
12 // Felix Nagel
13 // contributors: Hoang Giang Bui
14 // Josep Maria Carbonell
15 //
16 
17 #pragma once
18 
19 // System includes
20 
21 // External includes
22 
23 // Project includes
24 #include "includes/define.h"
25 #include "containers/array_1d.h"
26 #include "includes/serializer.h"
27 
28 namespace Kratos
29 {
30 
33 
37 
41 
45 
49 
51 
58 class Point : public array_1d<double, 3>
59 {
60  static constexpr std::size_t mDimension = 3;
61 
62 public:
65 
69 
72 
74 
76 
77  typedef std::size_t SizeType;
78 
79  typedef std::size_t IndexType;
80 
84 
87  {
88  SetAllCoordinates();
89  }
90 
92  Point(double NewX, double NewY = 0, double NewZ = 0) : BaseType()
93  {
94  this->operator()(0) = NewX;
95  this->operator()(1) = NewY;
96  this->operator()(2) = NewZ;
97  }
98 
101  Point(Point const &rOtherPoint)
102  : BaseType(rOtherPoint) {}
103 
106  explicit Point(CoordinatesArrayType const &rOtherCoordinates)
107  : BaseType(rOtherCoordinates) {}
108 
111  template <class TVectorType>
112  explicit Point(vector_expression<TVectorType> const &rOtherCoordinates)
113  : BaseType(rOtherCoordinates) {}
114 
117  explicit Point(std::vector<double> const &rOtherCoordinates) : BaseType()
118  {
119  SizeType size = rOtherCoordinates.size();
120  size = (mDimension < size) ? mDimension : size;
121  for (IndexType i = 0; i < size; i++)
122  this->operator[](i) = rOtherCoordinates[i];
123  }
124 
126  virtual ~Point() {}
127 
131 
133  Point &operator=(const Point &rOther)
134  {
136  return *this;
137  }
138 
139  bool operator==(const Point &rOther) const
140  {
141  return std::equal(this->begin(), this->end(), rOther.begin());
142  }
143 
147 
154  double SquaredDistance(const Point& rOtherPoint) const
155  {
156  const array_1d<double, 3> diff_vector = this->Coordinates() - rOtherPoint.Coordinates();
157  return (std::pow(diff_vector[0], 2) + std::pow(diff_vector[1], 2) + std::pow(diff_vector[2], 2));
158  }
159 
166  double Distance(const Point& rOtherPoint) const
167  {
168  return norm_2(this->Coordinates() - rOtherPoint.Coordinates());
169  }
170 
174 
175  static constexpr IndexType Dimension()
176  {
177  return mDimension;
178  }
179 
181  double X() const
182  {
183  return this->operator[](0);
184  }
185 
187  double Y() const
188  {
189  return this->operator[](1);
190  }
191 
193  double Z() const
194  {
195  return this->operator[](2);
196  }
197 
198  double &X()
199  {
200  return this->operator[](0);
201  }
202 
204  double &Y()
205  {
206  return this->operator[](1);
207  }
208 
210  double &Z()
211  {
212  return this->operator[](2);
213  }
214 
215  CoordinatesArrayType const &Coordinates() const
216  {
217  return *this;
218  }
219 
221  {
222  return *this;
223  }
224 
228 
230  virtual std::string Info() const
231  {
232  return "Point";
233  }
234 
236  virtual void PrintInfo(std::ostream &rOStream) const
237  {
238  rOStream << this->Info();
239  }
240 
242  virtual void PrintData(std::ostream &rOStream) const
243  {
244  rOStream << " (" << this->operator[](0)
245  << ", " << this->operator[](1)
246  << ", " << this->operator[](2)
247  << ")";
248  }
249 
251 
252  private:
255 
256  void SetAllCoordinates(double const &Value = double())
257  {
258  for (IndexType i = 0; i < mDimension; i++)
259  this->operator()(i) = Value;
260  }
261 
265 
266  friend class Serializer;
267 
268  virtual void save(Serializer &rSerializer) const
269  {
270  rSerializer.save_base("BaseClass", *static_cast<const array_1d<double, mDimension> *>(this));
271  }
272 
273  virtual void load(Serializer &rSerializer)
274  {
275  rSerializer.load_base("BaseClass", *static_cast<array_1d<double, mDimension> *>(this));
276  }
277 
279 
280 }; // Class Point
281 
283 
286 
290 
292 inline std::istream &operator>>(std::istream &rIStream,
293  Point &rThis){
294  return rIStream;
295  }
296 
298 inline std::ostream &operator<<(std::ostream &rOStream,
299  const Point &rThis)
300 {
301  rThis.PrintInfo(rOStream);
302  rThis.PrintData(rOStream);
303 
304  return rOStream;
305 }
307 
308 } // namespace Kratos.
Point class.
Definition: point.h:59
double & Z()
Definition: point.h:210
CoordinatesArrayType const & Coordinates() const
Definition: point.h:215
Point(double NewX, double NewY=0, double NewZ=0)
3d constructor.
Definition: point.h:92
std::size_t IndexType
Definition: point.h:79
static constexpr IndexType Dimension()
Definition: point.h:175
KRATOS_CLASS_POINTER_DEFINITION(Point)
Pointer definition of Point.
double Distance(const Point &rOtherPoint) const
This method computes the distance between this point and another one.
Definition: point.h:166
array_1d< double, mDimension > BaseType
Definition: point.h:73
double & Y()
Definition: point.h:204
BaseType CoordinatesArrayType
Definition: point.h:75
virtual std::string Info() const
Turn back information as a string.
Definition: point.h:230
bool operator==(const Point &rOther) const
Definition: point.h:139
Point & operator=(const Point &rOther)
Assignment operator.
Definition: point.h:133
double & X()
Definition: point.h:198
Point()
Default constructor.
Definition: point.h:86
virtual ~Point()
Destructor.
Definition: point.h:126
Point(std::vector< double > const &rOtherCoordinates)
Definition: point.h:117
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: point.h:242
double Y() const
Definition: point.h:187
std::size_t SizeType
Definition: point.h:77
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: point.h:236
Point(Point const &rOtherPoint)
Definition: point.h:101
double SquaredDistance(const Point &rOtherPoint) const
This method computes the distance between this point and another one (squared)
Definition: point.h:154
Point(vector_expression< TVectorType > const &rOtherCoordinates)
Definition: point.h:112
CoordinatesArrayType & Coordinates()
Definition: point.h:220
Point(CoordinatesArrayType const &rOtherCoordinates)
Definition: point.h:106
double Z() const
Definition: point.h:193
double X() const
Definition: point.h:181
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
void load_base(std::string const &rTag, TDataType &rObject)
Definition: serializer.h:791
void save_base(std::string const &rTag, std::vector< TDataType > const &rObject)
Definition: serializer.h:820
Short class definition.
Definition: array_1d.h:61
BOOST_UBLAS_INLINE array_1d & operator=(const array_1d &v)
Definition: array_1d.h:187
BOOST_UBLAS_INLINE const_reference operator()(size_type i) const
Definition: array_1d.h:160
BOOST_UBLAS_INLINE const_reference operator[](size_type i) const
Definition: array_1d.h:173
BOOST_UBLAS_INLINE size_type size() const
Definition: array_1d.h:370
BOOST_UBLAS_INLINE const_iterator end() const
Definition: array_1d.h:611
BOOST_UBLAS_INLINE const_iterator begin() const
Definition: array_1d.h:606
std::size_t IndexType
The definition of the index type.
Definition: key_hash.h:35
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
TExpressionType::data_type norm_2(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression)
Definition: amatrix_interface.h:625
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
AMatrix::MatrixExpression< TExpressionType, AMatrix::row_major_access > vector_expression
Definition: amatrix_interface.h:490
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
integer i
Definition: TensorModule.f:17