42 std::vector<T> oldPos(3,T());
43 oldPos[0] = p->getPos()[0] - _dT * p->getVel()[0];
44 oldPos[1] = p->getPos()[1] - _dT * p->getVel()[1];
45 oldPos[2] = p->getPos()[2] - _dT * p->getVel()[2];
47 std::vector<T> line(3,T());
48 line[0] = p->getPos()[0] - oldPos[0];
49 line[1] = p->getPos()[1] - oldPos[1];
50 line[2] = p->getPos()[2] - oldPos[2];
52 std::vector<T> reflection(3, T());
53 int latticeR[4] = { 0,0,0,0 };
58 latticeR[0] = p->getCuboid();
59 _sg.getCuboidGeometry().get(latticeR[0]).getLatticeR(&(latticeR[1]),&p->getPos()[0]);
60 int mat = _sg.get(latticeR);
62 for (_matIter = _materials.begin(); _matIter != _materials.end(); _matIter++) {
63 if (mat == *_matIter) {
66 std::vector<int> normal(3, T());
67 if (_sg.get(latticeR[0], latticeR[1] - 1, latticeR[2], latticeR[3]) == 1) {
70 if (_sg.get(latticeR[0], latticeR[1] + 1, latticeR[2], latticeR[3]) == 1) {
73 if (_sg.get(latticeR[0], latticeR[1], latticeR[2] - 1, latticeR[3]) == 1) {
76 if (_sg.get(latticeR[0], latticeR[1], latticeR[2] + 1, latticeR[3]) == 1) {
79 if (_sg.get(latticeR[0], latticeR[1], latticeR[2], latticeR[3] - 1) == 1) {
82 if (_sg.get(latticeR[0], latticeR[1], latticeR[2], latticeR[3] + 1) == 1) {
86 if (normal[0]==0 && normal[1]==0 && normal[2]==0) {
89 if (_sg.get(latticeR[0], latticeR[1] - 1, latticeR[2] - 1, latticeR[3]) == 1) {
93 else if (_sg.get(latticeR[0], latticeR[1] - 1, latticeR[2] + 1, latticeR[3]) == 1) {
97 else if (_sg.get(latticeR[0], latticeR[1] + 1, latticeR[2] - 1, latticeR[3]) == 1) {
101 else if (_sg.get(latticeR[0], latticeR[1] + 1, latticeR[2] + 1, latticeR[3]) == 1) {
105 else if (_sg.get(latticeR[0], latticeR[1] - 1, latticeR[2], latticeR[3] - 1) == 1) {
109 else if (_sg.get(latticeR[0], latticeR[1] - 1, latticeR[2], latticeR[3] + 1) == 1) {
113 else if (_sg.get(latticeR[0], latticeR[1] + 1, latticeR[2], latticeR[3] - 1) == 1) {
117 else if (_sg.get(latticeR[0], latticeR[1] + 1, latticeR[2], latticeR[3] + 1) == 1) {
121 else if (_sg.get(latticeR[0], latticeR[1], latticeR[2] - 1, latticeR[3] - 1) == 1) {
125 else if (_sg.get(latticeR[0], latticeR[1], latticeR[2] - 1, latticeR[3] + 1) == 1) {
129 else if (_sg.get(latticeR[0], latticeR[1], latticeR[2] + 1, latticeR[3] - 1) == 1) {
133 else if (_sg.get(latticeR[0], latticeR[1], latticeR[2] + 1, latticeR[3] + 1) == 1) {
138 else if (_sg.get(latticeR[0], latticeR[1] - 1, latticeR[2] - 1, latticeR[3] - 1) == 1) {
143 else if (_sg.get(latticeR[0], latticeR[1] - 1, latticeR[2] - 1, latticeR[3] + 1) == 1) {
148 else if (_sg.get(latticeR[0], latticeR[1] - 1, latticeR[2] + 1, latticeR[3] - 1) == 1) {
153 else if (_sg.get(latticeR[0], latticeR[1] - 1, latticeR[2] + 1, latticeR[3] + 1) == 1) {
158 else if (_sg.get(latticeR[0], latticeR[1] + 1, latticeR[2] - 1, latticeR[3] - 1) == 1) {
163 else if (_sg.get(latticeR[0], latticeR[1] + 1, latticeR[2] - 1, latticeR[3] + 1) == 1) {
168 else if (_sg.get(latticeR[0], latticeR[1] + 1, latticeR[2] + 1, latticeR[3] - 1) == 1) {
173 else if (_sg.get(latticeR[0], latticeR[1] + 1, latticeR[2] + 1, latticeR[3] + 1) == 1) {
180 std::cout <<
"----->>>>> ERROR Normal is ZERO" << std::endl;
185 T prod = line[0]*normal[0] + line[1]*normal[1] + line[2]*normal[2];
195 reflection[0] = line[0] - 2.*prod*normal[0]*invNormNormal;
196 reflection[1] = line[1] - 2.*prod*normal[1]*invNormNormal;
197 reflection[2] = line[2] - 2.*prod*normal[2]*invNormNormal;
202 reflection[0] = reflection[0]*vel;
203 reflection[1] = reflection[1]*vel;
204 reflection[2] = reflection[2]*vel;
207 oldPos[0] += 0.5 * (line[0] + reflection[0]) * _dT;
208 oldPos[1] += 0.5 * (line[1] + reflection[1]) * _dT;
209 oldPos[2] += 0.5 * (line[2] + reflection[2]) * _dT;
211 p->getVel() = reflection;