vector.cpp 2.36 KB
Newer Older
1 2 3 4 5 6 7 8
#include "Vector/vector_dist.hpp"
#include "Decomposition/CartDecomposition.hpp"


template<typename T> class Particle
{
public:

incardon's avatar
incardon committed
9 10 11 12 13 14
#ifdef SE_CLASS3

	typedef boost::fusion::vector<T,T[3],T[3][3],SE3_ADD_PROP(3)> type;

#else

15 16
	typedef boost::fusion::vector<T,T[3],T[3][3]> type;

incardon's avatar
incardon committed
17 18
#endif

19 20 21 22 23
	type data;

	static const unsigned int s = 0;
	static const unsigned int v = 1;
	static const unsigned int t = 2;
incardon's avatar
incardon committed
24 25 26 27 28 29 30 31

#ifdef SE_CLASS3

	static const unsigned int max_prop = SE3_MAX_PROP(3);
	static const unsigned int max_prop_real = 3;

#else

32
	static const unsigned int max_prop = 3;
incardon's avatar
incardon committed
33 34 35 36
	static const unsigned int max_prop_real = 3;

#endif

incardon's avatar
incardon committed
37 38 39 40 41
	static inline bool noPointers()
	{
		return true;
	}

42 43 44 45 46 47 48 49 50 51
};

int main(int argc, char* argv[])
{
	//
	// ### WIKI 2 ###
	//
	// Here we Initialize the library, than we create a uniform random generator between 0 and 1 to to generate particles
	// randomly in the domain, we create a Box that define our domain, boundary conditions, and ghost
	//
52
	openfpm_init(&argc,&argv);
53
	Vcluster<> & v_cl = create_vcluster();
54 55 56 57 58 59 60 61 62 63

	// set the seed
	// create the random generator engine
	std::default_random_engine eg(v_cl.getProcessUnitID()*100);
	std::uniform_real_distribution<float> ud(0.0f, 1.0f);

	Box<2,float> domain({0.0,0.0},{1.0,1.0});
    size_t bc[2]={PERIODIC,PERIODIC};
	Ghost<2,float> g(0.01);
	
incardon's avatar
incardon committed
64
	vector_dist<2,float, Particle<float> > vd(4096,domain,bc,g);
65 66 67 68 69 70 71

	auto it = vd.getIterator();

	while (it.isNext())
	{
		auto key = it.get();

Pietro Incardona's avatar
Pietro Incardona committed
72 73
		vd.getPos(key)[0] = ud(eg);
		vd.getPos(key)[1] = ud(eg);
74

Pietro Incardona's avatar
Pietro Incardona committed
75 76
		vd.template getProp<1>(key)[0] = sin(10.0*vd.getPos(key)[0]);
		vd.template getProp<1>(key)[1] = sin(10.0*vd.getPos(key)[1]);
77

78 79 80
		++it;
	}

81
	vd.write("Vector/vector_before_map",CSV_WRITER);
82 83 84

	vd.map();

85
	vd.write("Vector/vector_after_map",CSV_WRITER);
86
	
87 88
	vd.ghost_get<0>();

89
	vd.write("Vector/vector_ghost_fill",CSV_WRITER);
90

91 92 93 94 95 96 97 98 99 100 101 102
	vd.getDecomposition().write("Vector/vect_decomposition");

	// move the particles

	for (size_t i = 0 ; i < 100 ; i++)
	{
		auto it = vd.getDomainIterator();

		while (it.isNext())
		{
			auto key = it.get();

Pietro Incardona's avatar
Pietro Incardona committed
103 104
			vd.getPos(key)[0] += 0.005;
			vd.getPos(key)[1] += 0.005;
Pietro Incardona's avatar
Pietro Incardona committed
105
                        
Pietro Incardona's avatar
Pietro Incardona committed
106 107
            vd.template getProp<1>(key)[0] = 0.005;
            vd.template getProp<1>(key)[1] = 0.005;
108 109 110

			++it;
		}
incardon's avatar
incardon committed
111
		vd.write_frame("Vector/vector_move_before_map",i,CSV_WRITER);
112
		vd.map();
incardon's avatar
incardon committed
113
		vd.write_frame("Vector/vector_move",i,CSV_WRITER);
114
	}
115

116
	openfpm_finalize();
117
}