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 {
36 private:
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
46 public:
47 OctreeStructCell(plint divis, plint l, unsigned int lim, hemo::Array<double, 6> bbox,
48 std::vector<hemo::Array<plint,3>> triangle_list_,
49 std::vector<HemoCellParticle>& part, const std::vector<int> cell);
50 OctreeStructCell(plint divis, plint l, unsigned int lim,
51 std::vector<hemo::Array<plint,3>> triangle_list_,
52 std::vector<HemoCellParticle>& part, const std::vector<int> cell);
53 private:
54 void sharedConstructor(plint divis, plint l, unsigned int lim,
55 std::vector<hemo::Array<plint,3>> triangle_list_,
56 std::vector<HemoCellParticle> & part, const std::vector<int> cell);
57 public:
59 void constructTree(std::vector<HemoCellParticle>& part, std::vector<int> cell, std::vector<hemo::Array<plint,3>> triangle_list_);
61 void findCrossings(hemo::Array<plint, 3> latticeSite, std::vector<hemo::Array<plint,3>> &);
62
63 template<template<typename U> class Descriptor>
64 void findInnerNodes(plb::BlockLattice3D<T,Descriptor> * fluid, std::vector<HemoCellParticle> & particles, const std::vector<int> & cell, std::vector<plb::Cell<T,Descriptor>*> & innerNodes) {
65 innerNodes.clear();
67 //Adjust bbox to fit local atomic block
68 bbox[0] = bbox[0] < fluid->getLocation().x ? fluid->getLocation().x : bbox[0];
69 bbox[1] = bbox[1] > fluid->getLocation().x + fluid->getNx()-1 ? fluid->getLocation().x + fluid->getNx()-1: bbox[1];
70 bbox[2] = bbox[2] < fluid->getLocation().y ? fluid->getLocation().y : bbox[2];
71 bbox[3] = bbox[3] > fluid->getLocation().y + fluid->getNy()-1 ? fluid->getLocation().y + fluid->getNy()-1: bbox[3];
72 bbox[4] = bbox[4] < fluid->getLocation().z ? fluid->getLocation().z : bbox[4];
73 bbox[5] = bbox[5] > fluid->getLocation().z + fluid->getNz()-1 ? fluid->getLocation().z + fluid->getNz()-1: bbox[5];
74
75 // Create a triple for-loop to go over all lattice points in the bounding box of a cell
76 for (int x = (int)bbox[0]; x <= (int)bbox[1]+0.5; x++) {
77 for (int y = (int)bbox[2]; y <= (int)bbox[3]+0.5; y++) {
78 for (int z = (int)bbox[4]; z <= (int)bbox[5]+0.5; z++) {
79 int crossedCounter = 0; // How many triangles are crossed
80
81 hemo::Array<plint, 3> latticeSite = {x, y, z};
82 std::vector<hemo::Array<plint,3>> triangles_list;
83 findCrossings(latticeSite,triangles_list);
84
85 for (hemo::Array<plint, 3> triangle : triangles_list) {
86 // Muller-trumbore intersection algorithm
87 const hemo::Array<double,3> & v0 = particles[cell[triangle[0]]].sv.position;
88 const hemo::Array<double,3> & v1 = particles[cell[triangle[1]]].sv.position;
89 const hemo::Array<double,3> & v2 = particles[cell[triangle[2]]].sv.position;
90
91 crossedCounter += hemo::MollerTrumbore(v0, v1, v2, latticeSite);
92 }
93
94 // Count even-odd crossings
95 if (crossedCounter%2) {
96 int x_l = x-fluid->getLocation().x;
97 int y_l = y-fluid->getLocation().y;
98 int z_l = z-fluid->getLocation().z;
99 innerNodes.push_back(&fluid->get(x_l,y_l,z_l));
100 }
101 }
102 }
103 }
104 }
105
106 template<template<typename U> class Descriptor>
107 void findInnerNodes(plb::BlockLattice3D<T,Descriptor> * fluid, std::vector<HemoCellParticle> & particles, const std::vector<int> & cell, std::set<Array<plint,3>> & innerNodes) {
108 innerNodes.clear();
109 hemo::Array<T,6> bbox = bBox;
110 //Adjust bbox to fit local atomic block
111 bbox[0] = bbox[0] < fluid->getLocation().x ? fluid->getLocation().x : bbox[0];
112 bbox[1] = bbox[1] > fluid->getLocation().x + fluid->getNx()-1 ? fluid->getLocation().x + fluid->getNx()-1: bbox[1];
113 bbox[2] = bbox[2] < fluid->getLocation().y ? fluid->getLocation().y : bbox[2];
114 bbox[3] = bbox[3] > fluid->getLocation().y + fluid->getNy()-1 ? fluid->getLocation().y + fluid->getNy()-1: bbox[3];
115 bbox[4] = bbox[4] < fluid->getLocation().z ? fluid->getLocation().z : bbox[4];
116 bbox[5] = bbox[5] > fluid->getLocation().z + fluid->getNz()-1 ? fluid->getLocation().z + fluid->getNz()-1: bbox[5];
117
118 // Create a triple for-loop to go over all lattice points in the bounding box of a cell
119 for (int x = (int)bbox[0]; x <= (int)bbox[1]+0.5; x++) {
120 for (int y = (int)bbox[2]; y <= (int)bbox[3]+0.5; y++) {
121 for (int z = (int)bbox[4]; z <= (int)bbox[5]+0.5; z++) {
122 int crossedCounter = 0; // How many triangles are crossed
123
124 hemo::Array<plint, 3> latticeSite = {x, y, z};
125 std::vector<hemo::Array<plint,3>> triangles_list;
126 findCrossings(latticeSite,triangles_list);
127
128 for (hemo::Array<plint, 3> triangle : triangles_list) {
129 // Muller-trumbore intersection algorithm
130 const hemo::Array<double,3> & v0 = particles[cell[triangle[0]]].sv.position;
131 const hemo::Array<double,3> & v1 = particles[cell[triangle[1]]].sv.position;
132 const hemo::Array<double,3> & v2 = particles[cell[triangle[2]]].sv.position;
133
134 crossedCounter += hemo::MollerTrumbore(v0, v1, v2, latticeSite);
135 }
136
137 // Count even-odd crossings
138 if (crossedCounter%2) {
139 int x_l = x-fluid->getLocation().x;
140 int y_l = y-fluid->getLocation().y;
141 int z_l = z-fluid->getLocation().z;
142 innerNodes.insert({x_l,y_l,z_l});
143 }
144 }
145 }
146 }
147 }
148 };
149}
150
151#endif
Definition octree.h:35
hemo::Array< T, 6 > bBox
Definition octree.h:37
OctreeStructCell(plint divis, plint l, unsigned int lim, hemo::Array< double, 6 > bbox, std::vector< hemo::Array< plint, 3 > > triangle_list_, std::vector< HemoCellParticle > &part, const std::vector< int > cell)
void constructTree(std::vector< HemoCellParticle > &part, std::vector< int > cell, std::vector< hemo::Array< plint, 3 > > triangle_list_)
Definition octree.cpp:106
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:107
OctreeStructCell(plint divis, plint l, unsigned int lim, std::vector< hemo::Array< plint, 3 > > triangle_list_, std::vector< HemoCellParticle > &part, const std::vector< int > cell)
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:64
OctreeStructCell * nodes[8]
Definition octree.h:39
~OctreeStructCell()
Definition octree.cpp:83
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:163
plint maxDivisions
Definition octree.h:41
plint level
Definition octree.h:42
int returnTrianglesAmount()
Definition octree.cpp:92
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:66
long int plint
Definition constant_defaults.h:127
Definition cell.py:1
Definition config.cpp:34
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:39