vector.cpp 2.34 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

37 38 39 40 41 42 43 44 45 46
};

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
	//
47 48
	openfpm_init(&argc,&argv);
	Vcluster & v_cl = create_vcluster();
49 50 51 52 53 54 55 56 57 58 59 60
	
	typedef Point<2,float> s;

	// 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
61
	vector_dist<2,float, Particle<float> > vd(4096,domain,bc,g);
62 63 64 65 66 67 68

	auto it = vd.getIterator();

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

Pietro Incardona's avatar
Pietro Incardona committed
69 70
		vd.getPos(key)[0] = ud(eg);
		vd.getPos(key)[1] = ud(eg);
71

Pietro Incardona's avatar
Pietro Incardona committed
72 73
		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]);
74

75 76 77
		++it;
	}

78
	vd.write("Vector/vector_before_map",CSV_WRITER);
79 80 81

	vd.map();

82
	vd.write("Vector/vector_after_map",CSV_WRITER);
83
	
84 85
	vd.ghost_get<0>();

86
	vd.write("Vector/vector_ghost_fill",CSV_WRITER);
87

88 89 90 91 92 93 94 95 96 97 98 99
	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
100 101
			vd.getPos(key)[0] += 0.005;
			vd.getPos(key)[1] += 0.005;
Pietro Incardona's avatar
Pietro Incardona committed
102
                        
Pietro Incardona's avatar
Pietro Incardona committed
103 104
            vd.template getProp<1>(key)[0] = 0.005;
            vd.template getProp<1>(key)[1] = 0.005;
105 106 107

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

113
	openfpm_finalize();
114
}