|
14 | 14 |
|
15 | 15 | #include "libmesh/vector_value.h" |
16 | 16 |
|
| 17 | +#include <utility> |
| 18 | + |
17 | 19 | TEST(NestedSolve, FixedSize) |
18 | 20 | { |
19 | 21 | auto compute = [&](const NestedSolve::Value<2> & guess, |
@@ -200,6 +202,50 @@ TEST(NestedSolve, ScalarPowellTight) |
200 | 202 | EXPECT_NEAR(solution, 2, 1e-6); |
201 | 203 | } |
202 | 204 |
|
| 205 | +TEST(NestedSolve, ScalarBounded) |
| 206 | +{ |
| 207 | + auto computeResidual = [&](const Real & guess, Real & residual) { residual = guess - 2.0; }; |
| 208 | + auto computeJacobian = [&](const Real & /*guess*/, Real & jacobian) { jacobian = 1.0; }; |
| 209 | + |
| 210 | + bool bounds_checked = false; |
| 211 | + auto computeBounds = [&]() |
| 212 | + { |
| 213 | + bounds_checked = true; |
| 214 | + return std::make_pair(1.0, 3.0); |
| 215 | + }; |
| 216 | + |
| 217 | + NestedSolve solver; |
| 218 | + Real solution = 1.5; |
| 219 | + solver.nonlinearBounded(solution, computeResidual, computeJacobian, computeBounds); |
| 220 | + |
| 221 | + EXPECT_TRUE(bounds_checked); |
| 222 | + EXPECT_NEAR(solution, 2.0, 1e-10); |
| 223 | + EXPECT_GE(solution, 1.0); |
| 224 | + EXPECT_LE(solution, 3.0); |
| 225 | +} |
| 226 | + |
| 227 | +TEST(NestedSolve, ScalarBoundedAD) |
| 228 | +{ |
| 229 | + auto computeResidual = [&](const ADReal & guess, ADReal & residual) { residual = guess - 2.0; }; |
| 230 | + auto computeJacobian = [&](const ADReal & /*guess*/, ADReal & jacobian) { jacobian = 1.0; }; |
| 231 | + |
| 232 | + bool bounds_checked = false; |
| 233 | + auto computeBounds = [&]() |
| 234 | + { |
| 235 | + bounds_checked = true; |
| 236 | + return std::make_pair(1.0, 3.0); |
| 237 | + }; |
| 238 | + |
| 239 | + ADNestedSolve solver; |
| 240 | + ADReal solution = 1.5; |
| 241 | + solver.nonlinearBounded(solution, computeResidual, computeJacobian, computeBounds); |
| 242 | + |
| 243 | + EXPECT_TRUE(bounds_checked); |
| 244 | + EXPECT_NEAR(MetaPhysicL::raw_value(solution), 2.0, 1e-10); |
| 245 | + EXPECT_GE(MetaPhysicL::raw_value(solution), 1.0); |
| 246 | + EXPECT_LE(MetaPhysicL::raw_value(solution), 3.0); |
| 247 | +} |
| 248 | + |
203 | 249 | TEST(NestedSolve, PlacementNew) |
204 | 250 | { |
205 | 251 | Eigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> em(3, 3); |
|
0 commit comments