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

#include <MCGIDI_functions.hpp>

Inheritance diagram for MCGIDI::Functions::XYs2d:

Public Member Functions

LUPI_HOST_DEVICE XYs2d ()
LUPI_HOST XYs2d (GIDI::Functions::XYs2d const &a_XYs2d)
LUPI_HOST_DEVICE ~XYs2d ()
LUPI_HOST_DEVICE double evaluate (double a_x2, double a_x1) const
LUPI_HOST_DEVICE void serialize (LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)
Public Member Functions inherited from MCGIDI::Functions::Function2d
LUPI_HOST_DEVICE Function2d ()
LUPI_HOST Function2d (double a_domainMin, double a_domainMax, Interpolation a_interpolation, double a_outerDomainValue=0)
LUPI_HOST_DEVICE ~Function2d ()
LUPI_HOST_DEVICE Function2dType type () const
LUPI_HOST_DEVICE String typeString () const
LUPI_HOST_DEVICE MCGIDI_VIRTUAL_FUNCTION double evaluate (double a_x2, double a_x1) const MCGIDI_TRUE_VIRTUAL
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::Functions::Function2d
Function2dType m_type

Detailed Description

Definition at line 287 of file MCGIDI_functions.hpp.

Constructor & Destructor Documentation

◆ XYs2d() [1/2]

LUPI_HOST_DEVICE MCGIDI::Functions::XYs2d::XYs2d ( )

Definition at line 975 of file MCGIDI_functions.cc.

975 :
976 m_Xs( ),
977 m_functions1d( ) {
978
980}

◆ XYs2d() [2/2]

LUPI_HOST MCGIDI::Functions::XYs2d::XYs2d ( GIDI::Functions::XYs2d const & a_XYs2d)

Definition at line 984 of file MCGIDI_functions.cc.

984 :
985 Function2d( a_XYs2d.domainMin( ), a_XYs2d.domainMax( ), GIDI2MCGIDI_interpolation( a_XYs2d.interpolation( ) ), a_XYs2d.outerDomainValue( ) ),
986 m_Xs( a_XYs2d.Xs( ) ) {
987
989
990 Vector<GIDI::Functions::Function1dForm *> const &function1ds = a_XYs2d.function1ds( );
991 m_functions1d.resize( function1ds.size( ) );
992 for( std::size_t i1 = 0; i1 < function1ds.size( ); ++i1 ) m_functions1d[i1] = parseFunction1d_d1( function1ds[i1] );
993}
LUPI_HOST Function1d_d1 * parseFunction1d_d1(Transporting::MC const &a_settings, GIDI::Suite const &a_suite)
LUPI_HOST_DEVICE Interpolation GIDI2MCGIDI_interpolation(ptwXY_interpolation a_interpolation)

◆ ~XYs2d()

LUPI_HOST_DEVICE MCGIDI::Functions::XYs2d::~XYs2d ( )

Definition at line 998 of file MCGIDI_functions.cc.

998 {
999
1000 for( std::size_t i1 = 0; i1 < m_functions1d.size( ); ++i1 ) delete m_functions1d[i1];
1001}

Member Function Documentation

◆ evaluate()

LUPI_HOST_DEVICE double MCGIDI::Functions::XYs2d::evaluate ( double a_x2,
double a_x1 ) const

Definition at line 1005 of file MCGIDI_functions.cc.

1005 {
1006
1007 int intLower = binarySearchVector( a_x2, m_Xs );
1008 double evaluatedValue = 0.0;
1009
1010 if( intLower < 0 ) {
1011 if( intLower == -1 ) { /* X2 > last value of Xs. */
1012 evaluatedValue = m_functions1d.back( )->evaluate( a_x1 ); }
1013 else { /* X2 < first value of Xs. */
1014 evaluatedValue = m_functions1d[0]->evaluate( a_x1 );
1015 } }
1016 else {
1017 std::size_t lower = static_cast<std::size_t>( intLower );
1018 double y1 = m_functions1d[lower]->evaluate( a_x1 );
1019
1021 evaluatedValue = y1; }
1022 else {
1023 double x1 = m_Xs[lower];
1024 double x2 = m_Xs[lower+1];
1025 double y2 = m_functions1d[lower+1]->evaluate( a_x1 );
1026
1028 double fraction = ( x2 - a_x2 ) / ( x2 - x1 );
1029 evaluatedValue = fraction * y1 + ( 1 - fraction ) * y2; }
1030 else if( interpolation( ) == Interpolation::LINLOG ) {
1031 double fraction = log( x2 / a_x2 ) / log( x2 / x1 );
1032 evaluatedValue = fraction * y1 + ( 1 - fraction ) * y2; }
1033 else if( interpolation( ) == Interpolation::LOGLIN ) {
1034 double fraction = ( x2 - a_x2 ) / ( x2 - x1 );
1035 evaluatedValue = exp( fraction * log( y1 ) + ( 1 - fraction ) * log( y2 ) ); }
1036 else if( interpolation( ) == Interpolation::LOGLOG ) {
1037 double fraction = log( x2 / a_x2 ) / log( x2 / x1 );
1038 evaluatedValue = exp( fraction * log( y1 ) + ( 1 - fraction ) * log( y2 ) ); }
1039 else {
1040 LUPI_THROW( "XYs2d::evaluate: unsupport interpolation." );
1041 }
1042 }
1043 }
1044
1045 return( evaluatedValue );
1046}
#define LUPI_THROW(arg)
LUPI_HOST_DEVICE Interpolation interpolation() const
LUPI_HOST_DEVICE int binarySearchVector(double a_x, Vector< double > const &a_Xs, bool a_boundIndex=false)
Definition MCGIDI.hpp:318

◆ serialize()

LUPI_HOST_DEVICE void MCGIDI::Functions::XYs2d::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 1056 of file MCGIDI_functions.cc.

1056 {
1057
1058 Function2d::serialize( a_buffer, a_mode );
1059 DATA_MEMBER_VECTOR_DOUBLE( m_Xs, a_buffer, a_mode );
1060
1061 std::size_t vectorSize = m_functions1d.size( );
1062 int vectorSizeInt = (int) vectorSize;
1063 DATA_MEMBER_INT( vectorSizeInt, a_buffer, a_mode );
1064 vectorSize = (std::size_t) vectorSizeInt;
1065 if( a_mode == LUPI::DataBuffer::Mode::Unpack ) m_functions1d.resize( vectorSize, &a_buffer.m_placement );
1066 if( a_mode == LUPI::DataBuffer::Mode::Memory ) a_buffer.m_placement += m_functions1d.internalSize();
1067 for( std::size_t vectorIndex = 0; vectorIndex < vectorSize; ++vectorIndex ) {
1068 m_functions1d[vectorIndex] = serializeFunction1d_d1( a_buffer, a_mode, m_functions1d[vectorIndex] );
1069 }
1070}
#define DATA_MEMBER_VECTOR_DOUBLE(member, buf, mode)
#define DATA_MEMBER_INT( member, buf, mode)
LUPI_HOST_DEVICE void serialize(LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)
LUPI_HOST_DEVICE Functions::Function1d_d1 * serializeFunction1d_d1(LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode, Functions::Function1d_d1 *a_function1d)

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