limes 3.1.0
Composable Calculus Expressions for C++20
Loading...
Searching...
No Matches
limes::expr::ConstrainedBoxIntegral< E, Dims, Constraint > Struct Template Reference

Box integral with constraint for irregular regions. More...

#include <box_integral.hpp>

Public Types

using value_type = typename E::value_type
 
using integrand_type = E
 
using bounds_type = std::array< std::pair< value_type, value_type >, Dims >
 

Public Member Functions

constexpr ConstrainedBoxIntegral (E e, bounds_type b, Constraint c) noexcept
 
algorithms::integration_result< value_typeeval (methods::monte_carlo< value_type > const &method) const
 Evaluate using Monte Carlo with rejection sampling.
 
algorithms::integration_result< value_typeeval () const
 Evaluate with default Monte Carlo.
 
algorithms::integration_result< value_typeeval (std::size_t samples) const
 Evaluate with sample count.
 
std::string to_string () const
 String representation.
 

Public Attributes

integrand
 
bounds_type bounds
 
Constraint constraint
 

Static Public Attributes

static constexpr std::size_t dims_v = Dims
 
static constexpr std::size_t arity_v = (E::arity_v > Dims) ? (E::arity_v - Dims) : 0
 

Detailed Description

template<typename E, std::size_t Dims, typename Constraint>
struct limes::expr::ConstrainedBoxIntegral< E, Dims, Constraint >

Box integral with constraint for irregular regions.

Uses rejection sampling to integrate over regions defined by a constraint function. Points are sampled from the bounding box and rejected if they don't satisfy the constraint.

Template Parameters
EIntegrand expression type
DimsNumber of dimensions
ConstraintConstraint predicate type
Example: Triangle region
// Integrate over triangle where y < x
auto I = integral(x*y)
.over_box({{0,1}, {0,1}})
.where([](auto x, auto y) { return y < x; });
auto result = I.eval(100000); // 100k samples
constexpr auto integral(E expr)
Create an IntegralBuilder for fluent integral construction.
Definition integral.hpp:505
constexpr Var< 1, T > y
Definition var.hpp:49
constexpr Var< 0, T > x
Definition var.hpp:46
Example: Circle region
// Integrate over unit disk
auto J = integral(f)
.over_box({{-1,1}, {-1,1}})
.where([](auto x, auto y) { return x*x + y*y < 1; });
Note
The acceptance rate affects variance. For regions that are a small fraction of the bounding box, more samples are needed for accuracy.
See also
BoxIntegral::where() Factory method

Definition at line 253 of file box_integral.hpp.

Member Typedef Documentation

◆ bounds_type

template<typename E , std::size_t Dims, typename Constraint >
using limes::expr::ConstrainedBoxIntegral< E, Dims, Constraint >::bounds_type = std::array<std::pair<value_type, value_type>, Dims>

Definition at line 256 of file box_integral.hpp.

◆ integrand_type

template<typename E , std::size_t Dims, typename Constraint >
using limes::expr::ConstrainedBoxIntegral< E, Dims, Constraint >::integrand_type = E

Definition at line 255 of file box_integral.hpp.

◆ value_type

template<typename E , std::size_t Dims, typename Constraint >
using limes::expr::ConstrainedBoxIntegral< E, Dims, Constraint >::value_type = typename E::value_type

Definition at line 254 of file box_integral.hpp.

Constructor & Destructor Documentation

◆ ConstrainedBoxIntegral()

template<typename E , std::size_t Dims, typename Constraint >
constexpr limes::expr::ConstrainedBoxIntegral< E, Dims, Constraint >::ConstrainedBoxIntegral ( e,
bounds_type  b,
Constraint  c 
)
inlineconstexprnoexcept

Definition at line 265 of file box_integral.hpp.

Member Function Documentation

◆ eval() [1/3]

template<typename E , std::size_t Dims, typename Constraint >
algorithms::integration_result< value_type > limes::expr::ConstrainedBoxIntegral< E, Dims, Constraint >::eval ( ) const
inline

◆ eval() [2/3]

◆ eval() [3/3]

template<typename E , std::size_t Dims, typename Constraint >
algorithms::integration_result< value_type > limes::expr::ConstrainedBoxIntegral< E, Dims, Constraint >::eval ( std::size_t  samples) const
inline

Evaluate with sample count.

Definition at line 317 of file box_integral.hpp.

References limes::expr::ConstrainedBoxIntegral< E, Dims, Constraint >::eval().

◆ to_string()

template<typename E , std::size_t Dims, typename Constraint >
std::string limes::expr::ConstrainedBoxIntegral< E, Dims, Constraint >::to_string ( ) const
inline

Member Data Documentation

◆ arity_v

template<typename E , std::size_t Dims, typename Constraint >
constexpr std::size_t limes::expr::ConstrainedBoxIntegral< E, Dims, Constraint >::arity_v = (E::arity_v > Dims) ? (E::arity_v - Dims) : 0
staticconstexpr

Definition at line 259 of file box_integral.hpp.

◆ bounds

template<typename E , std::size_t Dims, typename Constraint >
bounds_type limes::expr::ConstrainedBoxIntegral< E, Dims, Constraint >::bounds

◆ constraint

template<typename E , std::size_t Dims, typename Constraint >
Constraint limes::expr::ConstrainedBoxIntegral< E, Dims, Constraint >::constraint

Definition at line 263 of file box_integral.hpp.

◆ dims_v

template<typename E , std::size_t Dims, typename Constraint >
constexpr std::size_t limes::expr::ConstrainedBoxIntegral< E, Dims, Constraint >::dims_v = Dims
staticconstexpr

Definition at line 258 of file box_integral.hpp.

◆ integrand

template<typename E , std::size_t Dims, typename Constraint >
E limes::expr::ConstrainedBoxIntegral< E, Dims, Constraint >::integrand

The documentation for this struct was generated from the following file: