https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Functions
BrentsMethodTest.C File Reference

Go to the source code of this file.

Functions

Real f (Real x)
 Test function for Brents method.
 
 TEST (BrentsMethod, bracket)
 
 TEST (BrentsMethod, root)
 

Function Documentation

◆ f()

Real f ( Real  x)

Test function for Brents method.

f(x) = log(1 + x) * tanh(x / 3) + x / 4 - 3 which has a root at 5.170302597.

Note: the implementation of Brents bracketing method restricts the bracketing interval to positive values

Definition at line 21 of file BrentsMethodTest.C.

22{
23 return std::log(1.0 + x) * std::tanh(x / 3.0) + x / 4.0 - 3;
24}
const std::vector< double > x

Referenced by SolidMechanicsPlasticModel::activeConstraints(), SolidMechanicsPlasticMeanCapTC::activeConstraints(), SolidMechanicsPlasticMohrCoulombMulti::activeConstraints(), SolidMechanicsPlasticTensileMulti::activeConstraints(), SolidMechanicsPlasticWeakPlaneShear::activeConstraints(), SolidMechanicsPlasticWeakPlaneTensile::activeConstraints(), ComputeMultiPlasticityStress::applyKuhnTucker(), BrentsMethod::bracket(), MultiPlasticityRawComponentAssembler::buildActiveConstraints(), MultiPlasticityRawComponentAssembler::buildActiveConstraintsJoint(), MultiPlasticityRawComponentAssembler::buildActiveConstraintsRock(), ComputeMultiPlasticityStress::buildDumbOrder(), MultiPlasticityLinearSystem::calculateConstraints(), MultiPlasticityLinearSystem::calculateRHS(), ComputeMultiPlasticityStress::checkKuhnTucker(), ChemicalReactionsApp__registerAll(), ChemicalReactionsTestApp__registerAll(), CombinedApp__registerAll(), CombinedTestApp__registerAll(), StiffenedGasTwoPhaseFluidProperties::compute_p_sat(), ADComputeIncrementalShellStrain::computeGMatrix(), ComputeHomogenizedLagrangianStrainA::ComputeHomogenizedLagrangianStrainA(), SCMMixingKimAndChung::computeLatticeMixingParameter(), ComputeSimoHughesJ2PlasticityStress::computeQpPK1Stress(), ElectrochemicalSinteringMaterial::computeQpProperties(), GrandPotentialSinteringMaterial::computeQpProperties(), ADWallHeatTransferCoefficientGnielinskiMaterial::computeQpProperties(), CNSFVHLLCBC::computeQpResidual(), PCNSFVHLLCBC::computeQpResidual(), CNSFVHLLC::computeQpResidual(), PCNSFVHLLC::computeQpResidual(), ComputeLagrangianStrainBase< G >::computeQpRotationIncrement(), ContactApp__registerAll(), ContactTestApp__registerAll(), SodiumProperties::drho_dT(), ElectromagneticsApp__registerAll(), ElectromagneticsTestApp__registerAll(), StabilizationUtils::elementAverage(), MultiPlasticityLinearSystem::eliminateLinearDependence(), HSCoupler2D3DUserObject::evaluateTemperatureFunction(), ExternalPetscSolverApp__registerAll(), ExternalPetscSolverTestApp__registerAll(), FluidPropertiesApp__registerAll(), FluidPropertiesTestApp__registerAll(), FormIFunction(), FourierNoise::FourierNoise(), FsiApp__registerAll(), FsiTestApp__registerAll(), FunctionalExpansionToolsApp__registerAll(), FunctionalExpansionToolsTestApp__registerAll(), GeochemistryApp__registerAll(), GeochemistryTestApp__registerAll(), OptimizeSolve::getTaoSolutionStatus(), HeatTransferApp__registerAll(), HeatTransferTestApp__registerAll(), HomogenizationInterface< T >::HomogenizationInterface(), SubChannel1PhaseProblem::implicitPetscSolve(), Beta::incompleteBetaInv(), Gamma::incompleteGammaInv(), ParameterStudyAction::inferMultiAppMode(), LevelSetApp__registerAll(), LevelSetTestApp__registerAll(), ComputeMultiPlasticityStress::lineSearch(), MiscApp__registerAll(), MiscTestApp__registerAll(), ModulesApp__registerAll(), OptimizeSolve::monitor(), NavierStokesApp__registerAll(), NavierStokesTestApp__registerAll(), FluidPropertiesUtils::NewtonSolve2D(), ViewFactorBase::normalizeUsingLagrangeMultiplier(), NSFVDispersePhaseDragFunctorMaterial::NSFVDispersePhaseDragFunctorMaterial(), OptimizationApp__registerAll(), OptimizationTestApp__registerAll(), PorousFlowLineGeometry::parseNextLineReals(), PeridynamicsApp__registerAll(), PeridynamicsTestApp__registerAll(), PhaseFieldApp__registerAll(), PhaseFieldTestApp__registerAll(), PorousFlowApp__registerAll(), PorousFlowTestApp__registerAll(), LevelSetOlssonReinitialization::precomputeQpResidual(), NavierStokesLHDGAssemblyHelper::pressureVolumeResidual(), PorousFlowFluidStateFlash::rachfordRice(), RayTracingApp__registerAll(), RayTracingTestApp__registerAll(), RdgApp__registerAll(), RdgTestApp__registerAll(), ReactorApp__registerAll(), ReactorTestApp__registerAll(), ChemicalReactionsApp::registerAll(), CombinedApp::registerAll(), ContactApp::registerAll(), ElectromagneticsApp::registerAll(), ExternalPetscSolverApp::registerAll(), FluidPropertiesApp::registerAll(), FsiApp::registerAll(), FunctionalExpansionToolsApp::registerAll(), GeochemistryApp::registerAll(), HeatTransferApp::registerAll(), LevelSetApp::registerAll(), MiscApp::registerAll(), ModulesApp::registerAll(), NavierStokesApp::registerAll(), NavierStokesUnitApp::registerAll(), OptimizationApp::registerAll(), PeridynamicsApp::registerAll(), PhaseFieldApp::registerAll(), PorousFlowApp::registerAll(), RayTracingApp::registerAll(), RdgApp::registerAll(), ReactorApp::registerAll(), ReactorUnitApp::registerAll(), ScalarTransportApp::registerAll(), ShiftedBoundaryMethodApp::registerAll(), SolidMechanicsApp::registerAll(), SolidPropertiesApp::registerAll(), StochasticToolsApp::registerAll(), SubChannelApp::registerAll(), ThermalHydraulicsApp::registerAll(), XFEMApp::registerAll(), ChemicalReactionsTestApp::registerAll(), CombinedTestApp::registerAll(), ContactTestApp::registerAll(), ElectromagneticsTestApp::registerAll(), ExternalPetscSolverTestApp::registerAll(), FluidPropertiesTestApp::registerAll(), FsiTestApp::registerAll(), FunctionalExpansionToolsTestApp::registerAll(), GeochemistryTestApp::registerAll(), HeatTransferTestApp::registerAll(), LevelSetTestApp::registerAll(), MiscTestApp::registerAll(), NavierStokesTestApp::registerAll(), OptimizationTestApp::registerAll(), PeridynamicsTestApp::registerAll(), PhaseFieldTestApp::registerAll(), PorousFlowTestApp::registerAll(), RayTracingTestApp::registerAll(), RdgTestApp::registerAll(), ReactorTestApp::registerAll(), ScalarTransportTestApp::registerAll(), ShiftedBoundaryMethodTestApp::registerAll(), SolidMechanicsTestApp::registerAll(), SolidPropertiesTestApp::registerAll(), StochasticToolsTestApp::registerAll(), SubChannelTestApp::registerAll(), ThermalHydraulicsTestApp::registerAll(), XFEMTestApp::registerAll(), ModulesApp::registerAllObjects(), ComputeMultiPlasticityStress::residual2(), FiniteStrainPlasticMaterial::returnMap(), ComputeMultiPlasticityStress::returnMap(), SodiumProperties::rho(), BrentsMethod::root(), ScalarTransportApp__registerAll(), ScalarTransportTestApp__registerAll(), ComputeLagrangianStrainBase< G >::setQpIncrementalStrains(), OptimizeSolve::setTaoSolutionStatus(), ShiftedBoundaryMethodApp__registerAll(), ShiftedBoundaryMethodTestApp__registerAll(), ComputeMultiPlasticityStress::singleStep(), MultiParameterPlasticityStressUpdate::smoothAllQuantities(), SolidMechanicsApp__registerAll(), SolidMechanicsTestApp__registerAll(), SolidPropertiesApp__registerAll(), SolidPropertiesTestApp__registerAll(), StochasticToolsApp__registerAll(), StochasticToolsTestApp__registerAll(), SubChannelTestApp__registerAll(), TemperatureDependentHardeningStressUpdateTempl< is_ad >::TemperatureDependentHardeningStressUpdateTempl(), TEST(), TEST(), TEST(), TEST_F(), ThermalHydraulicsApp__registerAll(), ThermalHydraulicsTestApp__registerAll(), FourierNoise::value(), FourierNoise::value(), Water97FluidProperties::vaporTemperature_ad(), XFEMApp__registerAll(), XFEMTestApp__registerAll(), IdealRealGasMixtureFluidProperties::xs_prim_from_p_T(), MultiPlasticityRawComponentAssembler::yieldFunction(), SolidMechanicsPlasticMohrCoulombMulti::yieldFunctionEigvals(), SolidMechanicsPlasticModel::yieldFunctionV(), SolidMechanicsPlasticMohrCoulombMulti::yieldFunctionV(), and SolidMechanicsPlasticTensileMulti::yieldFunctionV().

◆ TEST() [1/2]

TEST ( BrentsMethod  ,
bracket   
)

Definition at line 26 of file BrentsMethodTest.C.

27{
28 // Initial guess for bracketing interval does not bracket root
29 Real x1 = 0.5;
30 Real x2 = 1.0;
31
32 auto func = [](Real x) { return f(x); };
33
34 // Call bracket to determine the bracketing interval
35 BrentsMethod::bracket(func, x1, x2);
36
37 // The product of the function f(x) at the bracketing interval (x1, x2) must
38 // be negative to bracket a root
39 EXPECT_LT(f(x1) * f(x2), 0.0);
40
41 // Test that a warning is thrown if the initial guesses are equal
42 try
43 {
44 // Trigger identical initial guess error
45 BrentsMethod::bracket(func, x1, x1);
46 FAIL() << "missing expected exception";
47 }
48 catch (const std::exception & e)
49 {
50 std::string msg(e.what());
51 ASSERT_TRUE(msg.find("Bad initial range (0) used in BrentsMethod::bracket") !=
52 std::string::npos)
53 << "failed with unexpected error: " << msg;
54 }
55
56 // Test that a warning is thrown if no bracketing interval is found after 50 iterations.
57 try
58 {
59 // Trigger no bracketing interval warning by adding 4 to f(x), whereby no real root exists
60 auto func2 = [](Real x) { return f(x) + 4.0; };
61
62 BrentsMethod::bracket(func2, x1, x2);
63 FAIL() << "missing expected exception";
64 }
65 catch (const std::exception & e)
66 {
67 std::string msg(e.what());
68 ASSERT_TRUE(
69 msg.find("No bracketing interval found by BrentsMethod::bracket after 50 iterations") !=
70 std::string::npos)
71 << "failed with unexpected error: " << msg;
72 }
73}
Real f(Real x)
Test function for Brents method.
void bracket(std::function< Real(Real)> const &f, Real &x1, Real &x2)
Function to bracket a root of a given function.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ TEST() [2/2]

TEST ( BrentsMethod  ,
root   
)

Definition at line 75 of file BrentsMethodTest.C.

76{
77 // Bracketing interval that does bracket root
78 Real x1 = 0.5;
79 Real x2 = 10.0;
80
81 auto func = [](Real x) { return f(x); };
82
83 // Check that the root is 5.170302597
84 EXPECT_NEAR(5.170302597, BrentsMethod::root(func, x1, x2), 1e-8);
85
86 // Test that a warning is thrown if the supplied interval does not bracket the root
87 try
88 {
89 // Trigger no bracketing interval error
90 x2 = 1.0;
91 BrentsMethod::root(func, x1, x2);
92 FAIL() << "missing expected exception";
93 }
94 catch (const std::exception & e)
95 {
96 std::string msg(e.what());
97 ASSERT_TRUE(msg.find("Root must be bracketed in BrentsMethod::root") != std::string::npos)
98 << "failed with unexpected error: " << msg;
99 }
100}
Real root(std::function< Real(Real)> const &f, Real x1, Real x2, Real tol=1.0e-12)
Finds the root of a function using Brent's method.