Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
GIDI_XYs3d.cc
Go to the documentation of this file.
1/*
2# <<BEGIN-copyright>>
3# Copyright 2019, Lawrence Livermore National Security, LLC.
4# This file is part of the gidiplus package (https://github.com/LLNL/gidiplus).
5# gidiplus is licensed under the MIT license (see https://opensource.org/licenses/MIT).
6# SPDX-License-Identifier: MIT
7# <<END-copyright>>
8*/
9
10#include "GIDI.hpp"
11#include <HAPI.hpp>
12
13namespace GIDI {
14
15namespace Functions {
16
17/*! \class XYs3d
18 * Class for the GNDS <**XYs3d**> node.
19 */
20
21/* *********************************************************************************************************//**
22 *
23 * @param a_construction [in] Used to pass user options for parsing.
24 * @param a_node [in] The **HAPI::Node** to be parsed and used to construct the XYs2d.
25 * @param a_setupInfo [in] Information create my the Protare constructor to help in parsing.
26 * @param a_parent [in] The parent GIDI::Suite.
27 ***********************************************************************************************************/
28
29XYs3d::XYs3d( Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, Suite *a_parent ) :
30 Function3dForm( a_construction, a_node, a_setupInfo, FormType::XYs3d, a_parent ),
31 m_interpolationQualifier( a_node.attribute_as_string( GIDI_interpolationQualifierChars ) ) {
32
34 data2dListParse( a_construction, a_node.child( GIDI_function2dsChars ), a_setupInfo, m_function2ds );
35 checkOuterDomainValues2d( m_function2ds, m_Xs );
36 return; // Need to add uncertainty parsing.
37 }
38
39 for( HAPI::Node child = a_node.first_child( ); !child.empty( ); child.to_next_sibling( ) ) {
40 std::string name( child.name( ) );
41
42 if( name == GIDI_axesChars ) continue;
43 if( name == GIDI_uncertaintyChars ) continue;
44
45 Function2dForm *_form = data2dParse( a_construction, child, a_setupInfo, nullptr );
46 if( _form == nullptr ) throw Exception( "XYs3d::XYs3d: data2dParse returned nullptr." );
47 if( m_Xs.size( ) > 0 ) {
48 if( _form->outerDomainValue( ) <= m_Xs[m_Xs.size( )-1] ) throw Exception( "XYs3d::XYs3d: next outerDomainValue <= current outerDomainValue." );
49 }
50 m_Xs.push_back( _form->outerDomainValue( ) );
51 m_function2ds.push_back( _form );
52 }
53
54}
55
56/* *********************************************************************************************************//**
57 * @param a_axes [in] The axes to copy for *this*.
58 * @param a_interpolation [in] The interpolation along the outer most independent axis and the dependent axis.
59 * @param a_index [in] Currently not used.
60 * @param a_outerDomainValue [in] If embedded in a higher dimensional function, the value of the domain of the next higher dimension.
61 ***********************************************************************************************************/
62
63XYs3d::XYs3d( Axes const &a_axes, ptwXY_interpolation a_interpolation, int a_index, double a_outerDomainValue ) :
64 Function3dForm( GIDI_XYs3dChars, FormType::XYs3d, a_axes, a_interpolation, a_index, a_outerDomainValue ),
65 m_interpolationQualifier( "" ) {
66
67}
68
69/* *********************************************************************************************************//**
70 ***********************************************************************************************************/
71
73
74 for( std::vector<Function2dForm *>::iterator iter = m_function2ds.begin( ); iter < m_function2ds.end( ); ++iter ) delete *iter;
75}
76
77/* *********************************************************************************************************//**
78 * Returns the domain minimum for the instance.
79 *
80 * @return The domain minimum for the instance.
81 ***********************************************************************************************************/
82
83double XYs3d::domainMin( ) const {
84
85 if( m_Xs.size( ) == 0 ) throw Exception( "XYs3d::domainMin: XYs3d has no 2d-functions" );
86 return( m_Xs[0] );
87}
88
89/* *********************************************************************************************************//**
90 * Returns the domain maximum for the instance.
91 *
92 * @return The domain maximum for the instance.
93 ***********************************************************************************************************/
94
95double XYs3d::domainMax( ) const {
96
97 if( m_Xs.size( ) == 0 ) throw Exception( "XYs3d::domainMax: XYs3d has no 2d-functions" );
98 return( m_Xs[m_Xs.size( )-1] );
99}
100
101/* *********************************************************************************************************//**
102 * Returns the value of the function *f(x3,x2,x1)* at the specified point *a_x3*, *a_x2* and *a_x1*.
103 *
104 * @param a_x3 [in] The value of the **x3** axis.
105 * @param a_x2 [in] The value of the **x2** axis.
106 * @param a_x1 [in] The value of the **x1** axis.
107 * @return The value of the function evaluated at *a_x3*, *a_x2* and *a_x1*.
108 ***********************************************************************************************************/
109
110double XYs3d::evaluate( double a_x3, double a_x2, double a_x1 ) const {
111
112 if( m_Xs.size( ) == 0 ) throw Exception( "XYs3d::evaluate: XYs3d has no 2d functions." );
113
114 long iX3 = binarySearchVector( a_x3, m_Xs );
115
116 if( iX3 < 0 ) {
117 if( iX3 == -1 ) { /* x3 > last value of Xs. */
118 return( m_function2ds.back( )->evaluate( a_x2, a_x1 ) );
119 }
120 return( m_function2ds[0]->evaluate( a_x2, a_x1 ) ); /* x3 < first value of Xs. */
121 }
122
123// Currently does not interpolate;
124 return( m_function2ds[static_cast<std::size_t>(iX3)]->evaluate( a_x2, a_x1 ) );
125}
126
127/* *********************************************************************************************************//**
128 * Appends *a_function2d* to the end of *this*.
129 *
130 * @param a_function2d [in] The 2d-function to append to *this*.
131 ***********************************************************************************************************/
132
133void XYs3d::append( Function2dForm *a_function2d ) {
134
135 if( m_function2ds.size( ) > 0 ) {
136 if( a_function2d->outerDomainValue( ) <= m_Xs.back( ) ) throw Exception( "XYs3d::append: outerDomainValue not greater than current maximum outer domain's value." );
137 }
138
139 m_Xs.push_back( a_function2d->outerDomainValue( ) );
140 m_function2ds.push_back( a_function2d );
141 a_function2d->setAncestor( this );
142}
143
144/* *********************************************************************************************************//**
145 * Fills the argument *a_writeInfo* with the XML lines that represent *this*. Recursively enters each sub-node.
146 *
147 * @param a_writeInfo [in/out] Instance containing incremental indentation and other information and stores the appended lines.
148 * @param a_indent [in] The amount to indent *this* node.
149 * @param a_embedded [in] If *true*, *this* function is embedded in a higher dimensional function.
150 * @param a_inRegions [in] If *true*, *this* is in a Regions2d container.
151 ***********************************************************************************************************/
152
153void XYs3d::toXMLList_func( GUPI::WriteInfo &a_writeInfo, std::string const &a_indent, bool a_embedded, bool a_inRegions ) const {
154
155 std::string indent2 = a_writeInfo.incrementalIndent( a_indent );
156 std::string attributes;
157
158 if( a_embedded ) {
160 else {
161 if( a_inRegions ) {
162 attributes = a_writeInfo.addAttribute( GIDI_indexChars, intToString( index( ) ) ); }
163 else {
164 if( label( ) != "" ) attributes = a_writeInfo.addAttribute( GIDI_labelChars, label( ) );
165 }
166 }
167
168 if( m_interpolationQualifier != "" ) attributes = a_writeInfo.addAttribute( GIDI_interpolationQualifierChars, m_interpolationQualifier );
169
170 a_writeInfo.addNodeStarter( a_indent, moniker( ), attributes );
171 axes( ).toXMLList( a_writeInfo, indent2 );
172 for( std::vector<Function2dForm *>::const_iterator iter = m_function2ds.begin( ); iter != m_function2ds.end( ); ++iter ) (*iter)->toXMLList_func( a_writeInfo, indent2, true, false );
173 a_writeInfo.addNodeEnder( moniker( ) );
174}
175
176} // End namespace Functions.
177
178} // End namespace GIDI.
#define GIDI_outerDomainValueChars
Definition GIDI.hpp:436
#define GIDI_labelChars
Definition GIDI.hpp:438
#define GIDI_indexChars
Definition GIDI.hpp:437
#define GIDI_interpolationQualifierChars
Definition GIDI.hpp:435
#define GIDI_XYs3dChars
Definition GIDI.hpp:316
#define GNDS_formatVersion_1_10Chars
Definition LUPI.hpp:48
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
Function3dForm(std::string const &a_moniker, FormType a_type, ptwXY_interpolation a_interpolation, int a_index, double a_outerDomainValue)
Axes const & axes() const
Definition GIDI.hpp:1012
double outerDomainValue() const
Definition GIDI.hpp:1010
double evaluate(double a_x3, double a_x2, double a_x1) const
void append(Function2dForm *a_function2d)
void toXMLList_func(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent, bool a_embedded, bool a_inRegions) const
double domainMin() const
Definition GIDI_XYs3d.cc:83
XYs3d(Axes const &a_axes, ptwXY_interpolation a_interpolation=ptwXY_interpolationLinLin, int a_index=0, double a_outerDomainValue=0.0)
Definition GIDI_XYs3d.cc:63
double domainMax() const
Definition GIDI_XYs3d.cc:95
LUPI::FormatVersion m_formatVersion
Definition GIDI.hpp:599
void setAncestor(Ancestry *a_ancestor)
Definition GUPI.hpp:106
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
bool empty() const
Definition HAPI_Node.cc:150
Node first_child() const
Definition HAPI_Node.cc:82
std::string const & format() const
Definition LUPI.hpp:74
Definition GIDI.hpp:32
FormType
Definition GIDI.hpp:118
long binarySearchVector(double a_x, std::vector< double > const &a_Xs)
Definition GIDI_misc.cc:33
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
enum ptwXY_interpolation_e ptwXY_interpolation