ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
ibm_common.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "ibm_common.hpp"
21
23#include "communication.hpp"
24#include "system/System.hpp"
25
26#include <utils/Vector.hpp>
28
29#include <boost/mpi/collectives/all_reduce.hpp>
30
31#include <optional>
32#include <stdexcept>
33
35 int pid) {
36 auto *p = cell_structure.get_local_particle(pid);
37 std::optional<Particle> opt_part{std::nullopt};
38
39 if (p and not p->is_ghost()) {
40 opt_part = *p;
41 }
42 opt_part = boost::mpi::all_reduce(comm_cart, opt_part,
43 [](std::optional<Particle> const &acc,
44 std::optional<Particle> const &item) {
45 if (acc) {
46 return acc;
47 }
48 return item;
49 });
50 if (opt_part)
51 return opt_part.value().pos();
52 throw std::runtime_error("Immersed Boundary: Particle not found");
53}
Vector implementation and trait types for boost qvm interoperability.
boost::mpi::communicator comm_cart
The communicator.
Utils::Vector3d get_ibm_particle_position(CellStructure const &cell_structure, int pid)
Returns the position of a given particle.
Describes a cell structure / cell system.
Particle * get_local_particle(int id)
Get a local particle by id.
auto const & pos() const
Definition Particle.hpp:431