17 template <
typename TFunctor>
22 for (
Size j = 1; j <
N; ++j) {
25 result += 2._f * functor(x);
27 result += 4._f * functor(x);
30 return Float(result * h / 3._f);
35 template <
typename TRng = UniformRng,
typename TInternal =
double>
41 static constexpr uint chunk = 100;
53 template <
typename TFunctor>
57 double errorSqr =
sqr(targetError);
63 for (
Size i = 0; i < chunk; ++i) {
65 const Vector q(rng(0), rng(1), rng(2));
72 for (
Size i : inside) {
73 const double x = (double)f(buffer[i]);
78 const double m = double(n);
79 if (m * sumSqr -
sum *
sum < m * m * errorSqr * sumSqr) {
90 template <
typename TFunctor>
93 if (functor(r.
lower()) * functor(r.
upper()) > 0._f) {
96 while (r.
size() > eps * range.
size()) {
98 if (functor(x) * functor(r.
upper()) > 0._f) {
110 template <
typename TFunctor>
114 const Float y2 = functor(x);
115 if (
abs(y1 - y2) > eps) {
Simplified implementation of std::unique_ptr, using only default deleter.
Object defining computational domain.
@ INSIDE
Marks all vectors inside of the domain.
INLINE Optional< Float > getRoot(const Interval &range, const Float eps, const TFunctor &functor)
Returns a root of a R->R function on given range.
INLINE bool isContinuous(const Interval &range, const Float delta, const Float eps, const TFunctor &functor)
Checks if the given R->R function is continuous in given interval.
NAMESPACE_SPH_BEGIN INLINE Float integrate(const Interval range, const TFunctor &functor)
Integrates a one-dimensional function using Simpson's rule.
uint32_t Size
Integral type used to index arrays (by default).
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
constexpr INLINE T sqr(const T &f) noexcept
Return a squared value.
INLINE auto abs(const T &f)
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
const NothingType NOTHING
Random number generators.
void clear()
Removes all elements from the array, but does NOT release the memory.
Helper object defining three-dimensional interval (box).
INLINE const Vector & lower() const
Returns lower bounds of the box.
INLINE Vector size() const
Returns box dimensions.
Base class for computational domains.
virtual void getSubset(ArrayView< const Vector > vs, Array< Size > &output, const SubsetType type) const =0
Returns an array of indices, marking vectors with given property by their index.
virtual Box getBoundingBox() const =0
Returns the bounding box of the domain.
virtual Float getVolume() const =0
Returns the total volume of the domain.
Object for integrating a generic three-dimensional scalar function.
Integrator(const IDomain &domain)
Constructs an integrator given the domain of integration.
Float integrate(TFunctor &&f, const Float targetError=0.001_f)
Integrates a function.
Integrator(IDomain &&domain)=delete
Object representing a 1D interval of real numbers.
INLINE Float lower() const
Returns lower bound of the interval.
INLINE Float upper() const
Returns upper bound of the interval.
INLINE Float center() const
Returns the center of the interval.
INLINE Float size() const
Returns the size of the interval.
Array with fixed number of allocated elements.
Object with deleted copy constructor and copy operator.