DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
Scalar.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "DNDS/HardEigen.hpp"
4#include "DNDS/Defines.hpp"
5#include "fmt/core.h"
6
7namespace DNDS::Scalar
8{
9 template <class TF>
10 real BisectSolveLower(TF &&F, real v0, real v1, real fTarget, int maxIter)
11 {
12 real f0 = F(v0);
13 real f1 = F(v1);
14 DNDS_assert_info(f0 <= fTarget && f1 >= fTarget && v0 < v1,
15 fmt::format(" v0 {} v1 {} f0 {} f1 {} fT {}", v0, v1, f0, f1, fTarget));
16 for (int iter = 1; iter <= maxIter; iter++)
17 {
18 if (f0 >= fTarget - verySmallReal)
19 break;
20 real vm = 0.5 * (v0 + v1);
21 v0 = std::min(v0, vm);
22 v1 = std::max(v1, vm);
23 if (F(vm) <= fTarget)
24 v0 = vm;
25 else
26 v1 = vm;
27 }
28
29 return v0;
30 }
31
32}
Core type aliases, constants, and metaprogramming utilities for the DNDS framework.
#define DNDS_assert_info(expr, info)
Debug-only assertion with an extra std::string info message.
Definition Errors.hpp:113
Robust linear-algebra primitives for small / moderately-sized Eigen matrices that are more numericall...
real BisectSolveLower(TF &&F, real v0, real v1, real fTarget, int maxIter)
Definition Scalar.hpp:10
DNDS_CONSTANT const real verySmallReal
Catch-all lower bound ("effectively zero").
Definition Defines.hpp:194
double real
Canonical floating-point scalar used throughout DNDSR (double precision).
Definition Defines.hpp:105