Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions unit/src/NestedSolveTest.C
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "libmesh/vector_value.h"

#include <utility>

TEST(NestedSolve, FixedSize)
{
auto compute = [&](const NestedSolve::Value<2> & guess,
Expand Down Expand Up @@ -200,6 +202,50 @@ TEST(NestedSolve, ScalarPowellTight)
EXPECT_NEAR(solution, 2, 1e-6);
}

TEST(NestedSolve, ScalarBounded)
{
auto computeResidual = [&](const Real & guess, Real & residual) { residual = guess - 2.0; };
auto computeJacobian = [&](const Real & /*guess*/, Real & jacobian) { jacobian = 1.0; };

bool bounds_checked = false;
auto computeBounds = [&]()
{
bounds_checked = true;
return std::make_pair(1.0, 3.0);
};

NestedSolve solver;
Real solution = 1.5;
solver.nonlinearBounded(solution, computeResidual, computeJacobian, computeBounds);

EXPECT_TRUE(bounds_checked);
EXPECT_NEAR(solution, 2.0, 1e-10);
EXPECT_GE(solution, 1.0);
EXPECT_LE(solution, 3.0);
}

TEST(NestedSolve, ScalarBoundedAD)
{
auto computeResidual = [&](const ADReal & guess, ADReal & residual) { residual = guess - 2.0; };
auto computeJacobian = [&](const ADReal & /*guess*/, ADReal & jacobian) { jacobian = 1.0; };

bool bounds_checked = false;
auto computeBounds = [&]()
{
bounds_checked = true;
return std::make_pair(1.0, 3.0);
};

ADNestedSolve solver;
ADReal solution = 1.5;
solver.nonlinearBounded(solution, computeResidual, computeJacobian, computeBounds);

EXPECT_TRUE(bounds_checked);
EXPECT_NEAR(MetaPhysicL::raw_value(solution), 2.0, 1e-10);
EXPECT_GE(MetaPhysicL::raw_value(solution), 1.0);
EXPECT_LE(MetaPhysicL::raw_value(solution), 3.0);
}

TEST(NestedSolve, PlacementNew)
{
Eigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> em(3, 3);
Expand Down