Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
MCGIDI::Probabilities::Xs_pdf_cdf1d Class Reference

#include <MCGIDI_functions.hpp>

Inheritance diagram for MCGIDI::Probabilities::Xs_pdf_cdf1d:

Public Member Functions

LUPI_HOST_DEVICE Xs_pdf_cdf1d ()
LUPI_HOST Xs_pdf_cdf1d (GIDI::Functions::Xs_pdf_cdf1d const &a_xs_pdf_cdf1d)
LUPI_HOST_DEVICE ~Xs_pdf_cdf1d ()
LUPI_HOST_DEVICE double evaluate (double a_x1) const
template<typename RNG>
LUPI_HOST_DEVICE double sample (double a_rngValue, RNG &&a_rng) const
LUPI_HOST_DEVICE void serialize (LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)
template<typename RNG>
LUPI_HOST_DEVICE double sample (double a_rngValue, LUPI_maybeUnused RNG &&a_rng) const
Public Member Functions inherited from MCGIDI::Probabilities::ProbabilityBase1d
LUPI_HOST_DEVICE ProbabilityBase1d ()
LUPI_HOST ProbabilityBase1d (GIDI::Functions::FunctionForm const &a_probabilty, Vector< double > const &a_Xs)
LUPI_HOST_DEVICE ~ProbabilityBase1d ()
LUPI_HOST_DEVICE ProbabilityBase1dType type () const
LUPI_HOST_DEVICE String typeString () const
LUPI_HOST_DEVICE MCGIDI_VIRTUAL_FUNCTION double evaluate (double a_x1) const MCGIDI_TRUE_VIRTUAL
template<typename RNG>
LUPI_HOST_DEVICE MCGIDI_VIRTUAL_FUNCTION double sample (double a_rngValue, RNG &&a_rng) const MCGIDI_TRUE_VIRTUAL
LUPI_HOST_DEVICE void serialize (LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)
template<typename RNG>
LUPI_HOST_DEVICE double sample (double a_rngValue, RNG &&a_rng) const
Public Member Functions inherited from MCGIDI::Probabilities::ProbabilityBase
LUPI_HOST_DEVICE ProbabilityBase ()
LUPI_HOST ProbabilityBase (GIDI::Functions::FunctionForm const &a_probabilty)
LUPI_HOST ProbabilityBase (GIDI::Functions::FunctionForm const &a_probabilty, Vector< double > const &a_Xs)
LUPI_HOST_DEVICE ~ProbabilityBase ()
LUPI_HOST_DEVICE void serialize (LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)
Public Member Functions inherited from MCGIDI::Functions::FunctionBase
LUPI_HOST_DEVICE FunctionBase ()
LUPI_HOST FunctionBase (GIDI::Functions::FunctionForm const &a_function)
LUPI_HOST_DEVICE FunctionBase (int a_dimension, double a_domainMin, double a_domainMax, Interpolation a_interpolation, double a_outerDomainValue=0)
virtual LUPI_HOST_DEVICE ~FunctionBase ()=0
LUPI_HOST_DEVICE Interpolation interpolation () const
LUPI_HOST_DEVICE double domainMin () const
LUPI_HOST_DEVICE double domainMax () const
LUPI_HOST_DEVICE double outerDomainValue () const
LUPI_HOST_DEVICE void serialize (LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)

Additional Inherited Members

Protected Attributes inherited from MCGIDI::Probabilities::ProbabilityBase1d
ProbabilityBase1dType m_type
Protected Attributes inherited from MCGIDI::Probabilities::ProbabilityBase
Vector< double > m_Xs

Detailed Description

Definition at line 373 of file MCGIDI_functions.hpp.

Constructor & Destructor Documentation

◆ Xs_pdf_cdf1d() [1/2]

LUPI_HOST_DEVICE MCGIDI::Probabilities::Xs_pdf_cdf1d::Xs_pdf_cdf1d ( )

Definition at line 1330 of file MCGIDI_functions.cc.

1330 :
1331 m_pdf( ),
1332 m_cdf( ) {
1333
1335}

◆ Xs_pdf_cdf1d() [2/2]

LUPI_HOST MCGIDI::Probabilities::Xs_pdf_cdf1d::Xs_pdf_cdf1d ( GIDI::Functions::Xs_pdf_cdf1d const & a_xs_pdf_cdf1d)

Definition at line 1339 of file MCGIDI_functions.cc.

1339 :
1340 ProbabilityBase1d( a_xs_pdf_cdf1d, a_xs_pdf_cdf1d.Xs( ) ),
1341 m_pdf( a_xs_pdf_cdf1d.pdf( ) ),
1342 m_cdf( a_xs_pdf_cdf1d.cdf( ) ) {
1343
1345}

◆ ~Xs_pdf_cdf1d()

LUPI_HOST_DEVICE MCGIDI::Probabilities::Xs_pdf_cdf1d::~Xs_pdf_cdf1d ( )

Definition at line 1350 of file MCGIDI_functions.cc.

1350 {
1351
1352}

Member Function Documentation

◆ evaluate()

LUPI_HOST_DEVICE double MCGIDI::Probabilities::Xs_pdf_cdf1d::evaluate ( double a_x1) const

Definition at line 1356 of file MCGIDI_functions.cc.

1356 {
1357
1358 int intLower = binarySearchVector( a_x1, m_Xs );
1359
1360 if( intLower < 0 ) {
1361 if( intLower == -2 ) return( m_pdf[0] );
1362 return( m_pdf.back( ) );
1363 }
1364
1365 std::size_t lower = static_cast<std::size_t>( intLower );
1366 double fraction = ( a_x1 - m_Xs[lower] ) / ( m_Xs[lower+1] - m_Xs[lower] );
1367
1368 return( ( 1. - fraction ) * m_pdf[lower] + fraction * m_pdf[lower+1] );
1369}
LUPI_HOST_DEVICE int binarySearchVector(double a_x, Vector< double > const &a_Xs, bool a_boundIndex=false)
Definition MCGIDI.hpp:318

◆ sample() [1/2]

template<typename RNG>
LUPI_HOST_DEVICE double MCGIDI::Probabilities::Xs_pdf_cdf1d::sample ( double a_rngValue,
LUPI_maybeUnused RNG && a_rng ) const

Definition at line 1653 of file MCGIDI_headerSource.hpp.

1653 {
1654
1655 int intLower = binarySearchVector( a_rngValue, m_cdf );
1656 double domainValue = 0;
1657
1658 if( intLower < 0 ) { // This should never happen.
1659 LUPI_THROW( "Xs_pdf_cdf1d::sample: intLower < 0." );
1660 }
1661
1662 std::size_t lower = static_cast<std::size_t>( intLower );
1663
1665 double fraction = ( m_cdf[lower+1] - a_rngValue ) / ( m_cdf[lower+1] - m_cdf[lower] );
1666 domainValue = fraction * m_Xs[lower] + ( 1 - fraction ) * m_Xs[lower+1]; }
1667 else { // Assumes lin-lin interpolation.
1668 double slope = m_pdf[lower+1] - m_pdf[lower];
1669
1670 if( slope == 0.0 ) {
1671 if( m_pdf[lower] == 0.0 ) {
1672 domainValue = m_Xs[lower];
1673 if( lower == 0 ) domainValue = m_Xs[1]; }
1674 else {
1675 double fraction = ( m_cdf[lower+1] - a_rngValue ) / ( m_cdf[lower+1] - m_cdf[lower] );
1676 domainValue = fraction * m_Xs[lower] + ( 1 - fraction ) * m_Xs[lower+1];
1677 } }
1678 else {
1679 double d1, d2;
1680
1681 slope = slope / ( m_Xs[lower+1] - m_Xs[lower] );
1682 d1 = a_rngValue - m_cdf[lower];
1683 d2 = m_cdf[lower+1] - a_rngValue;
1684 if( d2 > d1 ) { // Closer to lower.
1685 domainValue = m_Xs[lower] + ( sqrt( m_pdf[lower] * m_pdf[lower] + 2. * slope * d1 ) - m_pdf[lower] ) / slope; }
1686 else { // Closer to lower + 1.
1687 domainValue = m_Xs[lower+1] - ( m_pdf[lower+1] - sqrt( m_pdf[lower+1] * m_pdf[lower+1] - 2. * slope * d2 ) ) / slope;
1688 }
1689 }
1690 }
1691 return( domainValue );
1692}
#define LUPI_THROW(arg)
LUPI_HOST_DEVICE Interpolation interpolation() const

◆ sample() [2/2]

template<typename RNG>
LUPI_HOST_DEVICE double MCGIDI::Probabilities::Xs_pdf_cdf1d::sample ( double a_rngValue,
RNG && a_rng ) const

◆ serialize()

LUPI_HOST_DEVICE void MCGIDI::Probabilities::Xs_pdf_cdf1d::serialize ( LUPI::DataBuffer & a_buffer,
LUPI::DataBuffer::Mode a_mode )

This method serializes this for broadcasting as needed for MPI and GPUs. The method can count the number of required bytes, pack this or unpack this depending on a_mode.

Parameters
a_buffer[in] The buffer to read or write data to depending on a_mode.
a_mode[in] Specifies the action of this method.

Definition at line 1379 of file MCGIDI_functions.cc.

1379 {
1380
1381 ProbabilityBase1d::serialize( a_buffer, a_mode );
1382
1383 DATA_MEMBER_VECTOR_DOUBLE( m_pdf, a_buffer, a_mode );
1384 DATA_MEMBER_VECTOR_DOUBLE( m_cdf, a_buffer, a_mode );
1385}
#define DATA_MEMBER_VECTOR_DOUBLE(member, buf, mode)
LUPI_HOST_DEVICE void serialize(LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)

The documentation for this class was generated from the following files: