Debian Codegraph @

include/deal.II/base/point.h

raw
1 // ------------------------------------------------------------------------
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 // Copyright (C) 1998 - 2025 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // Part of the source code is dual licensed under Apache-2.0 WITH
9 // LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10 // governing the source code and code contributions can be found in
11 // LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12 //
13 // ------------------------------------------------------------------------
14
15 #ifndef dealii_point_h
16 #define dealii_point_h
17
18
19 #include <deal.II/base/config.h>
20
21 #include <deal.II/base/exceptions.h>
22 #include <deal.II/base/numbers.h>
23 #include <deal.II/base/template_constraints.h>
24 #include <deal.II/base/tensor.h>
25
26 #include <boost/geometry/core/cs.hpp>
27 #include <boost/geometry/geometries/point.hpp>
28
29 #include <cmath>
30
31 DEAL_II_NAMESPACE_OPEN
32
33 /**
34 * A class that represents a point in a Cartesian space of dimension
35 * @p dim .
36 *
37 * Objects of this class are used to represent points (i.e., vectors
38 * anchored at the origin) of a vector space equipped with a <a
39 * href="https://en.wikipedia.org/wiki/Cartesian_coordinate_system">Cartesian
40 * coordinate system</a>. They are, among other uses, passed to
41 * functions that operate on points in spaces of a priori fixed
42 * dimension: rather than using functions like <code>double f(const
43 * double x)</code> and <code>double f(const double x, const double
44 * y)</code>, you can use <code>double f(const Point<dim> &p)</code>
45 * instead as it allows writing dimension independent code.
46 *
47 * deal.II specifically uses Point objects as indicating points that
48 * are represented by Cartesian coordinates, i.e., where a point in @p
49 * dim space dimensions is characterized by signed distances along the
50 * axes of a coordinate system spanned by @p dim mutually orthogonal
51 * unit vectors (called the "coordinate axes"). This choice of
52 * representing a vector makes addition and scaling of vectors
53 * particularly simple: one only has to add or multiply each
54 * coordinate value. On the other hand, adding or scaling vectors is
55 * not nearly as simple when a vector is represented in other kinds of
56 * coordinate systems (e.g., <a
57 * href="https://en.wikipedia.org/wiki/Spherical_coordinate_system">spherical
58 * coordinate systems</a>).
59 *
60 *
61 * <h3>What's a <code>Point@<dim@></code> and what is a
62 * <code>Tensor@<1,dim@></code>?</h3>
63 *
64 * The Point class is derived from Tensor@<1,dim@> and consequently shares the
65 * latter's member functions and other attributes. In fact, it has relatively
66 * few additional functions itself (the most notable exception being the
67 * distance() function to compute the Euclidean distance between two points in
68 * space), and these two classes can therefore often be used interchangeably.
69 *
70 * Nonetheless, there are semantic differences that make us use these classes
71 * in different and well-defined contexts. Within deal.II, we use the
72 * <tt>Point</tt> class to denote points in space, i.e., for vectors (rank-1
73 * tensors) that are <em>anchored at the origin</em>. On the other hand,
74 * vectors that are anchored elsewhere (and consequently do not represent
75 * <em>points</em> in the common usage of the word) are represented by objects
76 * of type Tensor@<1,dim@>. In particular, this is the case for direction
77 * vectors, normal vectors, gradients, and the differences between two points
78 * (i.e., what you get when you subtract one point from another): all of these
79 * are represented by Tensor@<1,dim@> objects rather than Point@<dim@>.
80 *
81 * Furthermore, the Point class is only used where the coordinates of an
82 * object can be thought to possess the dimension of a length. An object that
83 * represents the weight, height, and cost of an object is neither a point nor
84 * a tensor (because it lacks the transformation properties under rotation of
85 * the coordinate system) and should consequently not be represented by either
86 * of these classes. Use an array of size 3 in this case, or the
87 * <code>std::array</code> class. Alternatively, as in the case of
88 * vector-valued functions, you can use objects of type Vector or
89 * <code>std::vector</code>.
90 *
91 *
92 * @tparam dim An integer that denotes the dimension of the space in which a
93 * point lies. This of course equals the number of coordinates that identify a
94 * point.
95 * @tparam Number The data type in which the coordinates values are to be
96 * stored. This will, in almost all cases, simply be the default @p double,
97 * but there are cases where one may want to store coordinates in a different
98 * (and always scalar) type. An example would be an interval type that can
99 * store the value of a coordinate as well as its uncertainty. Another example
100 * would be a type that allows for Automatic Differentiation (see, for
101 * example, the Sacado type used in step-33) and thereby can generate analytic
102 * (spatial) derivatives of a function when passed a Point object whose
103 * coordinates are stored in such a type.
104 *
105 *
106 * @ingroup geomprimitives
107 *
108 * @dealiiConceptRequires{dim >= 0}
109 */
110 template <int dim, typename Number = double>
111 DEAL_II_CXX20_REQUIRES(dim >= 0)
112 class Point : public Tensor<1, dim, Number>
113 {
114 public:
115 /**
116 * Standard constructor. Creates an object that corresponds to the origin,
117 * i.e., all coordinates are set to zero.
118 *
119 * @note This function can also be used in @ref GlossDevice "device" code.
120 */
121 constexpr DEAL_II_HOST_DEVICE
122 Point();
123
124 /**
125 * Convert a tensor to a point.
126 */
127 constexpr explicit DEAL_II_HOST_DEVICE
128 Point(const Tensor<1, dim, Number> &);
129
130 /**
131 * Constructor for one dimensional points. This function is only implemented
132 * for <tt>dim==1</tt> since the usage is considered unsafe for points with
133 * <tt>dim!=1</tt> as it would leave some components of the point
134 * coordinates uninitialized.
135 *
136 * @note This function can also be used in @ref GlossDevice "device" code.
137 */
138 constexpr explicit DEAL_II_HOST_DEVICE
139 Point(const Number x);
140
141 /**
142 * Constructor for two dimensional points. This function is only implemented
143 * for <tt>dim==2</tt> since the usage is considered unsafe for points with
144 * <tt>dim!=2</tt> as it would leave some components of the point
145 * coordinates uninitialized (if dim>2) or would not use some arguments (if
146 * dim<2).
147 *
148 * @note This function can also be used in @ref GlossDevice "device" code.
149 */
150 constexpr DEAL_II_HOST_DEVICE
151 Point(const Number x, const Number y);
152
153 /**
154 * Constructor for three dimensional points. This function is only
155 * implemented for <tt>dim==3</tt> since the usage is considered unsafe for
156 * points with <tt>dim!=3</tt> as it would leave some components of the
157 * point coordinates uninitialized (if dim>3) or would not use some
158 * arguments (if dim<3).
159 *
160 * @note This function can also be used in @ref GlossDevice "device" code.
161 */
162 constexpr DEAL_II_HOST_DEVICE
163 Point(const Number x, const Number y, const Number z);
164
165 /**
166 * Convert a boost::geometry::point to a dealii::Point.
167 */
168 template <std::size_t dummy_dim,
169 std::enable_if_t<(dim == dummy_dim) && (dummy_dim != 0), int> = 0>
170 constexpr Point(
171 const boost::geometry::model::
172 point<Number, dummy_dim, boost::geometry::cs::cartesian> &boost_pt);
173
174 /**
175 * Return a unit vector in coordinate direction <tt>i</tt>, i.e., a vector
176 * that is zero in all coordinates except for a single 1 in the <tt>i</tt>th
177 * coordinate.
178 *
179 * @note This function can also be used in @ref GlossDevice "device" code.
180 */
181 static constexpr DEAL_II_HOST_DEVICE Point<dim, Number>
182 unit_vector(const unsigned int i);
183
184 /**
185 * Read access to the <tt>index</tt>th coordinate.
186 *
187 * @note This function can also be used in @ref GlossDevice "device" code.
188 */
189 constexpr DEAL_II_HOST_DEVICE Number
190 operator()(const unsigned int index) const;
191
192 /**
193 * Read and write access to the <tt>index</tt>th coordinate.
194 *
195 * @note This function can also be used in @ref GlossDevice "device" code.
196 */
197 constexpr DEAL_II_HOST_DEVICE Number &
198 operator()(const unsigned int index);
199
200 /**
201 * Assignment operator from Tensor<1, dim, Number> with different underlying
202 * scalar type. This obviously requires that the @p OtherNumber type is
203 * convertible to @p Number.
204 */
205 template <typename OtherNumber>
206 constexpr Point<dim, Number> &
207 operator=(const Tensor<1, dim, OtherNumber> &p);
208
209 /**
210 * @name Addition and subtraction of points.
211 * @{
212 */
213
214 /**
215 * Add an offset given as Tensor<1,dim,Number> to a point.
216 *
217 * @note This function can also be used in @ref GlossDevice "device" code.
218 */
219 constexpr DEAL_II_HOST_DEVICE Point<dim, Number>
220 operator+(const Tensor<1, dim, Number> &) const;
221
222 /**
223 * Subtract two points, i.e., obtain the vector that connects the two. As
224 * discussed in the documentation of this class, subtracting two points
225 * results in a vector anchored at one of the two points (rather than at the
226 * origin) and, consequently, the result is returned as a Tensor@<1,dim@>
227 * rather than as a Point@<dim@>.
228 *
229 * @note This function can also be used in @ref GlossDevice "device" code.
230 */
231 constexpr DEAL_II_HOST_DEVICE Tensor<1, dim, Number>
232 operator-(const Point<dim, Number> &) const;
233
234 /**
235 * Subtract a difference vector (represented by a Tensor@<1,dim@>) from the
236 * current point. This results in another point and, as discussed in the
237 * documentation of this class, the result is then naturally returned as a
238 * Point@<dim@> object rather than as a Tensor@<1,dim@>.
239 *
240 * @note This function can also be used in @ref GlossDevice "device" code.
241 */
242 constexpr DEAL_II_HOST_DEVICE Point<dim, Number>
243 operator-(const Tensor<1, dim, Number> &) const;
244
245 /**
246 * The opposite vector.
247 *
248 * @note This function can also be used in @ref GlossDevice "device" code.
249 */
250 constexpr DEAL_II_HOST_DEVICE Point<dim, Number>
251 operator-() const;
252
253 /**
254 * @}
255 */
256
257 /**
258 * @name Multiplication and scaling of points. Dot products. Norms.
259 * @{
260 */
261
262 /**
263 * Multiply the current point by a factor.
264 *
265 * @note This function can also be used in @ref GlossDevice "device" code.
266 *
267 * @relatesalso EnableIfScalar
268 */
269 template <typename OtherNumber>
270 constexpr DEAL_II_HOST_DEVICE Point<
271 dim,
272 typename ProductType<Number,
273 typename EnableIfScalar<OtherNumber>::type>::type>
274 operator*(const OtherNumber) const;
275
276 /**
277 * Divide the current point by a factor.
278 *
279 * @note This function can also be used in @ref GlossDevice "device" code.
280 */
281 template <typename OtherNumber>
282 constexpr DEAL_II_HOST_DEVICE Point<
283 dim,
284 typename ProductType<Number,
285 typename EnableIfScalar<OtherNumber>::type>::type>
286 operator/(const OtherNumber) const;
287
288 /**
289 * Return the scalar product of the vectors representing two points.
290 *
291 * @note This function can also be used in @ref GlossDevice "device" code.
292 */
293 constexpr DEAL_II_HOST_DEVICE Number
294 operator*(const Tensor<1, dim, Number> &p) const;
295
296 /**
297 * Return the scalar product of this point vector with itself, i.e. the
298 * square, or the square of the norm. In case of a complex number type it is
299 * equivalent to the contraction of this point vector with a complex
300 * conjugate of itself.
301 *
302 * @note This function is equivalent to
303 * Tensor<rank,dim,Number>::norm_square() which returns the square of the
304 * Frobenius norm.
305 *
306 * @note This function can also be used in @ref GlossDevice "device" code.
307 */
308 constexpr DEAL_II_HOST_DEVICE
309 typename numbers::NumberTraits<Number>::real_type
310 square() const;
311
312 /**
313 * Return the Euclidean distance of <tt>this</tt> point to the point
314 * <tt>p</tt>, i.e. the $l_2$ norm of the difference between the
315 * vectors representing the two points.
316 *
317 * @note This function can also be used in @ref GlossDevice "device" code.
318 */
319 DEAL_II_HOST_DEVICE typename numbers::NumberTraits<Number>::real_type
320 distance(const Point<dim, Number> &p) const;
321
322 /**
323 * Return the squared Euclidean distance of <tt>this</tt> point to the point
324 * <tt>p</tt>.
325 *
326 * @note This function can also be used in @ref GlossDevice "device" code.
327 */
328 constexpr DEAL_II_HOST_DEVICE
329 typename numbers::NumberTraits<Number>::real_type
330 distance_square(const Point<dim, Number> &p) const;
331
332 /**
333 * @}
334 */
335
336 /**
337 * Read or write the data of this object to or from a stream for the purpose
338 * of serialization using the [BOOST serialization
339 * library](https://www.boost.org/doc/libs/1_74_0/libs/serialization/doc/index.html).
340 */
341 template <class Archive>
342 void
343 serialize(Archive &ar, const unsigned int version);
344 };
345
346 /*--------------------------- Inline functions: Point -----------------------*/
347
348 #ifndef DOXYGEN
349
350 // At least clang-3.7 requires us to have a user-defined constructor
351 // and we can't use 'Point<dim,Number>::Point () = default' here.
352 template <int dim, typename Number>
353 DEAL_II_CXX20_REQUIRES(dim >= 0)
354 constexpr DEAL_II_HOST_DEVICE Point<dim, Number>::Point() // NOLINT
355 {}
356
357
358
359 template <int dim, typename Number>
360 DEAL_II_CXX20_REQUIRES(dim >= 0)
361 constexpr DEAL_II_HOST_DEVICE Point<dim, Number>::Point(
362 const Tensor<1, dim, Number> &t)
363 : Tensor<1, dim, Number>(t)
364 {}
365
366
367
368 template <int dim, typename Number>
369 DEAL_II_CXX20_REQUIRES(dim >= 0)
370 constexpr DEAL_II_HOST_DEVICE Point<dim, Number>::Point(const Number x)
371 {
372 Assert(dim == 1,
373 ExcMessage(
374 "You can only initialize Point<1> objects using the constructor "
375 "that takes only one argument. Point<dim> objects with dim!=1 "
376 "require initialization with the constructor that takes 'dim' "
377 "arguments."));
378
379 // we can only get here if we pass the assertion. use the switch anyway so
380 // as to avoid compiler warnings about uninitialized elements or writing
381 // beyond the end of the 'values' array
382 switch (dim)
383 {
384 case 1:
385 this->values[0] = x;
386 break;
387
388 default:;
389 }
390 }
391
392
393
394 template <int dim, typename Number>
395 DEAL_II_CXX20_REQUIRES(dim >= 0)
396 constexpr DEAL_II_HOST_DEVICE Point<dim, Number>::Point(const Number x,
397 const Number y)
398 {
399 Assert(dim == 2,
400 ExcMessage(
401 "You can only initialize Point<2> objects using the constructor "
402 "that takes two arguments. Point<dim> objects with dim!=2 "
403 "require initialization with the constructor that takes 'dim' "
404 "arguments."));
405
406 // we can only get here if we pass the assertion. use the indirection anyway
407 // so as to avoid compiler warnings about uninitialized elements or writing
408 // beyond the end of the 'values' array
409 constexpr unsigned int y_index = (dim < 2) ? 0 : 1;
410 this->values[0] = x;
411 this->values[y_index] = y;
412 }
413
414
415
416 template <int dim, typename Number>
417 DEAL_II_CXX20_REQUIRES(dim >= 0)
418 constexpr DEAL_II_HOST_DEVICE Point<dim, Number>::Point(const Number x,
419 const Number y,
420 const Number z)
421 {
422 Assert(dim == 3,
423 ExcMessage(
424 "You can only initialize Point<3> objects using the constructor "
425 "that takes three arguments. Point<dim> objects with dim!=3 "
426 "require initialization with the constructor that takes 'dim' "
427 "arguments."));
428
429 // we can only get here if we pass the assertion. use the indirection anyway
430 // so as to avoid compiler warnings about uninitialized elements or writing
431 // beyond the end of the 'values' array
432 constexpr unsigned int y_index = (dim < 2) ? 0 : 1;
433 constexpr unsigned int z_index = (dim < 3) ? 0 : 2;
434 this->values[0] = x;
435 this->values[y_index] = y;
436 this->values[z_index] = z;
437 }
438
439
440
441 template <int dim, typename Number>
442 DEAL_II_CXX20_REQUIRES(dim >= 0)
443 template <std::size_t dummy_dim,
444 std::enable_if_t<(dim == dummy_dim) && (dummy_dim != 0), int>>
445 constexpr Point<dim, Number>::Point(
446 const boost::geometry::model::
447 point<Number, dummy_dim, boost::geometry::cs::cartesian> &boost_pt)
448 {
449 Assert(dim <= 3, ExcNotImplemented());
450 this->values[0] = boost::geometry::get<0>(boost_pt);
451 constexpr unsigned int y_index = (dim < 2) ? 0 : 1;
452 constexpr unsigned int z_index = (dim < 3) ? 0 : 2;
453
454 if (dim >= 2)
455 this->values[y_index] = boost::geometry::get<y_index>(boost_pt);
456
457 if (dim >= 3)
458 this->values[z_index] = boost::geometry::get<z_index>(boost_pt);
459 }
460
461
462
463 template <int dim, typename Number>
464 DEAL_II_CXX20_REQUIRES(dim >= 0)
465 constexpr DEAL_II_HOST_DEVICE
466 Point<dim, Number> Point<dim, Number>::unit_vector(unsigned int i)
467 {
468 Point<dim, Number> p;
469 p[i] = 1.;
470 return p;
471 }
472
473
474 template <int dim, typename Number>
475 DEAL_II_CXX20_REQUIRES(dim >= 0)
476 constexpr DEAL_II_HOST_DEVICE Number Point<dim, Number>::operator()(
477 const unsigned int index) const
478 {
479 AssertIndexRange(static_cast<int>(index), dim);
480 return this->values[index];
481 }
482
483
484
485 template <int dim, typename Number>
486 DEAL_II_CXX20_REQUIRES(dim >= 0)
487 constexpr DEAL_II_HOST_DEVICE Number &Point<dim, Number>::operator()(
488 const unsigned int index)
489 {
490 AssertIndexRange(static_cast<int>(index), dim);
491 return this->values[index];
492 }
493
494
495
496 template <int dim, typename Number>
497 DEAL_II_CXX20_REQUIRES(dim >= 0)
498 template <typename OtherNumber>
499 constexpr DEAL_II_ALWAYS_INLINE Point<dim, Number>
500 &Point<dim, Number>::operator=(const Tensor<1, dim, OtherNumber> &p)
501 {
502 Tensor<1, dim, Number>::operator=(p);
503 return *this;
504 }
505
506
507
508 template <int dim, typename Number>
509 DEAL_II_CXX20_REQUIRES(dim >= 0)
510 constexpr DEAL_II_HOST_DEVICE Point<dim, Number> Point<dim, Number>::operator+(
511 const Tensor<1, dim, Number> &p) const
512 {
513 Point<dim, Number> tmp = *this;
514 tmp += p;
515 return tmp;
516 }
517
518
519
520 template <int dim, typename Number>
521 DEAL_II_CXX20_REQUIRES(dim >= 0)
522 constexpr DEAL_II_HOST_DEVICE
523 Tensor<1, dim, Number> Point<dim, Number>::operator-(
524 const Point<dim, Number> &p) const
525 {
526 return (Tensor<1, dim, Number>(*this) -= p);
527 }
528
529
530
531 template <int dim, typename Number>
532 DEAL_II_CXX20_REQUIRES(dim >= 0)
533 constexpr DEAL_II_HOST_DEVICE Point<dim, Number> Point<dim, Number>::operator-(
534 const Tensor<1, dim, Number> &p) const
535 {
536 Point<dim, Number> tmp = *this;
537 tmp -= p;
538 return tmp;
539 }
540
541
542
543 template <int dim, typename Number>
544 DEAL_II_CXX20_REQUIRES(dim >= 0)
545 constexpr DEAL_II_HOST_DEVICE Point<dim, Number> Point<dim, Number>::operator-()
546 const
547 {
548 Point<dim, Number> result;
549 for (unsigned int i = 0; i < dim; ++i)
550 result.values[i] = -this->values[i];
551 return result;
552 }
553
554
555
556 template <int dim, typename Number>
557 DEAL_II_CXX20_REQUIRES(dim >= 0)
558 template <typename OtherNumber>
559 constexpr DEAL_II_HOST_DEVICE Point<
560 dim,
561 typename ProductType<Number, typename EnableIfScalar<OtherNumber>::type>::
562 type> Point<dim, Number>::operator*(const OtherNumber factor) const
563 {
564 Point<dim, typename ProductType<Number, OtherNumber>::type> tmp;
565 for (unsigned int i = 0; i < dim; ++i)
566 tmp[i] = this->operator[](i) * factor;
567 return tmp;
568 }
569
570
571
572 template <int dim, typename Number>
573 DEAL_II_CXX20_REQUIRES(dim >= 0)
574 template <typename OtherNumber>
575 constexpr DEAL_II_HOST_DEVICE Point<
576 dim,
577 typename ProductType<Number, typename EnableIfScalar<OtherNumber>::type>::
578 type> Point<dim, Number>::operator/(const OtherNumber factor) const
579 {
580 const Tensor<1, dim, Number> &base_object = *this;
581 return Point<
582 dim,
583 typename ProductType<Number,
584 typename EnableIfScalar<OtherNumber>::type>::type>(
585 dealii::operator/(base_object, factor));
586 }
587
588
589
590 template <int dim, typename Number>
591 DEAL_II_CXX20_REQUIRES(dim >= 0)
592 constexpr DEAL_II_HOST_DEVICE Number Point<dim, Number>::operator*(
593 const Tensor<1, dim, Number> &p) const
594 {
595 Number res = Number();
596 for (unsigned int i = 0; i < dim; ++i)
597 res += this->operator[](i) * p[i];
598 return res;
599 }
600
601
602 template <int dim, typename Number>
603 DEAL_II_CXX20_REQUIRES(dim >= 0)
604 constexpr DEAL_II_HOST_DEVICE typename numbers::NumberTraits<Number>::real_type
605 Point<dim, Number>::square() const
606 {
607 return this->norm_square();
608 }
609
610
611
612 template <int dim, typename Number>
613 DEAL_II_CXX20_REQUIRES(dim >= 0)
614 inline DEAL_II_HOST_DEVICE typename numbers::NumberTraits<Number>::real_type
615 Point<dim, Number>::distance(const Point<dim, Number> &p) const
616 {
617 return std::sqrt(distance_square(p));
618 }
619
620
621
622 template <int dim, typename Number>
623 DEAL_II_CXX20_REQUIRES(dim >= 0)
624 constexpr DEAL_II_HOST_DEVICE typename numbers::NumberTraits<Number>::real_type
625 Point<dim, Number>::distance_square(const Point<dim, Number> &p) const
626 {
627 Number sum = internal::NumberType<Number>::value(0.0);
628 for (unsigned int i = 0; i < dim; ++i)
629 {
630 const Number diff = static_cast<Number>(this->values[i]) - p[i];
631 sum += numbers::NumberTraits<Number>::abs_square(diff);
632 }
633
634 return sum;
635 }
636
637
638
639 template <int dim, typename Number>
640 DEAL_II_CXX20_REQUIRES(dim >= 0)
641 template <class Archive>
642 inline void Point<dim, Number>::serialize(Archive &ar, const unsigned int)
643 {
644 // forward to serialization
645 // function in the base class
646 ar &static_cast<Tensor<1, dim, Number> &>(*this);
647 }
648
649 #endif // DOXYGEN
650
651
652 /*--------------------------- Global functions: Point -----------------------*/
653
654
655 /**
656 * Global operator scaling a point vector by a scalar.
657 *
658 * @note This function can also be used in @ref GlossDevice "device" code.
659 *
660 * @relates Point
661 */
662 template <int dim, typename Number, typename OtherNumber>
663 constexpr DEAL_II_HOST_DEVICE
664 Point<dim,
665 typename ProductType<Number,
666 typename EnableIfScalar<OtherNumber>::type>::type>
667 operator*(const OtherNumber factor, const Point<dim, Number> &p)
668 {
669 return p * factor;
670 }
671
672
673
674 /**
675 * Output operator for points. Print the elements consecutively, with a space
676 * in between.
677 * @relatesalso Point
678 *
679 * @dealiiConceptRequires{dim >= 0}
680 */
681 template <int dim, typename Number>
682 DEAL_II_CXX20_REQUIRES(dim >= 0)
683 inline std::ostream &
684 operator<<(std::ostream &out, const Point<dim, Number> &p)
685 {
686 for (unsigned int i = 0; i < dim - 1; ++i)
687 out << p[i] << ' ';
688 out << p[dim - 1];
689
690 return out;
691 }
692
693
694
695 /**
696 * Input operator for points. Inputs the elements consecutively.
697 * @relatesalso Point
698 *
699 * @dealiiConceptRequires{dim >= 0}
700 */
701 template <int dim, typename Number>
702 DEAL_II_CXX20_REQUIRES(dim >= 0)
703 inline std::istream &
704 operator>>(std::istream &in, Point<dim, Number> &p)
705 {
706 for (unsigned int i = 0; i < dim; ++i)
707 in >> p[i];
708
709 return in;
710 }
711
712
713 #ifndef DOXYGEN
714
715 /**
716 * Output operator for points of dimension 1. This is implemented specialized
717 * from the general template in order to avoid a compiler warning that the
718 * loop is empty.
719 */
720 template <typename Number>
721 inline std::ostream &
722 operator<<(std::ostream &out, const Point<1, Number> &p)
723 {
724 out << p[0];
725
726 return out;
727 }
728
729 #endif // DOXYGEN
730 DEAL_II_NAMESPACE_CLOSE
731
732 #endif