vector_dist_multiphase_functions.hpp 4.51 KB
Newer Older
incardon's avatar
incardon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
/*
 * vector_dist_multiphase_functions.hpp
 *
 *  Created on: Oct 14, 2016
 *      Author: i-bird
 */

#ifndef SRC_VECTOR_VECTOR_DIST_MULTIPHASE_FUNCTIONS_HPP_
#define SRC_VECTOR_VECTOR_DIST_MULTIPHASE_FUNCTIONS_HPP_

#include "NN/CellList/CellListM.hpp"
#include "NN/VerletList/VerletListM.hpp"

incardon's avatar
incardon committed
14
template<typename Vector, typename CL, typename T> VerletList<Vector::dims,typename Vector::stype,FAST,shift<Vector::dims,typename Vector::stype>> createVerlet(Vector & v, Vector & v1, CL & cl, T r_cut)
incardon's avatar
incardon committed
15
16
17
{
	VerletList<Vector::dims,typename Vector::stype,FAST,shift<Vector::dims,typename Vector::stype>> ver;

incardon's avatar
incardon committed
18
	ver.Initialize(cl,r_cut,v.getPosVector(),v1.getPosVector(),v.size_local());
incardon's avatar
incardon committed
19
20
21
22

	return ver;
}

incardon's avatar
incardon committed
23
template<unsigned int sh_byte, typename Vector , typename Vector1,typename CL, typename T> VerletListM<Vector::dims,typename Vector::stype,sh_byte,CL,shift<Vector::dims,typename Vector::stype>> createVerletM(Vector & v, Vector1 & phases, CL & cl, T r_cut)
incardon's avatar
incardon committed
24
{
incardon's avatar
incardon committed
25
	VerletListM<Vector::dims,typename Vector::stype,sh_byte,CL,shift<Vector::dims,typename Vector::stype>> ver;
incardon's avatar
incardon committed
26

incardon's avatar
incardon committed
27
28
29
30
31
32
	openfpm::vector<pos_v<Vector::dims,typename Vector::stype>> v_phases;

	for (size_t i = 0 ; i < phases.size() ; i++)
		v_phases.add(pos_v<Vector::dims,typename Vector::stype>(phases.get(i).getPosVector()));

	ver.Initialize(cl,r_cut,v.getPosVector(),v_phases,v.size_local());
incardon's avatar
incardon committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

	return ver;
}

template<unsigned int nbit, typename Vector, typename T> CellListM<Vector::dims,typename Vector::stype,nbit> createCellListM(openfpm::vector<Vector> & phases, T r_cut)
{
	size_t div[3];
	Box<Vector::dims,typename Vector::stype> box_cl;

	CellListM<Vector::dims,typename Vector::stype,nbit> NN;
	if (phases.size() == 0)
		return NN;

	box_cl = phases.get(0).getDecomposition().getProcessorBounds();
	phases.get(0).getCellListParams(r_cut,div,box_cl);

	NN.Initialize(box_cl,div);

	// for all the phases i
	for (size_t i = 0; i < phases.size() ; i++)
	{
		// iterate across all the particle of the phase i
		auto it = phases.get(i).getDomainAndGhostIterator();
		while (it.isNext())
		{
			auto key = it.get();

			// Add the particle of the phase i to the cell list
			NN.add(phases.get(i).getPos(key), key.getKey(), i);

			++it;
		}
	}

	return NN;
}


/////// Symmetric version

incardon's avatar
incardon committed
73
template<typename Vector,typename CL, typename T> VerletList<Vector::dims,typename Vector::stype,FAST,shift<Vector::dims,typename Vector::stype>> createVerletSym(Vector & v, Vector & v1, CL & cl, T r_cut)
incardon's avatar
incardon committed
74
75
76
{
	VerletList<Vector::dims,typename Vector::stype,FAST,shift<Vector::dims,typename Vector::stype>> ver;

incardon's avatar
incardon committed
77
	ver.Initialize(cl,r_cut,v.getPosVector(),v1.getPosVector(),v.size_local());
incardon's avatar
incardon committed
78
79
80
81

	return ver;
}

incardon's avatar
incardon committed
82
template<unsigned int sh_byte, typename Vector, typename Vector1 ,typename CL, typename T> VerletListM<Vector::dims,typename Vector::stype,sh_byte,CL,shift<Vector::dims,typename Vector::stype>> createVerletSymM(Vector & v, Vector1 & phases, CL & cl, T r_cut)
incardon's avatar
incardon committed
83
{
incardon's avatar
incardon committed
84
85
86
87
88
89
	VerletListM<Vector::dims,typename Vector::stype,sh_byte,CL,shift<Vector::dims,typename Vector::stype>> ver;

	openfpm::vector<pos_v<Vector::dims,typename Vector::stype>> v_phases;

	for (size_t i = 0 ; i < phases.size() ; i++)
		v_phases.add(pos_v<Vector::dims,typename Vector::stype>(phases.get(i).getPosVector()));
incardon's avatar
incardon committed
90

incardon's avatar
incardon committed
91
	ver.Initialize(cl,r_cut,v.getPosVector(),v_phases,v.size_local(),VL_SYMMETRIC);
incardon's avatar
incardon committed
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

	return ver;
}

template<unsigned int nbit, typename Vector, typename T> CellListM<Vector::dims,typename Vector::stype,nbit> createCellListSymM(openfpm::vector<Vector> & phases, T r_cut)
{
	Box<Vector::dims,typename Vector::stype> box_cl;

	CellListM<Vector::dims,typename Vector::stype,nbit> NN;
	if (phases.size() == 0)
		return NN;

	// Calculate the Cell list division for this CellList
	CellDecomposer_sm<Vector::dims,typename Vector::stype,shift<Vector::dims,typename Vector::stype>> cd_sm;

	size_t pad = 0;
	cl_param_calculateSym(phases.get(0).getDecomposition().getDomain(),cd_sm,phases.get(0).getDecomposition().getGhost(),r_cut,pad);

	// Processor bounding box
	Box<Vector::dims, typename Vector::stype> pbox = phases.get(0).getDecomposition().getProcessorBounds();

	// Ghost padding extension
	Ghost<Vector::dims,size_t> g_ext(0);
	NN.Initialize(cd_sm,pbox,pad);

	// for all the phases i
	for (size_t i = 0; i < phases.size() ; i++)
	{
		// iterate across all the particle of the phase i
		auto it = phases.get(i).getDomainAndGhostIterator();
		while (it.isNext())
		{
			auto key = it.get();

			// Add the particle of the phase i to the cell list
			NN.add(phases.get(i).getPos(key), key.getKey(), i);

			++it;
		}
	}

	return NN;
}

#endif /* SRC_VECTOR_VECTOR_DIST_MULTIPHASE_FUNCTIONS_HPP_ */