25#include "communication.hpp"
27#include "system/System.hpp"
31#include <boost/mpi/collectives/all_reduce.hpp>
32#include <boost/range/algorithm/find_if.hpp>
43 if (VolumeInitDone && !BoundariesFound) {
47 calc_volume_force(cs);
52 auto const &bonded_ias = *
get_system().bonded_ias;
55 if (not BoundariesFound) {
56 BoundariesFound = std::ranges::any_of(
57 std::views::elements<1>(bonded_ias), [](
auto const &handle) {
58 return std::holds_alternative<IBMVolCons>(*handle);
62 if (!VolumeInitDone && BoundariesFound) {
68 for (
auto &handle : std::views::elements<1>(bonded_ias)) {
69 if (
auto *v = std::get_if<IBMVolCons>(handle.get())) {
73 BoundariesFound =
true;
74 if (v->volRef == 0.) {
75 v->volRef = VolumesCurrent[v->softID];
80 VolumeInitDone =
true;
87 auto const it = boost::find_if(p1.
bonds(), [&](
auto const &bond) ->
bool {
88 return std::holds_alternative<IBMVolCons>(*bonded_ias.at(bond.bond_id()));
91 return (it != p1.
bonds().end())
92 ? std::get_if<IBMVolCons>(bonded_ias.
at(it->bond_id()).get())
101 if (!BoundariesFound)
105 auto const &bonded_ias = *
get_system().bonded_ias;
108 std::vector<double> tempVol(VolumesCurrent.size());
111 cs.
bond_loop([&tempVol, &box_geo, &bonded_ias](
112 Particle &p1,
int bond_id, std::span<Particle *> partners) {
115 if (vol_cons_params &&
116 std::holds_alternative<IBMTriel>(*bonded_ias.at(bond_id).get())) {
125 auto const x1 = box_geo.unfolded_position(p1.
pos(), p1.
image_box());
126 auto const x2 = x1 + box_geo.get_mi_vector(p2.
pos(), x1);
127 auto const x3 = x1 + box_geo.get_mi_vector(p3.
pos(), x1);
139 const double v321 = x3[0] * x2[1] * x1[2];
140 const double v231 = x2[0] * x3[1] * x1[2];
141 const double v312 = x3[0] * x1[1] * x2[2];
142 const double v132 = x1[0] * x3[1] * x2[2];
143 const double v213 = x2[0] * x1[1] * x3[2];
144 const double v123 = x1[0] * x2[1] * x3[2];
146 tempVol[vol_cons_params->softID] +=
147 1.0 / 6.0 * (-v321 + v231 + v312 - v132 - v213 + v123);
153 boost::mpi::all_reduce(
comm_cart, tempVol.data(),
154 static_cast<int>(tempVol.size()),
155 VolumesCurrent.data(), std::plus<double>());
159void ImmersedBoundaries::calc_volume_force(
CellStructure &cs) {
160 if (!BoundariesFound)
164 auto const &bonded_ias = *
get_system().bonded_ias;
167 std::span<Particle *> partners) {
168 if (std::holds_alternative<IBMTriel>(*bonded_ias.at(bond_id).get())) {
173 auto const vol_cons_params = vol_cons_parameters(bonded_ias, p1);
174 if (not vol_cons_params)
177 auto const current_volume =
178 VolumesCurrent[static_cast<unsigned int>(vol_cons_params->softID)];
182 Particle &p2 = *partners[0];
183 Particle &p3 = *partners[1];
188 auto const x1 = box_geo.unfolded_position(p1.pos(), p1.image_box());
192 auto const a12 = box_geo.get_mi_vector(p2.pos(), x1);
193 auto const a13 = box_geo.get_mi_vector(p3.pos(), x1);
197 auto const n = vector_product(a12, a13);
198 const double ln = n.norm();
199 const double A = 0.5 * ln;
200 const double fact = vol_cons_params->kappaV *
201 (current_volume - vol_cons_params->volRef) /
204 auto const nHat = n / ln;
205 auto const force = -fact * A * nHat;
216 auto const new_size = bond.
softID + 1u;
217 if (new_size > VolumesCurrent.size()) {
218 VolumesCurrent.resize(new_size);
static IBMVolCons const * vol_cons_parameters(BondedInteractionsMap const &bonded_ias, Particle const &p1)
Data structures for bonded interactions.
container for bonded interactions.
mapped_type const & at(key_type const &key) const
Describes a cell structure / cell system.
void bond_loop(BondKernel const &bond_kernel)
Bonded pair loop.
void volume_conservation(CellStructure &cs)
Calculate volumes, volume force and add it to each virtual particle.
void init_volume_conservation(CellStructure &cs)
Initialize volume conservation.
void register_softID(IBMVolCons &bond)
boost::mpi::communicator comm_cart
The communicator.
Parameters for IBM volume conservation bond.
void set_volumes_view(std::vector< double > const &volumes)
unsigned int softID
ID of the large soft particle to which this node belongs.
Struct holding all information for one particle.
auto const & image_box() const
auto const & bonds() const