Loading...
Searching...
No Matches
MeasuredCubicStencil.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3// See LICENSE for details.
4#pragma once
5
8
9namespace gpr::optim {
10
12 bool valid = false;
13 double coefficient = 0.0;
14 double error = std::numeric_limits<double>::infinity();
15};
16
22 const RefinedCurvatureActions& stencil,
23 const Eigen::VectorXd& center_gradient, const Eigen::VectorXd& mode,
24 double step)
25{
27 const auto& basis = stencil.basis;
28 const auto& coarse_mean = stencil.coarse_mean_gradient;
29 const auto& fine_mean = stencil.fine_mean_gradient;
30 if (basis.cols() != 2 || basis.rows() != center_gradient.size() ||
31 mode.size() != basis.rows() || coarse_mean.rows() != basis.rows() ||
32 fine_mean.rows() != basis.rows() || coarse_mean.cols() != 2 ||
33 fine_mean.cols() != 2 || !basis.allFinite() ||
34 !center_gradient.allFinite() || !mode.allFinite() ||
35 !coarse_mean.allFinite() || !fine_mean.allFinite() || !(step > 0.0) ||
36 !std::isfinite(step))
37 return out;
38 const double eps = std::numeric_limits<double>::epsilon();
39 const Eigen::Vector2d overlaps = basis.transpose() * mode;
40 if ((basis.transpose() * basis - Eigen::Matrix2d::Identity()).norm() >
41 std::sqrt(eps) ||
42 (mode - basis * overlaps).norm() >
43 std::sqrt(eps) * std::max(1.0, mode.norm()))
44 return out;
45 out.error = 0.0;
46 for (Eigen::Index j = 0; j < 2; ++j) {
47 const Eigen::VectorXd coarse =
48 (2.0 / (step * step)) * (coarse_mean.col(j) - center_gradient);
49 const Eigen::VectorXd fine =
50 (8.0 / (step * step)) * (fine_mean.col(j) - center_gradient);
51 const Eigen::VectorXd refined = (4.0 * fine - coarse) / 3.0;
52 const Eigen::VectorXd roundoff =
53 (64.0 * eps / (step * step)) *
54 (coarse_mean.col(j).cwiseAbs() + fine_mean.col(j).cwiseAbs() +
55 2.0 * center_gradient.cwiseAbs());
56 const Eigen::VectorXd error =
57 ((coarse - fine) / 3.0).cwiseAbs() + roundoff;
58 const double overlap = overlaps(j);
60 overlap, mode.dot(refined), basis.col(j).dot(refined));
61 out.error +=
62 overlap * overlap *
63 (3.0 * mode.cwiseAbs().dot(error) +
64 2.0 * std::abs(overlap) * basis.col(j).cwiseAbs().dot(error));
65 }
66 out.valid = std::isfinite(out.coefficient) && std::isfinite(out.error);
67 return out;
68}
69
70} // namespace gpr::optim
The curvature of a mode at the stationary point the search converges to, from the cubic model along t...
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out
double measuredCubicColumnContribution(double overlap, double mode_quadratic, double axis_quadratic)
MeasuredDirectionalCubic refinedDirectionalCubic(const RefinedCurvatureActions &stencil, const Eigen::VectorXd &center_gradient, const Eigen::VectorXd &mode, double step)