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

#include <GIDI.hpp>

Inheritance diagram for GIDI::Functions::Polynomial1d:

Public Member Functions

 Polynomial1d (Axes const &a_axes, double a_domainMin, double a_domainMax, std::vector< double > const &a_coefficients, int a_index=0, double a_outerDomainValue=0.0)
 Polynomial1d (Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, Suite *a_parent)
 Polynomial1d (Polynomial1d const &a_polynomial1d)
 ~Polynomial1d ()
double domainMin () const
double domainMax () const
std::vector< double > const & coefficients () const
double evaluate (double a_x1) const
void mapToXsAndAdd (std::size_t a_offset, std::vector< double > const &a_Xs, std::vector< double > &a_results, double a_scaleFactor) const
XYs1dasXYs1d (bool a_asLinlin, double a_accuray, double a_lowerEps, double a_upperEps) const
void toXMLList_func (GUPI::WriteInfo &a_writeInfo, std::string const &a_indent, bool a_embedded, bool a_inRegions) const
Public Member Functions inherited from GIDI::Functions::Function1dForm
 Function1dForm (std::string const &a_moniker, FormType a_type, ptwXY_interpolation a_interpolation, int a_index, double a_outerDomainValue)
 Function1dForm (std::string const &a_moniker, FormType a_type, Axes const &a_axes, ptwXY_interpolation a_interpolation, int a_index, double a_outerDomainValue)
 Function1dForm (Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, FormType a_type, Suite *a_suite=nullptr)
 Function1dForm (Function1dForm const &a_form)
 ~Function1dForm ()
Function1dFormoperator= (Function1dForm const &a_rhs)
virtual void write (FILE *a_file, std::string const &a_format) const
void print (std::string const &a_format) const
Public Member Functions inherited from GIDI::Functions::FunctionForm
 FunctionForm (std::string const &a_moniker, FormType a_type, int a_dimension, ptwXY_interpolation a_interpolation, int a_index, double a_outerDomainValue)
 FunctionForm (std::string const &a_moniker, FormType a_type, int a_dimension, Axes const &a_axes, ptwXY_interpolation a_interpolation, int a_index, double a_outerDomainValue)
 FunctionForm (Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, FormType a_type, int a_dimension, Suite *a_suite=nullptr)
 FunctionForm (FunctionForm const &a_form)
 ~FunctionForm ()
FunctionFormoperator= (FunctionForm const &a_rhs)
int dimension () const
int index () const
double outerDomainValue () const
void setOuterDomainValue (double a_outerDomainValue)
Axes const & axes () const
Axesaxes ()
ptwXY_interpolation interpolation () const
void setInterpolation (ptwXY_interpolation a_interpolation)
std::string interpolationString () const
void toXMLList (GUPI::WriteInfo &a_writeInfo, std::string const &a_indent) const
Public Member Functions inherited from GIDI::Form
 Form (FormType a_type)
 Form (std::string const &a_moniker, FormType a_type, std::string const &a_label)
 Form (HAPI::Node const &a_node, SetupInfo &a_setupInfo, FormType a_type, Suite *a_suite=nullptr)
 Form (Form const &a_form)
virtual ~Form ()
Formoperator= (Form const &a_rhs)
Suiteparent () const
std::string const & label () const
void setLabel (std::string const &a_label)
virtual std::string actualMoniker () const
std::string const & keyName () const
void setKeyName (std::string const &a_keyName)
std::string const & keyValue () const
virtual void setKeyValue (std::string const &a_keyName) const
FormType type () const
Form const * sibling (std::string a_label) const
GUPI::AncestryfindInAncestry3 (LUPI_maybeUnused std::string const &a_item)
GUPI::Ancestry const * findInAncestry3 (LUPI_maybeUnused std::string const &a_item) const
std::string xlinkItemKey () const
Public Member Functions inherited from GUPI::Ancestry
 Ancestry (std::string const &a_moniker, std::string const &a_attribute="")
virtual ~Ancestry ()
Ancestryoperator= (Ancestry const &a_ancestry)
std::string const & moniker () const
void setMoniker (std::string const &a_moniker)
Ancestryancestor ()
Ancestry const * ancestor () const
void setAncestor (Ancestry *a_ancestor)
std::string attribute () const
Ancestryroot ()
Ancestry const * root () const
bool isChild (Ancestry *a_instance)
bool isParent (Ancestry *a_parent)
bool isRoot () const
AncestryfindInAncestry (std::string const &a_href)
Ancestry const * findInAncestry (std::string const &a_href) const
virtual AncestryfindInAncestry3 (std::string const &a_item)=0
virtual Ancestry const * findInAncestry3 (std::string const &a_item) const =0
virtual LUPI_HOST void serialize (LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)
std::string toXLink () const
void printXML () const

Additional Inherited Members

Static Public Member Functions inherited from GUPI::Ancestry
static std::string buildXLinkItemKey (std::string const &a_name, std::string const &a_key)

Detailed Description

Class for the GNDS <polynomial1d> node.

Definition at line 1181 of file GIDI.hpp.

Constructor & Destructor Documentation

◆ Polynomial1d() [1/3]

GIDI::Functions::Polynomial1d::Polynomial1d ( Axes const & a_axes,
double a_domainMin,
double a_domainMax,
std::vector< double > const & a_coefficients,
int a_index = 0,
double a_outerDomainValue = 0.0 )
Parameters
a_axes[in] The axes to copy for this.
a_domainMin[in] The minimum value for the domain.
a_domainMax[in] The maximum value for the domain.
a_coefficients[in] The coefficients representing the polynomial.
a_index[in] Currently not used.
a_outerDomainValue[in] If embedded in a higher dimensional function, the value of the domain of the next higher dimension.

Definition at line 50 of file GIDI_polynomial1d.cc.

50 :
52 m_domainMin( a_domainMin ),
53 m_domainMax( a_domainMax ),
54 m_coefficients( a_coefficients ) {
55
56}
#define GIDI_polynomial1dChars
Definition GIDI.hpp:290
Function1dForm(std::string const &a_moniker, FormType a_type, ptwXY_interpolation a_interpolation, int a_index, double a_outerDomainValue)
Definition GIDI_form.cc:348
@ ptwXY_interpolationLinLin
Definition ptwXY.h:37

Referenced by asXYs1d(), and Polynomial1d().

◆ Polynomial1d() [2/3]

GIDI::Functions::Polynomial1d::Polynomial1d ( Construction::Settings const & a_construction,
HAPI::Node const & a_node,
SetupInfo & a_setupInfo,
Suite * a_parent )
Parameters
a_construction[in] Used to pass user options to the constructor.
a_node[in] The HAPI::Node to be parsed and used to construct the XYs2d.
a_setupInfo[in] Information create my the Protare constructor to help in parsing.
a_parent[in] The parent GIDI::Suite.

Definition at line 65 of file GIDI_polynomial1d.cc.

65 :
66 Function1dForm( a_construction, a_node, a_setupInfo, FormType::polynomial1d, a_parent ),
67 m_domainMin( a_node.attribute( GIDI_domainMinChars ).as_double( ) ),
68 m_domainMax( a_node.attribute( GIDI_domainMaxChars ).as_double( ) ) {
69
70 nf_Buffer<double> coeff;
71 parseValuesOfDoubles( a_construction, a_node.child( GIDI_valuesChars ), a_setupInfo, coeff );
72 m_coefficients = coeff.vector();
73}
#define GIDI_valuesChars
Definition GIDI.hpp:260
#define GIDI_domainMaxChars
Definition GIDI.hpp:447
#define GIDI_domainMinChars
Definition GIDI.hpp:446
void parseValuesOfDoubles(Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, nf_Buffer< double > &a_vector)
Definition GIDI_misc.cc:88

◆ Polynomial1d() [3/3]

GIDI::Functions::Polynomial1d::Polynomial1d ( Polynomial1d const & a_polynomial1d)

The Polynomial1d copy constructor.

Parameters
a_polynomial1d[in] The Polynomial1d instance to copy.

Definition at line 81 of file GIDI_polynomial1d.cc.

81 :
82 Function1dForm( a_polynomial1d ),
83 m_domainMin( a_polynomial1d.domainMin( ) ),
84 m_domainMax( a_polynomial1d.domainMax( ) ),
85 m_coefficients( a_polynomial1d.coefficients( ) ) {
86
87}

◆ ~Polynomial1d()

GIDI::Functions::Polynomial1d::~Polynomial1d ( )

Definition at line 92 of file GIDI_polynomial1d.cc.

92 {
93
94}

Member Function Documentation

◆ asXYs1d()

XYs1d * GIDI::Functions::Polynomial1d::asXYs1d ( bool a_asLinlin,
double a_accuray,
double a_lowerEps,
double a_upperEps ) const
virtual

This methods returns an XYs1d representation of this. The calling function owns the created instance and is responible for freeing it.

Parameters
a_asLinlin[in] This argument is not used but retained to make the methods API at same as other asXYs1d functions.
a_accuracy[in] The accuracy use to convert the data to lin=lin interpolation if needed.
a_lowerEps[in] This argument is not used but retained to make the methods API at same as other asXYs1d functions.
a_upperEps[in] This argument is not used but retained to make the methods API at same as other asXYs1d functions.
Returns
A pointer to an XYs1d instance that must be freed by the calling function.

Reimplemented from GIDI::Functions::Function1dForm.

Definition at line 159 of file GIDI_polynomial1d.cc.

159 {
160
161 XYs1d *xys1d = nullptr;
162
163 if( m_coefficients.size( ) < 3 ) {
164 double offset = 0.0, slope = 0.0;
165 if( m_coefficients.size( ) > 0 ) {
166 offset = m_coefficients[0];
167 if( m_coefficients.size( ) == 2 ) slope = m_coefficients[1];
168 }
169
170 std::vector<double> xs( 2 );
171 xs[0] = domainMin( );
172 xs[1] = domainMax( );
173
174 std::vector<double> ys( 2 );
175 ys[0] = slope * xs[0] + offset;
176 ys[1] = slope * xs[1] + offset;
177
178 xys1d = new XYs1d( axes( ), ptwXY_interpolationLinLin, xs, ys ); }
179 else {
180 double xs[2] = { domainMin( ), domainMax( ) };
181 ptwXYPoints *ptwXYPoints1 = ptwXY_createFromFunction( nullptr, 2, xs, asXYs1d_callback, const_cast<Polynomial1d *>( this ), a_accuracy, 1, 12 );
182 if( ptwXYPoints1 != nullptr ) xys1d = new XYs1d( axes( ), ptwXYPoints1 );
183 }
184
185 return( xys1d );
186}
G4ThreadLocal T * G4GeomSplitter< T >::offset
Axes const & axes() const
Definition GIDI.hpp:1012
Polynomial1d(Axes const &a_axes, double a_domainMin, double a_domainMax, std::vector< double > const &a_coefficients, int a_index=0, double a_outerDomainValue=0.0)
ptwXYPoints * ptwXY_createFromFunction(statusMessageReporting *smr, int n, double *xs, ptwXY_createFromFunction_callback func, void *argList, double accuracy, int checkForRoots, int biSectionMax)
Definition ptwXY_misc.c:46
struct ptwXYPoints_s ptwXYPoints

◆ coefficients()

std::vector< double > const & GIDI::Functions::Polynomial1d::coefficients ( ) const
inline

Returns the value of the m_coefficients member.

Definition at line 1197 of file GIDI.hpp.

Referenced by Polynomial1d(), and MCGIDI::Functions::Polynomial1d::Polynomial1d().

◆ domainMax()

double GIDI::Functions::Polynomial1d::domainMax ( ) const
inlinevirtual

Returns the value of the m_domainMax member.

Implements GIDI::Functions::FunctionForm.

Definition at line 1195 of file GIDI.hpp.

Referenced by asXYs1d(), Polynomial1d(), and toXMLList_func().

◆ domainMin()

double GIDI::Functions::Polynomial1d::domainMin ( ) const
inlinevirtual

Returns the value of the m_domainMin member.

Implements GIDI::Functions::FunctionForm.

Definition at line 1194 of file GIDI.hpp.

Referenced by asXYs1d(), Polynomial1d(), and toXMLList_func().

◆ evaluate()

double GIDI::Functions::Polynomial1d::evaluate ( double a_x1) const
virtual

The value of the polynomial at the point a_x1.

Parameters
a_x1[in] Domain value to evaluate this at.
Returns
The value of the polynomial at the point a_x1.

Implements GIDI::Functions::Function1dForm.

Definition at line 103 of file GIDI_polynomial1d.cc.

103 {
104
105 double _value = 0;
106
107 if( a_x1 < m_domainMin ) return( 0.0 );
108 if( a_x1 > m_domainMax ) return( 0.0 );
109
110 for( std::vector<double>::const_reverse_iterator riter = m_coefficients.rbegin( ); riter != m_coefficients.rend( ); ++riter ) {
111 _value = *riter + _value * a_x1;
112 }
113 return( _value );
114}

Referenced by mapToXsAndAdd().

◆ mapToXsAndAdd()

void GIDI::Functions::Polynomial1d::mapToXsAndAdd ( std::size_t a_offset,
std::vector< double > const & a_Xs,
std::vector< double > & a_results,
double a_scaleFactor ) const
virtual

Evaluates this at the X-values in a_Xs[a_offset:] and adds the results to a_results[a_offset:]. a_Xs and a_results must be the same size otherwise a throw is executed.

Parameters
a_offset[in] The offset in a_Xs to start.
a_Xs[in] The list of domain values to evaluate this at.
a_results[in] The list whose values are added to by the Y-values of this.
a_scaleFactor[in] A factor applied to each evaluation before it is added to a_results.

Reimplemented from GIDI::Functions::Function1dForm.

Definition at line 126 of file GIDI_polynomial1d.cc.

126 {
127
128 if( a_Xs.size( ) != a_results.size( ) ) throw Exception( "Constant1d::mapToXsAndAdd: a_Xs.size( ) != a_results.size( )." );
129
130 std::size_t index = 0;
131 auto XsIter = a_Xs.begin( );
132
133 for( ; XsIter != a_Xs.end( ); ++XsIter, ++index ) {
134 if( a_offset == index ) break;
135 }
136
137 for( ; XsIter != a_Xs.end( ); ++XsIter, ++index ) {
138 if( *XsIter >= m_domainMin ) break;
139 }
140
141 for( ; XsIter != a_Xs.end( ); ++XsIter, ++index ) {
142 if( *XsIter > m_domainMax ) break;
143 a_results[index] += a_scaleFactor * evaluate( *XsIter );
144 }
145}
double evaluate(double a_x1) const

◆ toXMLList_func()

void GIDI::Functions::Polynomial1d::toXMLList_func ( GUPI::WriteInfo & a_writeInfo,
std::string const & a_indent,
bool a_embedded,
bool a_inRegions ) const
virtual

Fills the argument a_writeInfo with the XML lines that represent this. Recursively enters each sub-node.

Parameters
a_writeInfo[in/out] Instance containing incremental indentation and other information and stores the appended lines.
a_indent[in] The amount to indent this node.
a_embedded[in] If true, this function is embedded in a higher dimensional function.
a_inRegions[in] If true, this is in a Regions1d container.

Reimplemented from GIDI::Functions::FunctionForm.

Definition at line 197 of file GIDI_polynomial1d.cc.

197 {
198
199 std::string indent2 = a_writeInfo.incrementalIndent( a_indent );
200 std::string attributes;
201
202 if( a_embedded ) {
204 else {
205 if( a_inRegions ) {
206 attributes = a_writeInfo.addAttribute( GIDI_indexChars, intToString( index( ) ) ); }
207 else {
208 if( label( ) != "" ) attributes = a_writeInfo.addAttribute( GIDI_labelChars, label( ) );
209 }
210 }
211
214 a_writeInfo.addNodeStarter( a_indent, moniker( ), attributes );
215
216 axes( ).toXMLList( a_writeInfo, indent2 );
217 doublesToXMLList( a_writeInfo, indent2, m_coefficients );
218 a_writeInfo.addNodeEnder( moniker( ) );
219}
#define GIDI_outerDomainValueChars
Definition GIDI.hpp:436
#define GIDI_labelChars
Definition GIDI.hpp:438
#define GIDI_indexChars
Definition GIDI.hpp:437
void toXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent="") const
Definition GIDI_axes.cc:113
std::string const & label() const
Definition GIDI.hpp:658
double outerDomainValue() const
Definition GIDI.hpp:1010
std::string const & moniker() const
Definition GUPI.hpp:102
void addNodeEnder(std::string const &a_moniker)
Definition GUPI.hpp:59
std::string incrementalIndent(std::string const &indent)
Definition GUPI.hpp:52
void addNodeStarter(std::string const &indent, std::string const &a_moniker, std::string const &a_attributes="")
Definition GUPI.hpp:55
std::string addAttribute(std::string const &a_name, std::string const &a_value) const
Definition GUPI.hpp:60
void doublesToXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent, std::vector< double > const &a_values, std::size_t a_start=0, bool a_newLine=true, std::string const &a_valueType="")
Definition GIDI_misc.cc:180
std::string intToString(int a_value)
Definition GIDI_misc.cc:415
std::string doubleToShortestString(double a_value, int a_significantDigits=15, int a_favorEFormBy=0)
Definition LUPI_misc.cc:349

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