Skip to content

Commit

Permalink
lbboundaries: initialization logic for cpu.
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiSzuttor committed Feb 18, 2020
1 parent 9aa17ad commit 0b8eb47
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
47 changes: 21 additions & 26 deletions src/core/grid_based_algorithms/lb_boundaries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*
*/


#include "grid_based_algorithms/lb_boundaries.hpp"

#include "communication.hpp"
Expand Down Expand Up @@ -116,8 +115,8 @@ void ek_init_boundaries() {
std::vector<std::shared_ptr<LBBoundary>> boundaries;
std::copy_if(lbboundaries.begin(), lbboundaries.end(),
std::back_inserter(boundaries), [&pos](auto const lbb) {
return not lbb->shape().is_inside(pos);
});
return not lbb->shape().is_inside(pos);
});
for (auto lbb : boundaries) {
if ((*lbb).charge_density() != 0.0f) {
node_charged = true;
Expand All @@ -126,7 +125,7 @@ void ek_init_boundaries() {
(*lbb).set_net_charge(
(*lbb).net_charge() +
(*lbb).charge_density() * ek_parameters.agrid *
ek_parameters.agrid * ek_parameters.agrid);
ek_parameters.agrid * ek_parameters.agrid);
}
}
if (not boundaries.empty()) {
Expand All @@ -137,7 +136,7 @@ void ek_init_boundaries() {
if (wallcharge_species != -1) {
if (node_charged)
host_wallcharge_species_density[ek_parameters.dim_y *
ek_parameters.dim_x * z +
ek_parameters.dim_x * z +
ek_parameters.dim_x * y + x] =
node_wallcharge / ek_parameters.valency[wallcharge_species];
}
Expand Down Expand Up @@ -184,7 +183,7 @@ void lb_init_boundaries() {
host_boundary_node_list[number_of_boundnodes] =
x + lbpar_gpu.dim_x * y + lbpar_gpu.dim_x * lbpar_gpu.dim_y * z;
auto const boundary_number =
std::distance(boundary, lbboundaries.rend());
std::distance(lbboundaries.begin(), boundary.base()) - 1;
host_boundary_index_list[number_of_boundnodes] =
boundary_number + 1;
number_of_boundnodes++;
Expand Down Expand Up @@ -215,14 +214,7 @@ void lb_init_boundaries() {
#endif /* defined ( CUDA) && defined (LB_BOUNDARIES_GPU) */
} else if (lattice_switch == ActiveLB::CPU) {
#if defined(LB_BOUNDARIES)
Utils::Vector3i offset;

auto const node_pos = calc_node_pos(comm_cart);

const auto lblattice = lb_lbfluid_get_lattice();
offset[0] = node_pos[0] * lblattice.grid[0];
offset[1] = node_pos[1] * lblattice.grid[1];
offset[2] = node_pos[2] * lblattice.grid[2];

for (int n = 0; n < lblattice.halo_grid_volume; n++) {
lbfields.at(n).boundary = 0;
Expand All @@ -231,6 +223,12 @@ void lb_init_boundaries() {
if (lblattice.halo_grid_volume == 0)
return;

auto const node_pos = calc_node_pos(comm_cart);
Utils::Vector3i offset;
offset[0] = node_pos[0] * lblattice.grid[0];
offset[1] = node_pos[1] * lblattice.grid[1];
offset[2] = node_pos[2] * lblattice.grid[2];

for (int z = 0; z < lblattice.grid[2] + 2; z++) {
for (int y = 0; y < lblattice.grid[1] + 2; y++) {
for (int x = 0; x < lblattice.grid[0] + 2; x++) {
Expand All @@ -239,22 +237,19 @@ void lb_init_boundaries() {
pos[1] = (offset[1] + (y - 0.5)) * lblattice.agrid;
pos[2] = (offset[2] + (z - 0.5)) * lblattice.agrid;

std::vector<bool> inside_boundaries;
for (auto it = lbboundaries.begin(); it != lbboundaries.end(); ++it) {
auto const inside_boundary = not(**it).shape().is_inside(pos);
inside_boundaries.push_back(inside_boundary);
}
auto const it =
std::find_if(inside_boundaries.begin(), inside_boundaries.end(),
[](bool b) { return b; });
if (it != inside_boundaries.end()) {
auto const boundary =
std::find_if(lbboundaries.rbegin(), lbboundaries.rend(),
[&pos](auto const lbb) {
return not lbb->shape().is_inside(pos);
});
if (boundary != lbboundaries.rend()) {
auto const index = get_linear_index(x, y, z, lblattice.halo_grid);
auto &node = lbfields[index];
auto const the_boundary =
std::distance(inside_boundaries.begin(), it);
node.boundary = the_boundary + 1;
auto const boundary_number =
std::distance(lbboundaries.begin(), boundary.base()) - 1;
node.boundary = boundary_number + 1;
node.slip_velocity =
LBBoundaries::lbboundaries[the_boundary]->velocity() *
(*boundary)->velocity() *
(lb_lbfluid_get_tau() / lb_lbfluid_get_agrid());
} else {
lbfields[get_linear_index(x, y, z, lblattice.halo_grid)].boundary =
Expand Down
5 changes: 2 additions & 3 deletions src/core/shapes/ShapeUnion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ShapeUnion : public Shape {
* @param[out] vec Distance vector.
*/
void calculate_dist(Utils::Vector3d const &pos, double &dist,
Utils::Vector3d &vec) const {
Utils::Vector3d &vec) const override {
auto dist_compare = [&pos](std::pair<double, Utils::Vector3d> const &res,
std::shared_ptr<Shapes::Shape> const &s) {
double d;
Expand All @@ -56,9 +56,8 @@ class ShapeUnion : public Shape {
"Distance to ShapeUnion not well-defined for given position!");
if (d < res.first) {
return std::make_pair(d, vec);
} else {
return res;
}
return res;
};
std::tie(dist, vec) =
std::accumulate(m_shapes.begin(), m_shapes.end(),
Expand Down

0 comments on commit 0b8eb47

Please sign in to comment.