Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
GIDI_XYs2d.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 XYs2d
18 * Class to store GNDS <**XYs2d**> node.
19 */
20
21/* *********************************************************************************************************//**
22 * @param a_axes [in] The axes to copy for *this*.
23 * @param a_interpolation [in] The interpolation along the outer most independent axis and the dependent axis.
24 * @param a_index [in] Currently not used.
25 * @param a_outerDomainValue [in] If embedded in a higher dimensional function, the value of the domain of the next higher dimension.
26 ***********************************************************************************************************/
27
28XYs2d::XYs2d( Axes const &a_axes, ptwXY_interpolation a_interpolation, int a_index, double a_outerDomainValue ) :
29 Function2dForm( GIDI_XYs2dChars, FormType::XYs2d, a_axes, a_interpolation, a_index, a_outerDomainValue ) {
30
31}
32
33/* *********************************************************************************************************//**
34 *
35 * @param a_construction [in] Used to pass user options for parsing.
36 * @param a_node [in] The **HAPI::Node** to be parsed and used to construct the XYs2d.
37 * @param a_setupInfo [in] Information create my the Protare constructor to help in parsing.
38 * @param a_parent [in] The parent GIDI::Suite.
39 ***********************************************************************************************************/
40
41XYs2d::XYs2d( Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, Suite *a_parent ) :
42 Function2dForm( a_construction, a_node, a_setupInfo, FormType::XYs2d, a_parent ),
43 m_interpolationQualifier( a_node.attribute_as_string( GIDI_interpolationQualifierChars ) ) {
44
46 data1dListParse( a_construction, a_node.child( GIDI_function1dsChars ), a_setupInfo, m_function1ds );
47 checkOuterDomainValues1d( m_function1ds, m_Xs );
48 return; // Need to add uncertainty parsing.
49 }
50
51 for( HAPI::Node child = a_node.first_child( ); !child.empty( ); child.to_next_sibling( ) ) {
52 std::string name( child.name( ) );
53
54 if( name == GIDI_axesChars ) continue;
55 if( name == GIDI_uncertaintyChars ) continue;
56
57 Function1dForm *_form = data1dParse( a_construction, child, a_setupInfo, nullptr );
58 if( _form == nullptr ) throw Exception( "XYs2d::XYs2d: data1dParse returned nullptr." );
59 if( m_Xs.size( ) > 0 ) {
60 if( _form->outerDomainValue( ) <= m_Xs[m_Xs.size( )-1] ) throw Exception( "XYs2d::XYs2d: next outerDomainValue <= current outerDomainValue." );
61 }
62 m_Xs.push_back( _form->outerDomainValue( ) );
63 m_function1ds.push_back( _form );
64 }
65
66}
67
68/* *********************************************************************************************************//**
69 ***********************************************************************************************************/
70
72
73 for( std::vector<Function1dForm *>::iterator iter = m_function1ds.begin( ); iter < m_function1ds.end( ); ++iter ) delete *iter;
74}
75
76/* *********************************************************************************************************//**
77 * Returns the domain minimum for the instance.
78 *
79 * @return The domain minimum for the instance.
80 ***********************************************************************************************************/
81
82double XYs2d::domainMin( ) const {
83
84 if( m_Xs.size( ) == 0 ) throw Exception( "XYs2d::domainMin: XYs2d has no 1d-functions" );
85 return( m_Xs[0] );
86}
87
88/* *********************************************************************************************************//**
89 * Returns the domain maximum for the instance.
90 *
91 * @return The domain maximum for the instance.
92 ***********************************************************************************************************/
93
94double XYs2d::domainMax( ) const {
95
96 if( m_Xs.size( ) == 0 ) throw Exception( "XYs2d::domainMax: XYs2d has no 1d-functions" );
97 return( m_Xs[m_Xs.size( )-1] );
98}
99
100/* *********************************************************************************************************//**
101 * Returns the value of the function *f(x2,x1)* at the specified point *a_x2* and *a_x1*.
102 *
103 * @param a_x2 [in] The value of the **x2** axis.
104 * @param a_x1 [in] The value of the **x1** axis.
105 * @return The value of the function evaluated at *a_x2* and *a_x1*.
106 ***********************************************************************************************************/
107
108double XYs2d::evaluate( double a_x2, double a_x1 ) const {
109
110 if( m_Xs.size( ) == 0 ) throw Exception( "XYs2d::evaluate: XYs2d has no 1d functions." );
111
112 long iX2 = binarySearchVector( a_x2, m_Xs );
113
114 if( iX2 < 0 ) {
115 if( iX2 == -1 ) { /* x2 > last value of Xs. */
116 return( m_function1ds.back( )->evaluate( a_x1 ) );
117 }
118 return( m_function1ds[0]->evaluate( a_x1 ) ); /* x2 < first value of Xs. */
119 }
120
121// Currently does not interpolate;
122 return( m_function1ds[static_cast<std::size_t>( iX2 )]->evaluate( a_x1 ) );
123}
124
125/* *********************************************************************************************************//**
126 * Fills the argument *a_writeInfo* with the XML lines that represent *this*. Recursively enters each sub-node.
127 *
128 * @param a_function1d [in] The 1-d function to append to *this*.
129 ***********************************************************************************************************/
130
131void XYs2d::append( Function1dForm *a_function1d ) {
132
133 if( m_function1ds.size( ) > 0 ) {
134 if( a_function1d->outerDomainValue( ) <= m_Xs.back( ) ) Exception( "XYs2d::append: next outerDomainValue <= current outerDomainValue." );
135 }
136
137 m_Xs.push_back( a_function1d->outerDomainValue( ) );
138 m_function1ds.push_back( a_function1d );
139 a_function1d->setAncestor( this );
140}
141
142/* *********************************************************************************************************//**
143 * Fills the argument *a_writeInfo* with the XML lines that represent *this*. Recursively enters each sub-node.
144 *
145 * @param a_writeInfo [in/out] Instance containing incremental indentation and other information and stores the appended lines.
146 * @param a_indent [in] The amount to indent *this* node.
147 * @param a_embedded [in] If *true*, *this* function is embedded in a higher dimensional function.
148 * @param a_inRegions [in] If *true*, *this* is in a Regions2d container.
149 ***********************************************************************************************************/
150
151void XYs2d::toXMLList_func( GUPI::WriteInfo &a_writeInfo, std::string const &a_indent, bool a_embedded, bool a_inRegions ) const {
152
153 std::string indent2 = a_writeInfo.incrementalIndent( a_indent );
154 std::string attributes;
155
156 if( a_embedded ) {
158 else {
159 if( a_inRegions ) {
160 attributes = a_writeInfo.addAttribute( GIDI_indexChars, intToString( index( ) ) ); }
161 else {
162 if( label( ) != "" ) attributes = a_writeInfo.addAttribute( GIDI_labelChars, label( ) );
163 }
164 }
165
166 if( m_interpolationQualifier != "" ) attributes = a_writeInfo.addAttribute( GIDI_interpolationQualifierChars, m_interpolationQualifier );
167
168 a_writeInfo.addNodeStarter( a_indent, moniker( ), attributes );
169 if( !a_embedded ) axes( ).toXMLList( a_writeInfo, indent2 );
170
171 for( std::vector<Function1dForm *>::const_iterator iter = m_function1ds.begin( ); iter != m_function1ds.end( ); ++iter ) (*iter)->toXMLList_func( a_writeInfo, indent2, true, false );
172 a_writeInfo.addNodeEnder( moniker( ) );
173}
174
175} // End namespace Functions.
176
177} // End namespace GIDI.
#define GIDI_XYs2dChars
Definition GIDI.hpp:300
#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 GNDS_formatVersion_1_10Chars
Definition LUPI.hpp:48
std::string const & label() const
Definition GIDI.hpp:658
Function2dForm(std::string const &a_moniker, FormType a_type, ptwXY_interpolation a_interpolation, int a_index, double a_outerDomainValue)
Definition GIDI_form.cc:476
double outerDomainValue() const
Definition GIDI.hpp:1010
double domainMin() const
Definition GIDI_XYs2d.cc:82
void append(Function1dForm *a_function1d)
double domainMax() const
Definition GIDI_XYs2d.cc:94
XYs2d(Axes const &a_axes, ptwXY_interpolation a_interpolation, int a_index=0, double a_outerDomainValue=0.0)
Definition GIDI_XYs2d.cc:28
double evaluate(double a_x2, double a_x1) const
void toXMLList_func(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent, bool a_embedded, bool a_inRegions) const
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