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 <cmath>
28#include <vector>
29
30namespace hemo {
31
33inline bool contained_sane(hemo::Array<plint, 3> const & x, plb::Box3D const & box) {
34 return x[0] >= box.x0 && x[0] <= box.x1 && x[1] >= box.y0 && x[1] <= box.y1 && x[2] >= box.z0 && x[2] <= box.z1;
35}
36inline T phi2(T x) {
37 x = fabs(x);
38 x = 1.0 - x;
39 return std::max(x, (T)0.0);
40}
41
42template <typename T>
43T phi3(T x);
44
45template <typename T>
46T phi4(T x);
47
48template <typename T>
50
51template <typename T, template <typename U> class Descriptor>
52void interpolationCoefficients(plb::BlockLattice3D<T, Descriptor> const & block, hemo::Array<T, 3> const & position,
53 std::vector<plb::Dot3D> & cellPos, std::vector<T> & weights);
54
55template <typename T, template <typename U> class Descriptor>
56void interpolationCoefficientsPhi1(plb::BlockLattice3D<T, Descriptor> const & block, hemo::Array<T, 3> const & position,
57 std::vector<plb::Dot3D> & cellPos, std::vector<T> & weights);
58
73inline void interpolationCoefficientsPhi2(plb::BlockLattice3D<T, DESCRIPTOR> & block, HemoCellParticle & particle) {
74 particle.kernelWeights.clear();
75 particle.kernelWeights.reserve(8);
76 particle.kernelLocations.clear();
77#ifdef INTERIOR_VISCOSITY
78 particle.kernelCoordinates.clear();
79 particle.kernelCoordinates.reserve(8);
80#endif
81
82 const plb::Dot3D location = block.getLocation();
83 const plb::Box3D boundingBox = block.getBoundingBox();
84 const plint lower[3] = {boundingBox.x0, boundingBox.y0, boundingBox.z0};
85 const plint upper[3] = {boundingBox.x1, boundingBox.y1, boundingBox.z1};
86
87 // Position relative to the block.
88 const T position[3] = {particle.sv.position[0] - location.x, particle.sv.position[1] - location.y,
89 particle.sv.position[2] - location.z};
90
91 // Candidate nodes and their one-dimensional weights per axis.
92 plint node[3][2];
93 T weight1D[3][2];
94 bool inside[3][2];
95 for (int d = 0; d < 3; ++d) {
96 const plint base = plint(std::floor(position[d]));
97 for (int i = 0; i < 2; ++i) {
98 node[d][i] = base + i;
99 weight1D[d][i] = phi2(position[d] - node[d][i]);
100 inside[d][i] = node[d][i] >= lower[d] && node[d][i] <= upper[d];
101 }
102 }
103
104 T total_weight = 0;
105 for (int i = 0; i < 2; ++i) {
106 if (!inside[0][i]) { continue; }
107 for (int j = 0; j < 2; ++j) {
108 if (!inside[1][j]) { continue; }
109 for (int k = 0; k < 2; ++k) {
110 if (!inside[2][k]) { continue; }
111 const T weight = weight1D[0][i] * weight1D[1][j] * weight1D[2][k];
112 if (weight == 0.0) { continue; }
113
114 plb::Cell<T, DESCRIPTOR> & cell = block.get(node[0][i], node[1][j], node[2][k]);
115 if (cell.getDynamics().isBoundary()) { continue; }
116
117 total_weight += weight;
118 particle.kernelWeights.push_back(weight);
119 particle.kernelLocations.push_back(&cell);
120#ifdef INTERIOR_VISCOSITY
121 particle.kernelCoordinates.push_back({node[0][i], node[1][j], node[2][k]});
122#endif
123 }
124 }
125 }
126 const T weight_coeff = 1.0 / total_weight;
127 for (T & weight_ : particle.kernelWeights) { //Normalize weight to 1
128 weight_ *= weight_coeff;
129 }
130}
131
132template <typename T, template <typename U> class Descriptor>
134
135 plb::BlockLattice3D<T, Descriptor> const & block, hemo::Array<T, 3> const & position,
136 std::vector<plb::Dot3D> & cellPos, std::vector<T> & weights);
137
138void interpolationCoefficientsPhi4(plb::BlockLattice3D<double, DESCRIPTOR> const & block,
139 hemo::Array<double, 3> const & position, std::vector<plb::Dot3D> & cellPos,
140 std::vector<double> & weights);
141
142template <typename T, template <typename U> class Descriptor>
143void interpolationCoefficientsPhi4c(plb::BlockLattice3D<T, Descriptor> const & block,
144 hemo::Array<T, 3> const & position, std::vector<plb::Dot3D> & cellPos,
145 std::vector<T> & weights);
146
147/*
148 * In case one of the interpolating boundary nodes is a boundary,
149 * the force is spread to the rest of the nodes
150 * */
151template <typename T, template <typename U> class Descriptor>
152void curateInterpolationCoefficients(plb::BlockLattice3D<T, Descriptor> & fluid, std::vector<plb::Dot3D> & cellPos,
153 std::vector<T> & weights);
154}
155#endif // IMMERSEDBOUNDARYMETHOD_3D_H
Definition hemoCellParticle.h:44
std::vector< T > kernelWeights
Definition hemoCellParticle.h:79
serializeValues_t sv
Definition hemoCellParticle.h:68
std::vector< plb::Cell< T, DESCRIPTOR > * > kernelLocations
Definition hemoCellParticle.h:78
double T
Definition constant_defaults.h:137
long int plint
Definition constant_defaults.h:149
Definition cell.py:1
Definition config.cpp:37
void interpolationCoefficientsPhi4c(plb::BlockLattice3D< T, Descriptor > const &block, hemo::Array< T, 3 > const &position, std::vector< plb::Dot3D > &cellPos, std::vector< T > &weights)
void curateInterpolationCoefficients(plb::BlockLattice3D< T, Descriptor > &fluid, std::vector< plb::Dot3D > &cellPos, std::vector< T > &weights)
void interpolationCoefficientsPhi4(plb::BlockLattice3D< double, DESCRIPTOR > const &block, hemo::Array< double, 3 > const &position, std::vector< plb::Dot3D > &cellPos, std::vector< double > &weights)
T phi4(T x)
void interpolationCoefficientsPhi3(plb::BlockLattice3D< T, Descriptor > const &block, hemo::Array< T, 3 > const &position, std::vector< plb::Dot3D > &cellPos, std::vector< T > &weights)
bool contained_sane(hemo::Array< plint, 3 > const &x, plb::Box3D const &box)
Decide if a Lagrangian point is contained in 3D box, boundaries exclusive.
Definition immersedBoundaryMethod.h:33
void interpolationCoefficientsPhi1(plb::BlockLattice3D< T, Descriptor > const &block, hemo::Array< T, 3 > const &position, std::vector< plb::Dot3D > &cellPos, std::vector< T > &weights)
T phi3(T x)
void interpolationCoefficientsPhi2(plb::BlockLattice3D< T, DESCRIPTOR > &block, HemoCellParticle &particle)
Compute the IBM kernel of a particle with the 2-point hat function phi2 (trilinear weights): kernelLo...
Definition immersedBoundaryMethod.h:73
T phi2(T x)
Definition immersedBoundaryMethod.h:36
void interpolationCoefficients(plb::BlockLattice3D< T, Descriptor > const &block, hemo::Array< T, 3 > const &position, std::vector< plb::Dot3D > &cellPos, std::vector< T > &weights)
T phi4c(T x)
Definition array.h:40
hemo::Array< T, 3 > position
Definition hemoCellParticle.h:50