hemocell
Loading...
Searching...
No Matches
octree.h
Go to the documentation of this file.
1/*
2This file is part of the HemoCell library
3
4HemoCell is developed and maintained by the Computational Science Lab
5in the University of Amsterdam. Any questions or remarks regarding this library
6can be sent to: info@hemocell.eu
7
8When using the HemoCell library in scientific work please cite the
9corresponding paper: https://doi.org/10.3389/fphys.2017.00563
10
11The HemoCell library is free software: you can redistribute it and/or
12modify it under the terms of the GNU Affero General Public License as
13published by the Free Software Foundation, either version 3 of the
14License, or (at your option) any later version.
15
16The library is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU Affero General Public License for more details.
20
21You should have received a copy of the GNU Affero General Public License
22along with this program. If not, see <http://www.gnu.org/licenses/>.
23*/
24#ifndef HEMO_OCTREE_H
25#define HEMO_OCTREE_H
26
27#include "hemoCellParticle.h" // Need to make pointers to particle object
28#include <vector>
29#include "atomicBlock/blockLattice3D.h"
30#include "atomicBlock/blockLattice3D.hh"
31#include "mollerTrumbore.h"
32
33
34namespace hemo {
36private:
38 std::vector<hemo::Array<plint, 3>> triangle_list = {}; // Keep all the unsorted obs here
40
42 plint level; // To keep track of how many octants we have already
43 bool finalNode = false; // To track if needs more subdividing
45
46public:
47 OctreeStructCell(plint divis, plint l, unsigned int lim, hemo::Array<double, 6> bbox,
48 std::vector<hemo::Array<plint, 3>> triangle_list_, std::vector<HemoCellParticle> & part,
49 const std::vector<int> cell);
50 OctreeStructCell(plint divis, plint l, unsigned int lim, std::vector<hemo::Array<plint, 3>> triangle_list_,
51 std::vector<HemoCellParticle> & part, const std::vector<int> cell);
52
53private:
54 void sharedConstructor(plint divis, plint l, unsigned int lim, std::vector<hemo::Array<plint, 3>> triangle_list_,
55 std::vector<HemoCellParticle> & part, const std::vector<int> cell);
56
57public:
59 void constructTree(std::vector<HemoCellParticle> & part, std::vector<int> cell,
60 std::vector<hemo::Array<plint, 3>> triangle_list_);
62 void findCrossings(hemo::Array<plint, 3> latticeSite, std::vector<hemo::Array<plint, 3>> &);
63
64 template <template <typename U> class Descriptor>
65 void findInnerNodes(plb::BlockLattice3D<T, Descriptor> * fluid, std::vector<HemoCellParticle> & particles,
66 const std::vector<int> & cell, std::vector<plb::Cell<T, Descriptor> *> & innerNodes) {
67 innerNodes.clear();
69 //Adjust bbox to fit local atomic block
70 bbox[0] = bbox[0] < fluid->getLocation().x ? fluid->getLocation().x : bbox[0];
71 bbox[1] =
72 bbox[1] > fluid->getLocation().x + fluid->getNx() - 1 ? fluid->getLocation().x + fluid->getNx() - 1 : bbox[1];
73 bbox[2] = bbox[2] < fluid->getLocation().y ? fluid->getLocation().y : bbox[2];
74 bbox[3] =
75 bbox[3] > fluid->getLocation().y + fluid->getNy() - 1 ? fluid->getLocation().y + fluid->getNy() - 1 : bbox[3];
76 bbox[4] = bbox[4] < fluid->getLocation().z ? fluid->getLocation().z : bbox[4];
77 bbox[5] =
78 bbox[5] > fluid->getLocation().z + fluid->getNz() - 1 ? fluid->getLocation().z + fluid->getNz() - 1 : bbox[5];
79
80 // Create a triple for-loop to go over all lattice points in the bounding box of a cell
81 for (int x = (int)bbox[0]; x <= (int)bbox[1] + 0.5; x++) {
82 for (int y = (int)bbox[2]; y <= (int)bbox[3] + 0.5; y++) {
83 for (int z = (int)bbox[4]; z <= (int)bbox[5] + 0.5; z++) {
84 int crossedCounter = 0; // How many triangles are crossed
85
86 hemo::Array<plint, 3> latticeSite = {x, y, z};
87 std::vector<hemo::Array<plint, 3>> triangles_list;
88 findCrossings(latticeSite, triangles_list);
89
90 for (hemo::Array<plint, 3> triangle : triangles_list) {
91 // Muller-trumbore intersection algorithm
92 const hemo::Array<double, 3> & v0 = particles[cell[triangle[0]]].sv.position;
93 const hemo::Array<double, 3> & v1 = particles[cell[triangle[1]]].sv.position;
94 const hemo::Array<double, 3> & v2 = particles[cell[triangle[2]]].sv.position;
95
96 crossedCounter += hemo::MollerTrumbore(v0, v1, v2, latticeSite);
97 }
98
99 // Count even-odd crossings
100 if (crossedCounter % 2) {
101 int x_l = x - fluid->getLocation().x;
102 int y_l = y - fluid->getLocation().y;
103 int z_l = z - fluid->getLocation().z;
104 innerNodes.push_back(&fluid->get(x_l, y_l, z_l));
105 }
106 }
107 }
108 }
109 }
110
111 template <template <typename U> class Descriptor>
112 void findInnerNodes(plb::BlockLattice3D<T, Descriptor> * fluid, std::vector<HemoCellParticle> & particles,
113 const std::vector<int> & cell, std::set<Array<plint, 3>> & innerNodes) {
114 innerNodes.clear();
115 hemo::Array<T, 6> bbox = bBox;
116 //Adjust bbox to fit local atomic block
117 bbox[0] = bbox[0] < fluid->getLocation().x ? fluid->getLocation().x : bbox[0];
118 bbox[1] =
119 bbox[1] > fluid->getLocation().x + fluid->getNx() - 1 ? fluid->getLocation().x + fluid->getNx() - 1 : bbox[1];
120 bbox[2] = bbox[2] < fluid->getLocation().y ? fluid->getLocation().y : bbox[2];
121 bbox[3] =
122 bbox[3] > fluid->getLocation().y + fluid->getNy() - 1 ? fluid->getLocation().y + fluid->getNy() - 1 : bbox[3];
123 bbox[4] = bbox[4] < fluid->getLocation().z ? fluid->getLocation().z : bbox[4];
124 bbox[5] =
125 bbox[5] > fluid->getLocation().z + fluid->getNz() - 1 ? fluid->getLocation().z + fluid->getNz() - 1 : bbox[5];
126
127 // Create a triple for-loop to go over all lattice points in the bounding box of a cell
128 for (int x = (int)bbox[0]; x <= (int)bbox[1] + 0.5; x++) {
129 for (int y = (int)bbox[2]; y <= (int)bbox[3] + 0.5; y++) {
130 for (int z = (int)bbox[4]; z <= (int)bbox[5] + 0.5; z++) {
131 int crossedCounter = 0; // How many triangles are crossed
132
133 hemo::Array<plint, 3> latticeSite = {x, y, z};
134 std::vector<hemo::Array<plint, 3>> triangles_list;
135 findCrossings(latticeSite, triangles_list);
136
137 for (hemo::Array<plint, 3> triangle : triangles_list) {
138 // Muller-trumbore intersection algorithm
139 const hemo::Array<double, 3> & v0 = particles[cell[triangle[0]]].sv.position;
140 const hemo::Array<double, 3> & v1 = particles[cell[triangle[1]]].sv.position;
141 const hemo::Array<double, 3> & v2 = particles[cell[triangle[2]]].sv.position;
142
143 crossedCounter += hemo::MollerTrumbore(v0, v1, v2, latticeSite);
144 }
145
146 // Count even-odd crossings
147 if (crossedCounter % 2) {
148 int x_l = x - fluid->getLocation().x;
149 int y_l = y - fluid->getLocation().y;
150 int z_l = z - fluid->getLocation().z;
151 innerNodes.insert({x_l, y_l, z_l});
152 }
153 }
154 }
155 }
156 }
157};
158}
159
160#endif
Definition octree.h:35
hemo::Array< T, 6 > bBox
Definition octree.h:37
void constructTree(std::vector< HemoCellParticle > &part, std::vector< int > cell, std::vector< hemo::Array< plint, 3 > > triangle_list_)
Definition octree.cpp:102
void findInnerNodes(plb::BlockLattice3D< T, Descriptor > *fluid, std::vector< HemoCellParticle > &particles, const std::vector< int > &cell, std::set< Array< plint, 3 > > &innerNodes)
Definition octree.h:112
plint limit
Definition octree.h:44
void findInnerNodes(plb::BlockLattice3D< T, Descriptor > *fluid, std::vector< HemoCellParticle > &particles, const std::vector< int > &cell, std::vector< plb::Cell< T, Descriptor > * > &innerNodes)
Definition octree.h:65
OctreeStructCell * nodes[8]
Definition octree.h:39
~OctreeStructCell()
Definition octree.cpp:81
bool finalNode
Definition octree.h:43
std::vector< hemo::Array< plint, 3 > > triangle_list
Definition octree.h:38
void findCrossings(hemo::Array< plint, 3 > latticeSite, std::vector< hemo::Array< plint, 3 > > &)
Definition octree.cpp:152
plint maxDivisions
Definition octree.h:41
plint level
Definition octree.h:42
int returnTrianglesAmount()
Definition octree.cpp:88
void sharedConstructor(plint divis, plint l, unsigned int lim, std::vector< hemo::Array< plint, 3 > > triangle_list_, std::vector< HemoCellParticle > &part, const std::vector< int > cell)
Definition octree.cpp:65
long int plint
Definition constant_defaults.h:149
Definition cell.py:1
Definition config.cpp:37
int MollerTrumbore(const hemo::Array< T, 3 > &v0, const hemo::Array< T, 3 > &v1, const hemo::Array< T, 3 > &v2, hemo::Array< plint, 3 > &rayPoint)
Definition mollerTrumbore.h:30
Definition array.h:40