hemocell
Loading...
Searching...
No Matches
immersedBoundaryMethod.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 IMMERSEDBOUNDARYMETHOD_H
25#define IMMERSEDBOUNDARYMETHOD_H
26
27#include <vector>
28
29namespace hemo {
30
32inline bool contained_sane(hemo::Array<plint,3> const& x, Box3D const& box) {
33 return x[0]>=box.x0 && x[0]<=box.x1 &&
34 x[1]>=box.y0 && x[1]<=box.y1 &&
35 x[2]>=box.z0 && x[2]<=box.z1;
36}
37inline T phi2 (T x) {
38 x = fabs(x);
39 x = 1.0 - x;
40 return max(x,(T)0.0);
41}
42
43template<typename T>
44T phi3 (T x) ;
45
46template<typename T>
47T phi4 (T x) ;
48
49template<typename T>
50T phi4c (T x) ;
51
52template<typename T, template<typename U> class Descriptor>
54 BlockLattice3D<T,Descriptor> const& block, hemo::Array<T,3> const& position,
55 std::vector<Dot3D>& cellPos, std::vector<T>& weights);
56
57template<typename T, template<typename U> class Descriptor>
59 BlockLattice3D<T,Descriptor> const& block, hemo::Array<T,3> const& position,
60 std::vector<Dot3D>& cellPos, std::vector<T>& weights);
61
63 BlockLattice3D<T,DESCRIPTOR> & block, HemoCellParticle & particle)
64{
65 //Clean current
66 particle.kernelWeights.clear();
67 particle.kernelWeights.reserve(8);
68 particle.kernelLocations.clear();
69 #ifdef INTERIOR_VISCOSITY
70 particle.kernelCoordinates.clear();
71 particle.kernelCoordinates.reserve(8);
72 #endif
73
74 // Fixed kernel size
75 const plint x0=-1, x1=2; //const for nice loop unrolling
76
77 //Coordinates are relative
78 const Dot3D tmpDot = block.getLocation();
79 const hemo::Array<plint,3> relLoc = {tmpDot.x, tmpDot.y, tmpDot.z};
80
81 //Get position, relative
82 const hemo::Array<T,3> position_tmp = particle.sv.position;
83 const hemo::Array<T,3> position = {position_tmp[0] -relLoc[0], position_tmp[1]-relLoc[1],position_tmp[2]-relLoc[2]};
84
85 //Get our reference node (0,0)
86 const hemo::Array<plint,3> center({plint(position[0] + 0.5), plint(position[1] + 0.5), plint(position[2] + 0.5)});
87
88 //Boundingbox of lattice
89 const Box3D boundingBox = block.getBoundingBox();
90
91 //Prealloc is better than JItalloc
92 hemo::Array<plint,3> posInBlock;
93
94 T phi[3];
95 T weight;
96 T total_weight = 0;
97
98
99 for (int dx = x0; dx < x1; ++dx) {
100 for (int dy = x0; dy < x1; ++dy) {
101 for (int dz = x0; dz < x1; ++dz) {
102 posInBlock = {center[0] + dx, center[1] + dy, center[2] + dz};
103
104 //Sanity checks, skip if outside domain or boundary
105 if (!contained_sane(posInBlock,boundingBox)) {
106 continue;
107 }
108
109 phi[0] = (position[0] - posInBlock[0]); //Get absolute distance
110 phi[1] = (position[1] - posInBlock[1]);
111 phi[2] = (position[2] - posInBlock[2]);
112 weight = phi2(phi[0]) * phi2(phi[1]) * phi2(phi[2]);
113
114 if (weight == 0.0){
115 continue;
116 }
117
118 if (block.get(posInBlock[0],posInBlock[1],posInBlock[2]).getDynamics().isBoundary()) {
119 continue;
120 }
121
122 total_weight+=weight;
123
124 particle.kernelWeights.push_back(weight);
125 particle.kernelLocations.push_back(&block.get(posInBlock[0],posInBlock[1],posInBlock[2]));
126
127 #ifdef INTERIOR_VISCOSITY
128 // Or create a clone of the method?
129 particle.kernelCoordinates.push_back({posInBlock[0],posInBlock[1],posInBlock[2]});
130 #endif
131 }
132 }
133 }
134 const T weight_coeff = 1.0 / total_weight;
135 for(T & weight_ : particle.kernelWeights) { //Normalize weight to 1
136 weight_ *= weight_coeff;
137 }
138}
139
140template<typename T, template<typename U> class Descriptor>
142
143 BlockLattice3D<T,Descriptor> const& block, hemo::Array<T,3> const& position,
144 std::vector<Dot3D>& cellPos, std::vector<T>& weights);
145
147 BlockLattice3D<double,DESCRIPTOR> const& block, hemo::Array<double,3> const& position,
148 std::vector<Dot3D>& cellPos, std::vector<double>& weights);
149
150template<typename T, template<typename U> class Descriptor>
152 BlockLattice3D<T,Descriptor> const& block, hemo::Array<T,3> const& position,
153 std::vector<Dot3D>& cellPos, std::vector<T>& weights);
154
155/*
156 * In case one of the interpolating boundary nodes is a boundary,
157 * the force is spread to the rest of the nodes
158 * */
159template<typename T, template<typename U> class Descriptor>
160void curateInterpolationCoefficients (BlockLattice3D<T,Descriptor>& fluid,
161 std::vector<Dot3D>& cellPos, std::vector<T>& weights) ;
162
163
164}
165#endif // IMMERSEDBOUNDARYMETHOD_3D_H
166
Definition hemoCellParticle.h:40
std::vector< T > kernelWeights
Definition hemoCellParticle.h:76
serializeValues_t sv
Definition hemoCellParticle.h:65
std::vector< plb::Cell< T, DESCRIPTOR > * > kernelLocations
Definition hemoCellParticle.h:75
double T
Definition constant_defaults.h:118
long int plint
Definition constant_defaults.h:127
Definition config.cpp:34
void curateInterpolationCoefficients(BlockLattice3D< T, Descriptor > &fluid, std::vector< Dot3D > &cellPos, std::vector< T > &weights)
T phi4(T x)
bool contained_sane(hemo::Array< plint, 3 > const &x, Box3D const &box)
Decide if a Lagrangian point is contained in 3D box, boundaries exclusive.
Definition immersedBoundaryMethod.h:32
void interpolationCoefficientsPhi3(BlockLattice3D< T, Descriptor > const &block, hemo::Array< T, 3 > const &position, std::vector< Dot3D > &cellPos, std::vector< T > &weights)
void interpolationCoefficientsPhi4(BlockLattice3D< double, DESCRIPTOR > const &block, hemo::Array< double, 3 > const &position, std::vector< Dot3D > &cellPos, std::vector< double > &weights)
void interpolationCoefficientsPhi2(BlockLattice3D< T, DESCRIPTOR > &block, HemoCellParticle &particle)
Definition immersedBoundaryMethod.h:62
T phi3(T x)
T phi2(T x)
Definition immersedBoundaryMethod.h:37
void interpolationCoefficients(BlockLattice3D< T, Descriptor > const &block, hemo::Array< T, 3 > const &position, std::vector< Dot3D > &cellPos, std::vector< T > &weights)
void interpolationCoefficientsPhi4c(BlockLattice3D< T, Descriptor > const &block, hemo::Array< T, 3 > const &position, std::vector< Dot3D > &cellPos, std::vector< T > &weights)
T phi4c(T x)
void interpolationCoefficientsPhi1(BlockLattice3D< T, Descriptor > const &block, hemo::Array< T, 3 > const &position, std::vector< Dot3D > &cellPos, std::vector< T > &weights)
Definition array.h:39
hemo::Array< T, 3 > position
Definition hemoCellParticle.h:47