4#include <boost/fusion/sequence/intrinsic/at_c.hpp>
5#include <boost/fusion/include/at_c.hpp>
6#include <boost/fusion/container/vector.hpp>
7#include <boost/fusion/include/vector.hpp>
8#include <boost/fusion/container/vector/vector_fwd.hpp>
9#include <boost/fusion/include/vector_fwd.hpp>
10#include "boost/multi_array.hpp"
11#include "memory_ly/Encap.hpp"
12#include "Point_operators.hpp"
27template<
unsigned int dim ,
typename T>
class Point
38 typedef boost::fusion::vector<T[dim]>
type;
47 static const unsigned int x = 0;
49 typedef typename native_encapsulated_type<T[dim]>::type type_native;
68 for(
size_t i = 0; i < dim ; i++)
79 for(
size_t i = 0; i < dim ; i++)
88 __device__ __host__
inline Point(
const T (&p)[dim])
90 for(
size_t i = 0; i < dim ; i++)
99 __device__ __host__
inline Point(T d)
111 for (
size_t i = 0 ; i < dim ; i++)
112 {
get(i) =
static_cast<S
>(p.
get(i));}
122 for (
size_t i = 0 ; i < dim ; i++)
123 get(i) = p.template get<0>()[i];
133 for (
unsigned int i = 0 ; i < dim ; i++)
144 for (
unsigned int i = 0 ; i < dim ; i++)
155 __device__ __host__
inline Point(std::initializer_list<T> p1)
172 __device__ __host__
inline const T &
get(
unsigned int i)
const
174 return boost::fusion::at_c<x>(
data)[i];
186 return boost::fusion::at_c<x>(
data)[i];
195 __device__ __host__
inline T&
get(
unsigned int i)
197 return boost::fusion::at_c<x>(
data)[i];
221 __device__ __host__
inline const T&
operator[](
unsigned int i)
const
231 __device__ __host__ T
norm()
const
235 for (
size_t i = 0 ; i < dim ; i++)
254 for (
size_t i = 0 ; i < dim ; i++)
255 tot += (this->
get(i) - q.
get(i)) * (this->
get(i) - q.
get(i));
273 for (
size_t i = 0 ; i < dim ; i++)
274 tot += (this->
get(i) - q.
get(i)) * (this->
get(i) - q.
get(i));
284 __device__ __host__
inline void zero()
286 for (
size_t i = 0 ; i < dim ; i++)
298 for (
size_t i = 0 ; i < dim ; i++)
313 for (
size_t i = 0 ; i < dim ; i++)
328 std::stringstream ps;
330 for (
size_t i = 0 ; i < dim ; i++)
331 ps <<
"x[" << i <<
"]=" <<
get(i) <<
" ";
345 for (
size_t i = 0 ; i < dim ; i++)
362 for (
size_t i = 0 ; i < dim ; i++)
402 for (
size_t i = 0 ; i < dim - 1 ; i++)
405 str += std::to_string(
static_cast<double>(
get(i))) +
" ";
407 str += std::to_string(
static_cast<double>(
get(dim-1)));
419 __device__ __host__ T &
value(
size_t i)
431 __device__ __host__
inline T
value(
size_t i)
const
443 return boost::fusion::at_c<x>(
data);
455 for (
size_t i = 0; i < dim ; i++)
456 p.
get(i) =
static_cast<A
>(
get(i));
483 for (
size_t i = 0; i < dim ; i++)
484 {
get(i) = p_exp.value(i);}
496 template<
typename any>
501 for (
size_t i = 0; i < dim ; i++)
516 for (
size_t i = 0; i < dim ; i++)
535 for (
size_t i = 0; i < dim ; i++)
536 get(i) = p_exp.value(i);
552 for (
size_t i = 0 ; i < dim ; i++)
553 result.
get(i) =
get(i) / ar[i];
567 for (
size_t i = 0 ; i < dim ; i++)
583 for (
size_t i = 0; i < dim ; i++)
598 for (
size_t i = 0 ; i < dim ; i++)
613 for (
size_t i = 0 ; i < dim ; i++)
628 for (
size_t i = 0 ; i < dim ; i++)
639 __device__ __host__
inline void init()
const
647 static const unsigned int max_prop_real = 1;
650 static const unsigned int dims = dim;
653 static const unsigned int nvals = dim;
663template <
unsigned int N,
typename T> std::string toPointString(
const T (&p)[N] )
665 std::stringstream ps;
667 for (
size_t i = 0 ; i < N ; i++)
668 ps <<
"x[" << i <<
"]=" << p[i] <<
" ";
682template <
unsigned int N,
typename T,
typename Mem> std::string toPointString(
const encapc<1,
Point<N,T>,Mem> & p )
684 std::stringstream ps;
686 for (
size_t i = 0 ; i < N ; i++)
687 ps <<
"x[" << i <<
"]=" << p.template get<
Point<N,T>::x>()[i] <<
" ";
704template<typename T, bool is_point = is_Point<T>::value>
707 typedef boost::mpl::int_<std::rank<T>::value> type;
713 typedef boost::mpl::int_<1> type;
This class implement the point shape in an N-dimensional space.
static bool noPointers()
This structure has no internal pointers.
void one()
Set to one the point coordinate.
int yes_is_point
Indicate that is a Point.
T coord_type
coordinate type
std::string toPointString() const
Convert the point into a string.
static const unsigned int x
Property id of the point.
__device__ __host__ Point(const point_expression_op< orig, exp1, exp2, op > &p_exp)
Evaluate the expression and save the result on the point.
int is_vtk_writable
Indicate that this object is vtk writable.
__device__ __host__ bool operator==(const Point< dim, T > &p) const
Check if two points match.
__device__ __host__ Point< dim, T > & operator=(const point_expression_op< orig, exp1, exp2, op > &p_exp)
Fill the vector with the evaluated expression.
__device__ __host__ void zero()
Set to zero the point coordinate.
__device__ __host__ T distance(const Point< dim, T > &q) const
It calculate the distance between 2 points.
__device__ __host__ Point< dim, T > operator/=(const aT c)
divide each component by a constant
static Point< dim, T > zero_p()
Create a point set to zero.
boost::fusion::vector< T[dim]> type
boost fusion that store the point
__device__ __host__ Point(const openfpm::detail::multi_array::sub_array_openfpm< T, 1, vmpl > &mar)
Point constructor from multi array.
T get_vtk(size_t i) const
Get coordinate.
__device__ __host__ const T & operator[](unsigned int i) const
Get the component i.
static const unsigned int nvals
expose the dimension with a different name
__device__ __host__ Point< dim, T > & operator=(T d)
Fill the vector property with some value.
__device__ __host__ Point(const Point< dim, S > &p)
Point constructor.
__device__ __host__ Point< dim, T > & operator=(const T(&p)[dim])
Fill the point with the value specified in the array.
__device__ __host__ Point(const T(&p)[dim])
Constructor from an array.
Point(const encapc< d, Point< dim, T >, M > &p)
Point constructor.
__device__ __host__ Point(std::initializer_list< T > p1)
Constructor from a list.
__device__ __host__ Point< dim, T > & operator=(const point_expression< const T1[dim]> &p_exp)
Fill the vector property with the evaluated expression.
__device__ __host__ T & value(size_t i)
Return the reference to the value at coordinate i.
__device__ __host__ Point(const openfpm::detail::multi_array::const_sub_array_openfpm< T, 1, vmpl > &mar)
Point constructor from multi array.
__device__ __host__ T & get(unsigned int i)
Get coordinate.
__device__ __host__ Point< dim, T > operator/(const aT(&ar)[dim])
divide each component by an array
__device__ __host__ bool operator!=(const Point< dim, T > &p) const
Check if two points match.
Point< dim, A > convertPoint() const
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
__device__ __host__ Point()
Default contructor.
__device__ __host__ Point< dim, T > & operator=(const Point< dim, T > &p)
operator= between points
T distance2(const Point< dim, T > &q) const
It calculate the square distance between 2 points.
std::string to_string() const
Return the string with the point coordinate.
__device__ __host__ Point(const Point< dim, T > &p)
Point constructor from point.
static const unsigned int dims
expose the dimension
__device__ __host__ T value(size_t i) const
Return the value at coordinate i.
std::string toString() const
Return the string with the point coordinate.
__device__ __host__ Point(T d)
Constructor from scalar.
__device__ __host__ Point< dim, T > & operator+=(const Point< dim, T > &p)
Sum two points.
__device__ __host__ Point< dim, T > & operator=(const point_expression< any > &p_exp)
Fill the vector property with the evaluated expression.
void swap(Point< dim, T > &p)
exchange the data of two points
T(& asArray())[dim]
Return the coordinated of the point as reference array.
__device__ __host__ Point(const Point< dim, T > &&p)
Point constructor from point.
__device__ __host__ T norm() const
norm of the vector
__device__ __host__ T & operator[](unsigned int i)
Get the component i.
static const unsigned int max_prop
The point has one property.
__device__ __host__ Point< dim, T > & operator-=(const Point< dim, T > &p)
Subtract two points.
type data
structure that store the data of the point
__device__ __host__ void init() const
Do nothing stub operation.
Unknown operation specialization.
Main class that encapsulate a constant number used in a point expression.
__device__ __host__ void init() const
This function must be called before value.
__device__ __host__ const T & value(const int k) const
Evaluate the expression.
like std::rank but it also work for openfpm structures like Point where it return 1