Skip to content

Commit b7a4c5e

Browse files
committed
core: remove mixing due to reapplication of BC
1 parent da33cf2 commit b7a4c5e

File tree

4 files changed

+25
-41
lines changed

4 files changed

+25
-41
lines changed

include/fiber.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class Fiber {
135135
}
136136

137137

138-
Eigen::VectorXd matvec(VectorRef x, MatrixRef v) const;
138+
Eigen::VectorXd matvec(VectorRef x) const;
139139
void update_preconditioner();
140140
void update_force_operator();
141141
void update_boundary_conditions(Periphery &shell);
@@ -217,7 +217,7 @@ class FiberContainer {
217217
const Eigen::MatrixXd &get_local_node_positions() const { return r_fib_local_; };
218218
Eigen::VectorXd get_RHS() const;
219219
Eigen::MatrixXd flow(const MatrixRef &r_trg, const MatrixRef &forces, double eta, bool subtract_self) const;
220-
Eigen::VectorXd matvec(VectorRef &x_all, MatrixRef &v_fib) const;
220+
Eigen::VectorXd matvec(VectorRef &x_all) const;
221221
Eigen::MatrixXd apply_fiber_force(VectorRef &x_all) const;
222222
Eigen::VectorXd apply_preconditioner(VectorRef &x_all) const;
223223

src/core/fiber.cpp

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -209,31 +209,14 @@ void Fiber::update_RHS(double dt, MatrixRef &flow, MatrixRef &f_external) {
209209
RHS_.segment(3 * np, np) = -penalty_param_ * VectorXd::Ones(np);
210210

211211
if (flow.size()) {
212-
const int bc_start_i = 4 * np - 14;
213-
MatrixXd xsDs = (D_1.array().colwise() * xs_.row(0).transpose().array()).transpose();
214-
MatrixXd ysDs = (D_1.array().colwise() * xs_.row(1).transpose().array()).transpose();
215-
MatrixXd zsDs = (D_1.array().colwise() * xs_.row(2).transpose().array()).transpose();
216-
217-
VectorXd vT = VectorXd(np * 4);
218-
VectorXd v_x = flow.row(0).transpose();
219-
VectorXd v_y = flow.row(1).transpose();
220-
VectorXd v_z = flow.row(2).transpose();
221-
222-
vT.segment(0 * np, np) = v_x;
223-
vT.segment(1 * np, np) = v_y;
224-
vT.segment(2 * np, np) = v_z;
225-
vT.segment(3 * np, np) = xsDs * v_x + ysDs * v_y + zsDs * v_z;
226-
227-
VectorXd vT_in = VectorXd::Zero(4 * np);
228-
vT_in.segment(0, bc_start_i) = mats.P_downsample_bc * vT;
229-
230-
VectorXd xs_vT = VectorXd::Zero(4 * np); // from attachments
231-
const int minus_node = 0;
232-
233-
// FIXME: Does this imply always having velocity boundary conditions?
234-
xs_vT(bc_start_i + 3) = flow.col(minus_node).dot(xs_.col(minus_node));
235-
236-
RHS_ += -vT + vT_in - xs_vT;
212+
RHS_.segment(0 * np, np) += flow.row(0);
213+
RHS_.segment(1 * np, np) += flow.row(1);
214+
RHS_.segment(2 * np, np) += flow.row(2);
215+
216+
RHS_.segment(3 * np, np) += (xs_x.transpose() * (flow.row(0) * D_1.matrix()).array() +
217+
xs_y.transpose() * (flow.row(1) * D_1.matrix()).array() +
218+
xs_z.transpose() * (flow.row(2) * D_1.matrix()).array())
219+
.matrix();
237220
}
238221
if (f_external.size()) {
239222
ArrayXXd fs = f_external * D_1;
@@ -278,9 +261,7 @@ void Fiber::update_RHS(double dt, MatrixRef &flow, MatrixRef &f_external) {
278261
}
279262
}
280263

281-
VectorXd Fiber::matvec(VectorRef x, MatrixRef v) const {
282-
return A_ * x;
283-
}
264+
VectorXd Fiber::matvec(VectorRef x) const { return A_ * x; }
284265

285266
/// @brief Calculate the force operator cache variable
286267
///

src/core/fiber_container.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ VectorXd FiberContainer::apply_preconditioner(VectorRef &x_all) const {
7171
return y;
7272
}
7373

74-
VectorXd FiberContainer::matvec(VectorRef &x_all, MatrixRef &v_fib) const {
74+
VectorXd FiberContainer::matvec(VectorRef &x_all) const {
7575
VectorXd res = VectorXd::Zero(get_local_solution_size());
7676

7777
size_t offset = 0;
7878
int i_fib = 0;
7979
for (const auto &fib : *this) {
8080
const int np = fib.n_nodes_;
81-
res.segment(offset, 4 * np) = fib.matvec(x_all.segment(offset, 4 * np), v_fib.block(0, i_fib, 3, np));
81+
res.segment(offset, 4 * np) = fib.matvec(x_all.segment(offset, 4 * np));
8282

8383
i_fib++;
8484
offset += 4 * np;

src/core/system.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ BackgroundSource bs_; ///< Background flow
3232

3333
std::unique_ptr<Periphery> shell_; ///< Periphery
3434
Eigen::VectorXd curr_solution_; ///< Current MPI-rank local solution vector
35-
Eigen::MatrixXd v_fibers_; ///< Current MPI-rank local velocity on fibers
3635

3736
FiberContainer fc_bak_; ///< Copy of fibers for timestep reversion
3837
int rank_; ///< MPI rank
@@ -196,7 +195,7 @@ Eigen::VectorXd apply_matvec(VectorRef &x) {
196195
const FiberContainer &fc = fc_;
197196

198197
auto [x_fibers] = get_solution_maps(x.data());
199-
return fc.matvec(x_fibers, v_fibers_);
198+
return fc.matvec(x_fibers);
200199
}
201200

202201
/// @brief Evaluate the velocity at a list of target points
@@ -271,16 +270,20 @@ void prep_state_for_solver() {
271270
v_all += psc_.flow(r_all, params_.eta, properties.time);
272271
v_all += bs_.flow(r_all, params_.eta);
273272

274-
CVectorMap shell_velocities_flat(v_all.data() + 3 * fib_node_count, 3 * shell_node_count);
275-
shell_->solution_vec_ = shell_->M_inv_ * shell_velocities_flat;
276-
v_fibers_ = shell_->flow(fc_.get_local_node_positions(), shell_->solution_vec_, params_.eta);
273+
MatrixXd v_shell2fib;
274+
if (shell_->is_active()) {
275+
CVectorMap shell_velocities_flat(v_all.data() + 3 * fib_node_count, 3 * shell_node_count);
276+
shell_->solution_vec_ = shell_->M_inv_ * shell_velocities_flat;
277+
v_shell2fib = shell_->flow(fc_.get_local_node_positions(), shell_->solution_vec_, params_.eta);
278+
}
279+
else {
280+
v_shell2fib = MatrixXd::Zero(3, fib_node_count);
281+
}
277282

278283
MatrixXd external_force_fibers = MatrixXd::Zero(3, fib_node_count);
279-
fc_.update_RHS(properties.dt, v_fibers_, external_force_fibers);
284+
fc_.update_RHS(properties.dt, v_shell2fib, external_force_fibers);
280285
fc_.update_boundary_conditions(*shell_);
281-
fc_.apply_bc_rectangular(properties.dt, v_fibers_, external_force_fibers);
282-
283-
v_fibers_ += v_all.block(0, 0, 3, fib_node_count);
286+
fc_.apply_bc_rectangular(properties.dt, v_shell2fib, force_fibers);
284287
}
285288

286289

0 commit comments

Comments
 (0)