35 [[maybe_unused]]
const double t, [[maybe_unused]]
const double dt,
36 [[maybe_unused]] std::vector<GlobalVector*>
const& x,
37 [[maybe_unused]] std::vector<GlobalVector*>
const& x_prev,
38 [[maybe_unused]]
int const process_id,
48 using RawMatrixType = Eigen::SparseMatrix<double, Eigen::RowMajor>;
49 auto& K_raw = K.getRawMatrix();
51 for (
int k = 0; k < K_raw.outerSize(); ++k)
53 for (RawMatrixType::InnerIterator it(K_raw, k); it; ++it)
55 if (it.row() != it.col())
57 double const kij = it.value();
58 double const kji = K.get(it.col(), it.row());
59 double const dij = std::max({-kij, 0., -kji});
60 D->setValue(it.row(), it.col(), dij);
64 auto& D_raw = D->getRawMatrix();
65 D_raw -= (D_raw * Eigen::VectorXd::Ones(D_raw.cols())).eval().asDiagonal();
68 for (
int k = 0; k < D_raw.outerSize(); ++k)
70 for (RawMatrixType::InnerIterator it(D_raw, k); it; ++it)
72 double const dij = it.value();
73 double const xj = x[process_id]->get(it.col());
74 double const xi = x[process_id]->get(it.row());
75 double const fij = -dij * (xj - xi);
76 F->setValue(it.row(), it.col(), fij);
80 auto& M_raw = M.getRawMatrix();
81 for (
int k = 0; k < M_raw.outerSize(); ++k)
83 for (RawMatrixType::InnerIterator it(M_raw, k); it; ++it)
85 double const mij = it.value();
86 double const xdotj = (x[process_id]->get(it.col()) -
87 x_prev[process_id]->get(it.col())) /
89 double const xdoti = (x[process_id]->get(it.row()) -
90 x_prev[process_id]->get(it.row())) /
92 double const fij = -mij * (xdotj - xdoti);
93 F->add(it.row(), it.col(), fij);
104 auto& F_raw = F->getRawMatrix();
105 for (
int k = 0; k < F_raw.outerSize(); ++k)
107 for (RawMatrixType::InnerIterator it(F_raw, k); it; ++it)
109 if (it.row() != it.col())
111 double const fij = it.value();
112 P_plus->add(it.row(), std::max(0., fij));
113 P_minus->add(it.row(), std::min(0., fij));
115 double const x_prev_i = x_prev[process_id]->get(it.row());
116 double const x_prev_j = x_prev[process_id]->get(it.col());
118 double const Q_plus_i = Q_plus->get(it.row());
119 double Q_plus_i_tmp =
120 std::max({Q_plus_i, 0., x_prev_j - x_prev_i});
121 Q_plus->set(it.row(), Q_plus_i_tmp);
123 double const Q_minus_i = Q_minus->get(it.row());
124 double Q_minus_i_tmp =
125 std::min({Q_minus_i, 0., x_prev_j - x_prev_i});
126 Q_minus->set(it.row(), Q_minus_i_tmp);
131 Eigen::VectorXd
const M_L =
132 (M_raw * Eigen::VectorXd::Ones(M_raw.cols())).eval();
133 for (
auto k = R_plus->getRangeBegin(); k < R_plus->getRangeEnd(); ++k)
135 double const mi = M_L(k);
136 double const Q_plus_i = Q_plus->get(k);
137 double const P_plus_i = P_plus->get(k);
140 P_plus_i == 0. ? 0.0 : std::min(1.0, mi * Q_plus_i / dt / P_plus_i);
145 for (
auto k = R_minus->getRangeBegin(); k < R_minus->getRangeEnd(); ++k)
147 double const mi = M_L(k);
148 double const Q_minus_i = Q_minus->get(k);
149 double const P_minus_i = P_minus->get(k);
151 double const tmp = P_minus_i == 0.
153 : std::min(1.0, mi * Q_minus_i / dt / P_minus_i);
154 R_minus->set(k, tmp);
158 for (
int k = 0; k < F_raw.outerSize(); ++k)
160 for (RawMatrixType::InnerIterator it(F_raw, k); it; ++it)
162 double const fij = it.value();
165 double const R_plus_i = R_plus->get(it.row());
166 double const R_minus_j = R_minus->get(it.col());
167 double const alpha_ij = std::min(R_plus_i, R_minus_j);
169 alpha->setValue(it.row(), it.col(), alpha_ij);
173 double const R_minus_i = R_minus->get(it.row());
174 double const R_plus_j = R_plus->get(it.col());
175 double const alpha_ij = std::min(R_minus_i, R_plus_j);
177 alpha->setValue(it.row(), it.col(), alpha_ij);
183 for (
int k = 0; k < F_raw.outerSize(); ++k)
185 for (RawMatrixType::InnerIterator it(F_raw, k); it; ++it)
187 if (it.row() != it.col())
189 double const fij = it.value();
190 double const alpha_ij = alpha->get(it.row(), it.col());
192 b.add(it.row(), alpha_ij * fij);
203 for (
int k = 0; k < M.getNumberOfRows(); ++k)
205 M.setValue(k, k, M_L(k));