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>
27
28#include <boost/mpi/collectives/all_reduce.hpp>
29#include <boost/optional.hpp>
30#include <boost/serialization/optional.hpp>
31
32#include <stdexcept>
33
35 auto &cell_structure = *System::get_system().cell_structure;
36 auto *p = cell_structure.get_local_particle(pid);
37 boost::optional<Particle> opt_part{boost::none};
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 [](boost::optional<Particle> const &acc,
44 boost::optional<Particle> const &item) {
45 if (acc) {
46 return acc;
47 }
48 return item;
49 });
50 if (opt_part)
51 return opt_part.get().pos();
52 throw std::runtime_error("Immersed Boundary: Particle not found");
53}
Vector implementation and trait types for boost qvm interoperability.
std::shared_ptr< CellStructure > cell_structure
boost::mpi::communicator comm_cart
The communicator.
Utils::Vector3d get_ibm_particle_position(int pid)
Returns the position of a given particle.
System & get_system()