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>
44 if (VolumeInitDone && !BoundariesFound) {
48 calc_volume_force(cs);
53 auto const &bonded_ias = *
get_system().bonded_ias;
56 if (not BoundariesFound) {
57 BoundariesFound = std::ranges::any_of(
58 std::views::elements<1>(bonded_ias), [](
auto const &handle) {
59 return std::holds_alternative<IBMVolCons>(*handle);
63 if (!VolumeInitDone && BoundariesFound) {
69 for (
auto &handle : std::views::elements<1>(bonded_ias)) {
70 if (
auto *v = std::get_if<IBMVolCons>(handle.get())) {
74 BoundariesFound =
true;
75 if (v->volRef == 0.) {
76 v->volRef = VolumesCurrent[v->softID];
81 VolumeInitDone =
true;
88 auto const it = boost::find_if(p1.
bonds(), [&](
auto const &bond) ->
bool {
89 return std::holds_alternative<IBMVolCons>(*bonded_ias.at(bond.bond_id()));
92 return (it != p1.
bonds().end())
93 ? std::get_if<IBMVolCons>(bonded_ias.
at(it->bond_id()).get())
102 if (!BoundariesFound)
106 auto const &bonded_ias = *
get_system().bonded_ias;
109 std::vector<double> tempVol(VolumesCurrent.size());
112 cs.
bond_loop([&tempVol, &box_geo, &bonded_ias](
113 Particle &p1,
int bond_id, std::span<Particle *> partners) {
116 if (vol_cons_params &&
117 std::holds_alternative<IBMTriel>(*bonded_ias.at(bond_id).get())) {
126 auto const x1 = box_geo.unfolded_position(p1.
pos(), p1.
image_box());
127 auto const x2 = x1 + box_geo.get_mi_vector(p2.
pos(), x1);
128 auto const x3 = x1 + box_geo.get_mi_vector(p3.
pos(), x1);
140 const double v321 = x3[0] * x2[1] * x1[2];
141 const double v231 = x2[0] * x3[1] * x1[2];
142 const double v312 = x3[0] * x1[1] * x2[2];
143 const double v132 = x1[0] * x3[1] * x2[2];
144 const double v213 = x2[0] * x1[1] * x3[2];
145 const double v123 = x1[0] * x2[1] * x3[2];
147 tempVol[vol_cons_params->softID] +=
148 1.0 / 6.0 * (-v321 + v231 + v312 - v132 - v213 + v123);
154 boost::mpi::all_reduce(
comm_cart, tempVol.data(),
155 static_cast<int>(tempVol.size()),
156 VolumesCurrent.data(), std::plus<double>());
160void ImmersedBoundaries::calc_volume_force(
CellStructure &cs) {
161 if (!BoundariesFound)
165 auto const &bonded_ias = *
get_system().bonded_ias;
168 std::span<Particle *> partners) {
169 if (std::holds_alternative<IBMTriel>(*bonded_ias.at(bond_id).get())) {
174 auto const vol_cons_params = vol_cons_parameters(bonded_ias, p1);
175 if (not vol_cons_params)
178 auto const current_volume =
179 VolumesCurrent[static_cast<unsigned int>(vol_cons_params->softID)];
183 Particle &p2 = *partners[0];
184 Particle &p3 = *partners[1];
189 auto const x1 = box_geo.unfolded_position(p1.pos(), p1.image_box());
193 auto const a12 = box_geo.get_mi_vector(p2.pos(), x1);
194 auto const a13 = box_geo.get_mi_vector(p3.pos(), x1);
198 auto const n = vector_product(a12, a13);
199 const double ln = n.norm();
200 const double A = 0.5 * ln;
201 const double fact = vol_cons_params->kappaV *
202 (current_volume - vol_cons_params->volRef) /
205 auto const nHat = n / ln;
206 auto const force = -fact * A * nHat;
217 auto const new_size = bond.
softID + 1u;
218 if (new_size > VolumesCurrent.size()) {
219 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 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