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

#include <GIDI.hpp>

Inheritance diagram for GIDI::Functions::Regions1d:

Public Member Functions

 Regions1d (Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, Suite *a_parent)
 ~Regions1d ()
std::size_t size () const
Function1dForm const * operator[] (std::size_t a_index) const
double domainMin () const
double domainMax () const
void append (Function1dForm *a_function)
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
std::vector< double > const & Xs () const
std::vector< Function1dForm * > const & function1ds () const
std::vector< Function1dForm * > & function1ds ()
void toXMLList_func (GUPI::WriteInfo &a_writeInfo, std::string const &a_indent, bool a_embedded, bool a_inRegions) const
void write (FILE *a_file, std::string const &a_format) 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)
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 <regions1d> node.

Definition at line 1325 of file GIDI.hpp.

Constructor & Destructor Documentation

◆ Regions1d()

GIDI::Functions::Regions1d::Regions1d ( 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 52 of file GIDI_regions1d.cc.

52 :
53 Function1dForm( a_construction, a_node, a_setupInfo, FormType::regions1d, a_parent ) {
54
55 if( a_setupInfo.m_formatVersion.format( ) != GNDS_formatVersion_1_10Chars ) {
56 data1dListParse( a_construction, a_node.child( GIDI_function1dsChars ), a_setupInfo, m_function1ds );
57 checkSequentialDomainLimits1d( m_function1ds, m_Xs );
58 return; // Need to add uncertainty parsing.
59 }
60
61 for( HAPI::Node child = a_node.first_child( ); !child.empty( ); child.to_next_sibling( ) ) {
62 std::string name( child.name( ) );
63
64 if( name == GIDI_axesChars ) continue;
65 if( name == GIDI_uncertaintyChars ) continue;
66
67 Function1dForm *_form = data1dParse( a_construction, child, a_setupInfo, nullptr );
68 if( _form == nullptr ) throw Exception( "Regions1d::Regions1d: data1dParse returned nullptr." );
69 append( _form );
70 }
71}
#define GIDI_axesChars
Definition GIDI.hpp:382
#define GIDI_uncertaintyChars
Definition GIDI.hpp:389
#define GIDI_function1dsChars
Definition GIDI.hpp:387
#define GNDS_formatVersion_1_10Chars
Definition LUPI.hpp:48
Function1dForm(std::string const &a_moniker, FormType a_type, ptwXY_interpolation a_interpolation, int a_index, double a_outerDomainValue)
Definition GIDI_form.cc:348
void append(Function1dForm *a_function)
const char * name(G4int ptype)
Functions::Function1dForm * data1dParse(Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, Suite *parent)
void data1dListParse(Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, std::vector< Functions::Function1dForm * > &a_function1ds)
void checkSequentialDomainLimits1d(std::vector< Functions::Function1dForm * > &a_functions, std::vector< double > &a_Xs)

◆ ~Regions1d()

GIDI::Functions::Regions1d::~Regions1d ( )

Definition at line 76 of file GIDI_regions1d.cc.

76 {
77
78 for( std::vector<Function1dForm *>::iterator iter = m_function1ds.begin( ); iter < m_function1ds.end( ); ++iter ) delete *iter;
79}

Member Function Documentation

◆ append()

void GIDI::Functions::Regions1d::append ( Function1dForm * a_function)

Appends the 1d function a_function to the region.

Parameters
a_function[in] The 1d function (i.e., 1d region) to append to the Regions1d.

Definition at line 111 of file GIDI_regions1d.cc.

111 {
112
113 if( dimension( ) != a_function->dimension( ) ) throw Exception( "Regions1d::append: dimensions differ." );
114
115 double _domainMin = a_function->domainMin( ), _domainMax = a_function->domainMax( );
116
117 if( m_Xs.size( ) == 0 ) {
118 m_Xs.push_back( _domainMin ); }
119 else {
120 if( m_Xs.back( ) != _domainMin ) throw Exception( "Regions1d::append: regions do not abut." );
121 }
122
123 m_Xs.push_back( _domainMax );
124 m_function1ds.push_back( a_function );
125}

◆ asXYs1d()

XYs1d * GIDI::Functions::Regions1d::asXYs1d ( bool a_asLinlin,
double a_accuracy,
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] If true, the inpolatation of the returned XYs1d instance will always be lin-lin. Otherwise, the interpolation depends on the child 1d functions.
a_accuracy[in] The accuracy use to convert the data to lin=lin interpolation if needed.
a_lowerEps[in] The relative domain ammount to put a point below a boundary between two regions.
a_upperEps[in] The relative domain ammount to put a point above a boundary between two regions.
Returns
A pointer to an XYs1d instance that must be freed by the calling function.

Reimplemented from GIDI::Functions::Function1dForm.

Definition at line 181 of file GIDI_regions1d.cc.

181 {
182
183 XYs1d *xys1d1 = nullptr, *xys1d2 = nullptr;
184
185 if( a_lowerEps < 1e-14 ) a_lowerEps = 0.0; // 1e-14 should be a global parameter.
186 if( a_upperEps < 1e-14 ) a_upperEps = 0.0;
187
188 if( !a_asLinlin ) {
189 bool firstRegion = true;
191 for( auto regionIter = m_function1ds.begin( ); regionIter != m_function1ds.end( ); ++regionIter ) {
192 if( (*regionIter)->moniker( ) == GIDI_XYs1dChars ) {
193 xys1d2 = static_cast<XYs1d *>( *regionIter );
194 if( firstRegion ) interpolation2 = ptwXY_getInterpolation( xys1d2->ptwXY( ) );
195 if( interpolation2 != ptwXY_getInterpolation( xys1d2->ptwXY( ) ) ) {
196 a_asLinlin = true;
197 break;
198 } }
199 else {
200 a_asLinlin = true;
201 break;
202 }
203 }
204 }
205
206 std::vector<double> xs;
207 std::vector<double> ys;
208
209 for( auto regionIter = m_function1ds.begin( ); regionIter != m_function1ds.end( ); ++regionIter ) {
210 xys1d2 = (*regionIter)->asXYs1d( a_asLinlin, a_accuracy, a_lowerEps, a_upperEps );
211 if( xys1d2 == nullptr ) {
212 delete xys1d1;
213 return( nullptr );
214 }
215
216 std::vector<double> xs2( xys1d2->xs( ) );
217 if( xs2.size( ) < 2 ) continue;
218
219 std::size_t xySize = xs.size( );
220 std::vector<double> ys2( xys1d2->ys( ) );
221 if( xySize > 0 ) {
222 double y1u = ys.back( );
223 double y2l = ys2[0];
224
225 if( y1u == y2l ) { // Simple, just remove last point in xs and ys.
226 xs.resize( xySize - 1 );
227 ys.resize( xySize - 1 ); }
228 else {
229 bool addLower = false, addUpper = false;
230 double x1l = xs[xySize-2];
231 double x1u = xs.back( );
232 double x2l = xs2[0];
233 double x2u = xs2[1];
234 double x1up = 0.0, x2lp= 0.0;
235
236 if( a_lowerEps != 0.0 ) {
237 double x1lp = getAdjustedX( x1l, 0.8 * a_lowerEps );
238 x1up = getAdjustedX( x1u, -a_lowerEps ); // Point to add in xs below xs.back() if room.
239
240 addLower = x1lp < x1up; // Only add if relative spacing between existing point is greater than 1.8 * a_lowerEps.
241 }
242
243 if( a_upperEps > 0 ) {
244 x2lp = getAdjustedX( x2l, a_upperEps ); // Point to add in xs2 above xs2[0] if room.
245 double x2up = getAdjustedX( x2u, 0.8 * -a_upperEps );
246
247 addUpper = x2lp < x2up; // Only add if relative spacing between existing point is greater than 1.8 * a_upperEps.
248 }
249
250 if( addLower ) {
251 if( addUpper ) {
252 xs.back( ) = x1up;
253 ys.back( ) = xys1d1->evaluate( x1up );
254 xs.push_back( x1u );
255 ys.push_back( 0.5 * ( y1u + y2l ) );
256 xs2[0] = x2lp;
257 ys2[0] = xys1d2->evaluate( x2lp ); }
258 else {
259 xs.back( ) = x1up;
260 ys.back( ) = xys1d1->evaluate( x1up );
261 } }
262 else if( addUpper ) {
263 xs2[0] = x2lp;
264 ys2[0] = xys1d2->evaluate( x2lp ); }
265 else {
266 ys2[0] = 0.5 * ( y1u + y2l );
267 xs.resize( xySize - 1 );
268 ys.resize( xySize - 1 );
269 }
270 }
271 }
272 xs.insert( xs.end( ), xs2.begin( ), xs2.end( ) );
273 ys.insert( ys.end( ), ys2.begin( ), ys2.end( ) );
274 xys1d1 = xys1d2;
275 }
276 delete xys1d1;
277
278 return( new XYs1d( axes( ), ptwXY_interpolationLinLin, xs, ys ) );
279}
#define GIDI_XYs1dChars
Definition GIDI.hpp:288
Axes const & axes() const
Definition GIDI.hpp:1012
ptwXY_interpolation ptwXY_getInterpolation(ptwXYPoints *ptwXY)
Definition ptwXY_core.c:518
enum ptwXY_interpolation_e ptwXY_interpolation
@ ptwXY_interpolationLinLin
Definition ptwXY.h:37

◆ domainMax()

double GIDI::Functions::Regions1d::domainMax ( ) const
virtual

Returns the domain maximum for the instance.

Returns
The domain maximum for the instance.

Implements GIDI::Functions::FunctionForm.

Definition at line 99 of file GIDI_regions1d.cc.

99 {
100
101 if( m_Xs.size( ) == 0 ) throw Exception( "Regions1d::domainMax: Regions1d has not regions" );
102 return( m_Xs[m_Xs.size( )-1] );
103}

◆ domainMin()

double GIDI::Functions::Regions1d::domainMin ( ) const
virtual

Returns the domain minimum for the instance.

Returns
The domain minimum for the instance.

Implements GIDI::Functions::FunctionForm.

Definition at line 87 of file GIDI_regions1d.cc.

87 {
88
89 if( m_Xs.size( ) == 0 ) throw Exception( "Regions1d::domainMin: Regions1d has no regions" );
90 return( m_Xs[0] );
91}

◆ evaluate()

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

The value of y(x1) at the point a_x1.

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

Implements GIDI::Functions::Function1dForm.

Definition at line 135 of file GIDI_regions1d.cc.

135 {
136
137 if( m_Xs.size( ) == 0 ) throw Exception( "Regions1d::evaluate: Regions1d has not regions" );
138
139 long iX1 = binarySearchVector( a_x1, m_Xs );
140
141 if( iX1 < 0 ) {
142 if( iX1 == -1 ) { /* x1 > last value of Xs. */
143 return( m_function1ds.back( )->evaluate( a_x1 ) );
144 }
145 iX1 = 0; /* x1 < last value of Xs. */
146 }
147
148 return( m_function1ds[static_cast<std::size_t>(iX1)]->evaluate( a_x1 ) );
149}
double evaluate(double a_x1) const
long binarySearchVector(double a_x, std::vector< double > const &a_Xs)
Definition GIDI_misc.cc:33

Referenced by evaluate().

◆ function1ds() [1/2]

std::vector< Function1dForm * > & GIDI::Functions::Regions1d::function1ds ( )
inline

Returns the value of the m_function1ds member.

Definition at line 1348 of file GIDI.hpp.

◆ function1ds() [2/2]

std::vector< Function1dForm * > const & GIDI::Functions::Regions1d::function1ds ( ) const
inline

Returns the value of the m_function1ds member.

Definition at line 1347 of file GIDI.hpp.

◆ mapToXsAndAdd()

void GIDI::Functions::Regions1d::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 161 of file GIDI_regions1d.cc.

161 {
162
163 for( auto iter = m_function1ds.begin( ); iter < m_function1ds.end( ); ++iter ) {
164 (*iter)->mapToXsAndAdd( a_offset, a_Xs, a_results, a_scaleFactor );
165 }
166}

◆ operator[]()

Function1dForm const * GIDI::Functions::Regions1d::operator[] ( std::size_t a_index) const
inline

Returns the region at index a_index - 1.

Definition at line 1336 of file GIDI.hpp.

◆ size()

std::size_t GIDI::Functions::Regions1d::size ( ) const
inline

Returns number of regions.

Definition at line 1335 of file GIDI.hpp.

Referenced by MCGIDI::Functions::Regions1d::Regions1d().

◆ toXMLList_func()

void GIDI::Functions::Regions1d::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 290 of file GIDI_regions1d.cc.

290 {
291
292 std::string indent2 = a_writeInfo.incrementalIndent( a_indent );
293 std::string indent3 = a_writeInfo.incrementalIndent( indent2 );
294 std::string attributes;
295
296 if( a_embedded ) {
298 else {
299 if( a_inRegions ) {
300 attributes = a_writeInfo.addAttribute( GIDI_indexChars, intToString( index( ) ) ); }
301 else {
302 if( label( ) != "" ) attributes = a_writeInfo.addAttribute( GIDI_labelChars, label( ) );
303 }
304 }
305
306 a_writeInfo.addNodeStarter( a_indent, moniker( ), attributes );
307 axes( ).toXMLList( a_writeInfo, indent2 );
308 a_writeInfo.push_back( indent2 + "<function1ds>" );
309 for( std::vector<Function1dForm *>::const_iterator iter = m_function1ds.begin( ); iter != m_function1ds.end( ); ++iter ) (*iter)->toXMLList_func( a_writeInfo, indent3, false, true );
310 a_writeInfo.push_back( "</function1ds>" );
311 a_writeInfo.addNodeEnder( moniker( ) );
312}
#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 push_back(std::string const &a_line)
Definition GUPI.hpp:53
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
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

◆ write()

void GIDI::Functions::Regions1d::write ( FILE * a_file,
std::string const & a_format ) const
virtual

This method calls the write method for each region of this.

Parameters
a_file[in] The C FILE instance to write the data to.
a_format[in] The format string passed to each region's write method.

Reimplemented from GIDI::Functions::Function1dForm.

Definition at line 321 of file GIDI_regions1d.cc.

321 {
322
323 for( auto regionIter = m_function1ds.begin( ); regionIter != m_function1ds.end( ); ++regionIter ) {
324 (*regionIter)->write( a_file, a_format );
325 }
326}

◆ Xs()

std::vector< double > const & GIDI::Functions::Regions1d::Xs ( ) const
inline

Returns the value of the m_Xs member.

Definition at line 1346 of file GIDI.hpp.


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