422{
423 if (d < 1 || reference.rows() != d || reference.cols() != d ||
424 support.empty())
425 throw std::invalid_argument(
426 "A d x d reference and a nonempty support are required");
427 Eigen::SelfAdjointEigenSolver<Matrix> modes(
428 .5 * (reference + reference.transpose()));
429 if (modes.info() != Eigen::Success || !(modes.eigenvalues().minCoeff() > 0))
430 throw std::domain_error("A positive reference curvature is required");
431 const Matrix& R = modes.eigenvectors();
433 const Eigen::Index n = nodes.tau.size(),
434 s = static_cast<Eigen::Index>(support.size()), S = s * d;
435 const bool primed = zeroMode.size() != 0;
436 if (primed && zeroMode.size() != n * d)
437 throw std::invalid_argument("A zero mode over every node is required");
438 std::vector<char> inSupport(n, 0);
439 for (Eigen::Index g: support) {
440 if (g < 0 || g >= n || inSupport[g])
441 throw std::invalid_argument(
442 "Support nodes must be distinct mesh nodes");
443 inSupport[g] = 1;
444 }
445
446 std::vector<Matrix> weighted(s);
447 for (Eigen::Index i = 0; i < s; ++i) {
448 const Matrix h = curvature(support[i]);
449 if (h.rows() != d || h.cols() != d || !h.allFinite())
450 throw std::invalid_argument("Finite d x d curvature required");
451 weighted[i] =
452 nodes.mass(support[i]) *
453 (R.transpose() * (.5 * (h + h.transpose()) - reference) * R);
454 }
455
456
457 std::vector<Matrix> columns(d,
Matrix(n, s));
458 std::vector<Eigen::SimplicialLDLT<Sparse>> scalar(d);
459 for (Eigen::Index a = 0; a < d; ++a) {
460 const double w2 = modes.eigenvalues()(a);
461 scalar[a].compute(
assemble(mesh, 1, [&](Eigen::Index) {
462 return Matrix::Constant(1, 1, w2);
464 if (scalar[a].info() != Eigen::Success)
465 throw std::runtime_error("Reference factorisation failed");
466 Vector unit = Vector::Zero(n);
467 for (Eigen::Index j = 0; j < s; ++j) {
468 unit(support[j]) = 1;
469 columns[a].col(j) = scalar[a].solve(unit);
470 unit(support[j]) = 0;
471 }
472 }
473 const Eigen::Index N = primed ? S + 1 : S;
474 Matrix A = Matrix::Identity(N, N);
475 for (Eigen::Index i = 0; i < s; ++i)
476 for (Eigen::Index j = 0; j < s; ++j)
477 for (Eigen::Index a = 0; a < d; ++a)
478 A.block(i * d + a, j * d, 1, d) +=
479 columns[a](support[i], j) * weighted[j].row(a);
481 if (primed) {
482
483
484
485 std::vector<Vector> modeU(d,
Vector(n)), gmu(d);
486 for (Eigen::Index g = 0; g < n; ++g) {
487 const Vector r = R.transpose() * zeroMode.segment(g * d, d);
488 for (Eigen::Index a = 0; a < d; ++a)
489 modeU[a](g) = r(a);
490 }
491 for (Eigen::Index a = 0; a < d; ++a)
492 gmu[a] = scalar[a].solve(
Vector(
nodes.mass.cwiseProduct(modeU[a])));
493 A(N - 1, N - 1) = 0;
494 for (Eigen::Index i = 0; i < s; ++i)
495 for (Eigen::Index a = 0; a < d; ++a) {
496 A(i * d + a, N - 1) = gmu[a](support[i]);
497 A(N - 1, i * d + a) =
498 nodes.mass(support[i]) * modeU[a](support[i]);
499 }
500 for (Eigen::Index a = 0; a < d; ++a) {
501 Vector offMass =
nodes.mass.cwiseProduct(modeU[a]);
502 for (Eigen::Index g: support)
503 offMass(g) = 0;
504
505 const Vector reach = columns[a].transpose() * offMass;
506 for (Eigen::Index j = 0; j < s; ++j)
507 A.block(N - 1, j * d, 1, d) -= reach(j) * weighted[j].row(a);
508 A(N - 1, N - 1) -= offMass.dot(gmu[a]);
509 }
510 for (Eigen::Index g = 0; g < n; ++g)
512 nodes.mass(g) * zeroMode.segment(g * d, d).squaredNorm();
513 }
514 Eigen::PartialPivLU<Matrix> lu(A);
515 const Matrix& U = lu.matrixLU();
516 out.sign = lu.permutationP().determinant() > 0 ? 1 : -1;
517 for (Eigen::Index i = 0; i < N; ++i) {
518 if (!(U(i, i) != 0))
519 throw std::domain_error("Singular Fredholm matrix");
520 out.logAbs += std::log(std::abs(U(i, i)));
521 if (U(i, i) < 0)
out.sign = -
out.sign;
522 }
523 if (primed) {
524 out.logAbs -= std::log(
out.norm);
526 }
528}
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out
Pencil assemble(const Mesh &mesh, Eigen::Index d, const std::function< Matrix(Eigen::Index)> &curvature)
constexpr std::array< Real, 8 > nodes