Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
GIDI_regions2d.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 Regions2d
18 * Class for the GNDS <**regions2d**> node.
19 */
20
21/* *********************************************************************************************************//**
22 *
23 * @param a_construction [in] Used to pass user options to the constructor.
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
29Regions2d::Regions2d( Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, Suite *a_parent ) :
30 Function2dForm( a_construction, a_node, a_setupInfo, FormType::regions2d, a_parent ) {
31
33 data2dListParse( a_construction, a_node.child( GIDI_function2dsChars ), a_setupInfo, m_function2ds );
34 checkSequentialDomainLimits2d( m_function2ds, m_Xs );
35 return; // Need to add uncertainty parsing.
36 }
37
38 for( HAPI::Node child = a_node.first_child( ); !child.empty( ); child.to_next_sibling( ) ) {
39 std::string name( child.name( ) );
40
41 if( name == GIDI_axesChars ) continue;
42 if( name == GIDI_uncertaintyChars ) continue;
43
44 Function2dForm *_form = data2dParse( a_construction, child, a_setupInfo, nullptr );
45 if( _form == nullptr ) throw Exception( "Regions2d::Regions2d: data2dParse returned nullptr." );
46 append( _form );
47 }
48}
49
50/* *********************************************************************************************************//**
51 ***********************************************************************************************************/
52
54
55 for( std::vector<Function2dForm *>::iterator iter = m_function2ds.begin( ); iter < m_function2ds.end( ); ++iter ) delete *iter;
56}
57
58/* *********************************************************************************************************//**
59 * Returns the domain minimum for the instance.
60 *
61 * @return The domain minimum for the instance.
62 ***********************************************************************************************************/
63
64double Regions2d::domainMin( ) const {
65
66 if( m_Xs.size( ) == 0 ) throw Exception( "Regions2d::domainMin: Regions2d has no regions" );
67 return( m_Xs[0] );
68}
69
70/* *********************************************************************************************************//**
71 * Returns the domain maximum for the instance.
72 *
73 * @return The domain maximum for the instance.
74 ***********************************************************************************************************/
75
76double Regions2d::domainMax( ) const {
77
78 if( m_Xs.size( ) == 0 ) throw Exception( "Regions2d::domainMax: Regions2d has no regions" );
79 return( m_Xs[m_Xs.size( )-1] );
80}
81
82/* *********************************************************************************************************//**
83 * Appends the 2d function *a_function* to the region.
84 *
85 ***********************************************************************************************************/
86
87void Regions2d::append( Function2dForm *a_function ) {
88
89 if( dimension( ) != a_function->dimension( ) ) throw Exception( "Regions2d::append: dimensions differ." );
90
91 double _domainMin = a_function->domainMin( ), _domainMax = a_function->domainMax( );
92
93 if( m_Xs.size( ) == 0 ) {
94 m_Xs.push_back( _domainMin ); }
95 else {
96 if( m_Xs.back( ) != _domainMin ) throw Exception( "Regions2d::append: regions do not abut." );
97 }
98
99 m_Xs.push_back( _domainMax );
100 m_function2ds.push_back( a_function );
101}
102
103/* *********************************************************************************************************//**
104 * The value of *y(x2,x1)* at the point *a_x2*, *a_x1*.
105 *
106 * @param a_x2 [in] The point for the *x2* axis.
107 * @param a_x1 [in] The point for the *x1* axis.
108 * @return The value of the function at the point *a_x2*, *a_x1*.
109 ***********************************************************************************************************/
110
111double Regions2d::evaluate( double a_x2, double a_x1 ) const {
112
113 if( m_Xs.size( ) == 0 ) throw Exception( "Regions2d::evaluate: regions2d has no regions" );
114
115 long iX1 = binarySearchVector( a_x1, m_Xs );
116
117 if( iX1 < 0 ) {
118 if( iX1 == -1 ) { /* x1 > last value of Xs. */
119 return( m_function2ds.back( )->evaluate( a_x2, a_x1 ) );
120 }
121 iX1 = 0; /* x1 < last value of Xs. */
122 }
123
124 return( m_function2ds[static_cast<std::size_t>(iX1)]->evaluate( a_x2, a_x1 ) );
125}
126
127/* *********************************************************************************************************//**
128 * Fills the argument *a_writeInfo* with the XML lines that represent *this*. Recursively enters each sub-node.
129 *
130 * @param a_writeInfo [in/out] Instance containing incremental indentation and other information and stores the appended lines.
131 * @param a_indent [in] The amount to indent *this* node.
132 * @param a_embedded [in] If *true*, *this* function is embedded in a higher dimensional function.
133 * @param a_inRegions [in] If *true*, *this* is in a Regions2d container.
134 ***********************************************************************************************************/
135
136void Regions2d::toXMLList_func( GUPI::WriteInfo &a_writeInfo, std::string const &a_indent, bool a_embedded, bool a_inRegions ) const {
137
138 std::string indent2 = a_writeInfo.incrementalIndent( a_indent );
139 std::string attributes;
140
141 if( a_embedded ) {
143 else {
144 if( a_inRegions ) {
145 attributes = a_writeInfo.addAttribute( GIDI_indexChars, intToString( index( ) ) ); }
146 else {
147 if( label( ) != "" ) attributes = a_writeInfo.addAttribute( GIDI_labelChars, label( ) );
148 }
149 }
150
151 a_writeInfo.addNodeStarter( a_indent, moniker( ), attributes );
152 axes( ).toXMLList( a_writeInfo, indent2 );
153 for( std::vector<Function2dForm *>::const_iterator iter = m_function2ds.begin( ); iter != m_function2ds.end( ); ++iter ) (*iter)->toXMLList_func( a_writeInfo, indent2, false, true );
154 a_writeInfo.addNodeEnder( moniker( ) );
155}
156
157} // End namespace Functions.
158
159} // 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 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
Function2dForm(std::string const &a_moniker, FormType a_type, ptwXY_interpolation a_interpolation, int a_index, double a_outerDomainValue)
Definition GIDI_form.cc:476
virtual double domainMax() const =0
Axes const & axes() const
Definition GIDI.hpp:1012
double outerDomainValue() const
Definition GIDI.hpp:1010
virtual double domainMin() const =0
void toXMLList_func(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent, bool a_embedded, bool a_inRegions) const
void append(Function2dForm *a_function)
double evaluate(double a_x2, double a_x1) const
Regions2d(Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, Suite *a_parent)
LUPI::FormatVersion m_formatVersion
Definition GIDI.hpp:599
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