Commit 1506debf authored by Pietro Incardona's avatar Pietro Incardona

Adding operator for vector

parent caf1e50d
# Change Log
All notable changes to this project will be documented in this file.
## [0.5.0] -
## [0.5.0] - mid July 2016
### Added
- map_list map communicate particles across processors mooving the information of all the particle map_list give the possibility to
give a list of property to move from one to another processor
- map_list map communicate particles across processors mooving the information of all the particle map_list give the possibility to give a list of property to move from one to another processor
- Numeric: Finite Differences discretization with matrix contruction and parallel solvers
### Fixed
......@@ -82,3 +81,18 @@ All notable changes to this project will be documented in this file.
### Changed
- Nothing to report
# Planned in the next Releases
## [0.7.0] - Mid of October
### Added
- Dynamic Load Balancies examples and interface fixation
- Check Point restart
## [0.6.0] - Beginning of september
### Added
- Parallel IO, new formats, imroved writers
......@@ -27,6 +27,7 @@
#include "Vector/vector_dist_ofb.hpp"
#include "Decomposition/CartDecomposition.hpp"
#include "data_type/aggregate.hpp"
#include "vector_dist_operators.hpp"
#define V_SUB_UNIT_FACTOR 64
......@@ -883,6 +884,21 @@ public:
return v_prp.template get<id>(vec_key.getKey());
}
/*! \brief Get the property of an element
*
* see the vector_dist iterator usage to get an element key
*
* \tparam id property id
* \param vec_key vector element
*
* \return return the selected property of the vector element
*
*/
template<unsigned int id> inline const auto getProp(vect_dist_key_dx vec_key) const -> decltype(v_prp.template get<id>(vec_key.getKey()))
{
return v_prp.template get<id>(vec_key.getKey());
}
/*! \brief It move all the particles that does not belong to the local processor to the respective processor
*
* \tparam out of bound policy it specify what to do when the particles are detected out of bound
......@@ -1438,7 +1454,7 @@ public:
* \return an iterator
*
*/
vector_dist_iterator getGhostIterator()
vector_dist_iterator getGhostIterator() const
{
return vector_dist_iterator(g_m, v_pos.size());
}
......@@ -1448,7 +1464,7 @@ public:
* \return an iterator
*
*/
vector_dist_iterator getDomainIterator()
vector_dist_iterator getDomainIterator() const
{
return vector_dist_iterator(0, g_m);
}
......@@ -1611,6 +1627,16 @@ public:
#endif
return v_cl;
}
//////////////////////////// Vector expression implementation ////////////////////////
template <unsigned int prp> inline vector_dist_expression<prp,vector_dist<dim,St,prop,Decomposition,Memory> > getV()
{
vector_dist_expression<prp,vector_dist<dim,St,prop,Decomposition,Memory> > exp_v(*this);
return exp_v;
}
};
#endif /* VECTOR_HPP_ */
/*
* vector_dist_operators.hpp
*
* Created on: Jun 11, 2016
* Author: i-bird
*/
#ifndef SRC_VECTOR_VECTOR_DIST_OPERATORS_HPP_
#define SRC_VECTOR_VECTOR_DIST_OPERATORS_HPP_
#define SUM 1
#define SUB 2
#define MUL 3
#define DIV 4
template <typename exp1, typename exp2, unsigned int op>
class vector_dist_expression_op
{
};
template <typename exp1, typename exp2>
class vector_dist_expression_op<exp1,exp2,SUM>
{
const exp1 o1;
const exp2 o2;
public:
typedef decltype(o1.value(vect_dist_key_dx(0))) r_type;
vector_dist_expression_op(const exp1 & o1, const exp2 & o2)
:o1(o1),o2(o2)
{}
template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx(0)))>::type > inline r_type value(const vect_dist_key_dx & key) const
{
return o1.value(key) + o2.value(key);
}
};
template <typename exp1, typename exp2>
class vector_dist_expression_op<exp1,exp2,SUB>
{
const exp1 o1;
const exp2 o2;
public:
vector_dist_expression_op(const exp1 & o1, const exp2 & o2)
:o1(o1),o2(o2)
{}
template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx(0)))>::type > inline r_type value(const vect_dist_key_dx & key) const
{
return o1.value(key) - o2.value(key);
}
};
template <typename exp1, typename exp2>
class vector_dist_expression_op<exp1,exp2,MUL>
{
const exp1 o1;
const exp2 o2;
public:
vector_dist_expression_op(const exp1 & o1, const exp2 & o2)
:o1(o1),o2(o2)
{}
template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx(0)))>::type > inline r_type value(const vect_dist_key_dx & key) const
{
return o1.value(key) * o2.value(key);
}
};
template <typename exp1, typename exp2>
class vector_dist_expression_op<exp1,exp2,DIV>
{
const exp1 o1;
const exp2 o2;
public:
vector_dist_expression_op(const exp1 & o1, const exp2 & o2)
:o1(o1),o2(o2)
{}
template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx(0)))>::type > inline r_type value(const vect_dist_key_dx & key) const
{
return o1.value(key) / o2.value(key);
}
};
/*! \brief Main class that encapsulate a vector operation expression
*
* \param prp property involved
* \param exp expression type
*
*/
template<unsigned int prp, typename vector>
class vector_dist_expression
{
vector & v;
public:
vector_dist_expression(vector & v)
:v(v)
{}
inline auto value(const vect_dist_key_dx & k) const -> decltype(v.template getProp<prp>(k))
{
return v.template getProp<prp>(k);
}
/*! \brief evaluate the expression and store it in the vector
*
* \param v_exp expression to evaluate
*
*/
template<typename exp1, typename exp2, unsigned int op> vector & operator=(const vector_dist_expression_op<exp1,exp2,op> & v_exp)
{
auto it = v.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
v.template getProp<prp>(key) = v_exp.value(key);
++it;
}
return v;
}
/*! \brief evaluate the expression and store it in the vector
*
* \param v_exp expression to evaluate
*
*/
vector & operator=(double d)
{
auto it = v.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
v.template getProp<prp>(key) = d;
++it;
}
return v;
}
};
/*! \brief Main class that encapsulate a vector operation expression
*
* \param prp property involved
* \param exp expression type
*
*/
template<unsigned int prp>
class vector_dist_expression<prp,double>
{
double d;
public:
inline vector_dist_expression(double & d)
:d(d)
{}
inline double value(const vect_dist_key_dx & k) const
{
return d;
}
};
/* \brief sum two distributed vectors
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<unsigned int p1, unsigned int p2, typename v1, typename v2>
inline vector_dist_expression_op<vector_dist_expression<p1,v1>,vector_dist_expression<p2,v2>,SUM>
operator+(const vector_dist_expression<p1,v1> & va, const vector_dist_expression<p2,v2> & vb)
{
vector_dist_expression_op<vector_dist_expression<p1,v1>,vector_dist_expression<p2,v2>,SUM> exp_sum(va,vb);
return exp_sum;
}
/* \brief sum two distributed vectors
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<typename exp1 , typename exp2, unsigned int op1, unsigned int prp1, typename v1>
inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<prp1,v1>,SUM>
operator+(const vector_dist_expression_op<exp1,exp2,op1> & va, const vector_dist_expression<prp1,v1> & vb)
{
vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<prp1,v1>,SUM> exp_sum(va,vb);
return exp_sum;
}
/* \brief sum two distributed vectors
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<typename exp1 , typename exp2, unsigned int op1, unsigned int prp1, typename v1>
inline vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression_op<exp1,exp2,op1>,SUM>
operator+(const vector_dist_expression<prp1,v1> & va, const vector_dist_expression_op<exp1,exp2,op1> & vb)
{
vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression_op<exp1,exp2,op1>,SUM> exp_sum(va,vb);
return exp_sum;
}
/* \brief sum two distributed vectors
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<typename exp1 , typename exp2, unsigned int op1, typename exp3 , typename exp4, unsigned int op2>
inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression_op<exp3,exp4,op2>,SUM>
operator+(const vector_dist_expression_op<exp1,exp2,op1> & va, const vector_dist_expression_op<exp3,exp4,op2> & vb)
{
vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression_op<exp3,exp4,op2>,SUM> exp_sum(va,vb);
return exp_sum;
}
/* \brief sum two distributed vectors
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<unsigned int prp1 , typename v1>
inline vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression<0,double>,SUM>
operator+(const vector_dist_expression<prp1,v1> & va, double d)
{
vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression<0,double>,SUM> exp_sum(va,vector_dist_expression<0,double>(d));
return exp_sum;
}
/* \brief sum two distributed vectors
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<unsigned int prp1 , typename v1>
inline vector_dist_expression_op<vector_dist_expression<0,double>,vector_dist_expression<prp1,v1>,SUM>
operator+(double d, const vector_dist_expression<prp1,v1> & vb)
{
vector_dist_expression_op<vector_dist_expression<0,double>,vector_dist_expression<prp1,v1>,SUM> exp_sum(vector_dist_expression<0,double>(d),vb);
return exp_sum;
}
/* \brief sum two distributed vectors
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<typename exp1 , typename exp2, unsigned int op1>
inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<0,double>,SUM>
operator+(const vector_dist_expression_op<exp1,exp2,op1> & va, double d)
{
vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<0,double>,SUM> exp_sum(va,vector_dist_expression<0,double>(d));
return exp_sum;
}
/* \brief sum two distributed vectors
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<unsigned int p1, unsigned int p2, typename v1, typename v2>
inline vector_dist_expression_op<vector_dist_expression<p1,v1>,vector_dist_expression<p2,v2>,SUB>
operator-(const vector_dist_expression<p1,v1> & va, const vector_dist_expression<p2,v2> & vb)
{
vector_dist_expression_op<vector_dist_expression<p1,v1>,vector_dist_expression<p2,v2>,SUB> exp_sum(va,vb);
return exp_sum;
}
/* \brief sum two distributed vectors
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<typename exp1, typename exp2, unsigned int op1, unsigned int p2, typename v2>
inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<p2,v2>,SUB>
operator-(const vector_dist_expression_op<exp1,exp2,op1> & va, const vector_dist_expression<p2,v2> & vb)
{
vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<p2,v2>,SUB> exp_sum(va,vb);
return exp_sum;
}
/* \brief sum two distributed vectors
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<typename exp1, typename exp2, unsigned int op1, unsigned int p2, typename v2>
inline vector_dist_expression_op<vector_dist_expression<p2,v2>,vector_dist_expression_op<exp1,exp2,op1>,SUB>
operator-(const vector_dist_expression<p2,v2> & va, const vector_dist_expression_op<exp1,exp2,op1> & vb)
{
vector_dist_expression_op<vector_dist_expression<p2,v2>, vector_dist_expression_op<exp1,exp2,op1>,SUB> exp_sum(va,vb);
return exp_sum;
}
/* \brief sum two distributed vectors
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<typename exp1, typename exp2, unsigned int op1, typename exp3, typename exp4, unsigned int op2>
inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression_op<exp3,exp4,op2>,SUB>
operator-(const vector_dist_expression_op<exp1,exp2,op1> & va, const vector_dist_expression_op<exp3,exp4,op2> & vb)
{
vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression_op<exp3,exp4,op2>,SUB> exp_sum(va,vb);
return exp_sum;
}
/* \brief sum two distributed vectors
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<unsigned int prp1, typename v1>
inline vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression<0,double>,SUB>
operator-(const vector_dist_expression<prp1,v1> & va, double d)
{
vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression<0,double>,SUB> exp_sum(va,vector_dist_expression<0,double>(d));
return exp_sum;
}
/* \brief sum two distributed vectors
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<unsigned int prp1, typename v1>
inline vector_dist_expression_op<vector_dist_expression<0,double>,vector_dist_expression<prp1,v1>,SUB>
operator-(double d, const vector_dist_expression<prp1,v1> & vb)
{
vector_dist_expression_op<vector_dist_expression<0,double>,vector_dist_expression<prp1,v1>,SUB> exp_sum(vector_dist_expression<0,double>(d),vb);
return exp_sum;
}
/* \brief multiplication double with a vector expression
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<unsigned int p2, typename v2>
inline vector_dist_expression_op<vector_dist_expression<0,double>,vector_dist_expression<p2,v2>,MUL>
operator*(double d, const vector_dist_expression<p2,v2> & vb)
{
vector_dist_expression_op<vector_dist_expression<0,double>,vector_dist_expression<p2,v2>,MUL> exp_sum(vector_dist_expression<0,double>(d),vb);
return exp_sum;
}
/* \brief multiplication double with a vector expression
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<unsigned int p2, typename v2>
inline vector_dist_expression_op<vector_dist_expression<p2,v2>,vector_dist_expression<0,double>,MUL>
operator*(const vector_dist_expression<p2,v2> & va, double d)
{
vector_dist_expression_op<vector_dist_expression<p2,v2>,vector_dist_expression<0,double>,MUL> exp_sum(va,vector_dist_expression<0,double>(d));
return exp_sum;
}
/* \brief multiplication double with a vector expression
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<unsigned int p1, typename v1,unsigned int p2, typename v2>
inline vector_dist_expression_op<vector_dist_expression<p1,v1>,vector_dist_expression<p2,v2>,MUL>
operator*(const vector_dist_expression<p1,v1> & va, const vector_dist_expression<p2,v2> & vb)
{
vector_dist_expression_op<vector_dist_expression<p1,v1>,vector_dist_expression<p2,v2>,MUL> exp_sum(va,vb);
return exp_sum;
}
/* \brief multiplication double with a vector expression
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<unsigned int p1, typename v1, typename exp1, typename exp2, unsigned int op1>
inline vector_dist_expression_op<vector_dist_expression<p1,v1>,vector_dist_expression_op<exp1,exp2,op1>,MUL>
operator*(const vector_dist_expression<p1,v1> & va, const vector_dist_expression_op<exp1,exp2,op1> & vb)
{
vector_dist_expression_op<vector_dist_expression<p1,v1>,vector_dist_expression_op<exp1,exp2,op1>,MUL> exp_sum(va,vb);
return exp_sum;
}
/* \brief multiplication double with a vector expression
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<unsigned int p1, typename v1, typename exp1, typename exp2, unsigned int op1>
inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<p1,v1>,MUL>
operator*(const vector_dist_expression_op<exp1,exp2,op1> & va, const vector_dist_expression<p1,v1> & vb)
{
vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<p1,v1>,MUL> exp_sum(va,vb);
return exp_sum;
}
/* \brief multiplication double with a vector expression
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<typename exp1, typename exp2, unsigned int op1, typename exp3 , typename exp4, unsigned int op2>
inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression_op<exp3,exp4,op2>,MUL>
operator*(const vector_dist_expression_op<exp1,exp2,op1> & va, const vector_dist_expression_op<exp3,exp4,op2> & vb)
{
vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression_op<exp3,exp4,op2>,MUL> exp_sum(va,vb);
return exp_sum;
}
/* \brief multiplication double with a vector expression
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<typename exp1, typename exp2, unsigned int op1>
inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<0,double>,DIV>
operator/(const vector_dist_expression_op<exp1,exp2,op1> & va, double d)
{
vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<0,double>,DIV> exp_sum(va,vector_dist_expression<0,double>(d));
return exp_sum;
}
/* \brief multiplication double with a vector expression
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<typename exp1, typename exp2, unsigned int op1>
inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<0,double>,DIV>
operator/(double d, const vector_dist_expression_op<exp1,exp2,op1> & va)
{
vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<0,double>,DIV> exp_sum(vector_dist_expression<0,double>(d),va);
return exp_sum;
}
/* \brief multiplication double with a vector expression
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<unsigned int prp1, typename v1>
inline vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression<0,double>,DIV>
operator/(const vector_dist_expression<prp1,v1> & va, double d)
{
vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression<0,double>,DIV> exp_sum(va,vector_dist_expression<0,double>(d));
return exp_sum;
}
/* \brief multiplication double with a vector expression
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<unsigned int prp1, typename v1>
inline vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression<0,double>,DIV>
operator/(double d, const vector_dist_expression<prp1,v1> & va)
{
vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression<0,double>,DIV> exp_sum(va,vector_dist_expression<0,double>(d));
return exp_sum;
}
/* \brief multiplication double with a vector expression
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<unsigned int prp1, typename v1, unsigned int prp2, typename v2>
inline vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression<prp2,v2>,DIV>
operator/(const vector_dist_expression<prp1,v1> & va, const vector_dist_expression<prp2,v2> & vb)
{
vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression<prp2,v2>,DIV> exp_sum(va,vb);
return exp_sum;
}
/* \brief multiplication double with a vector expression
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*
*/
template<unsigned int prp1, typename v1, typename exp1,typename exp2, unsigned int op1>
inline vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression_op<exp1,exp2,op1>,DIV>
operator/(const vector_dist_expression<prp1,v1> & va, const vector_dist_expression_op<exp1,exp2,op1> & vb)
{
vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression_op<exp1,exp2,op1>,DIV> exp_sum(va,vb);
return exp_sum;
}
/* \brief multiplication double with a vector expression
*
* \param v1 vector1
* \param v2 vector2
*
* \return a grid_key_dx_expression that encapsulate the expression
*