Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
GIDI_constant1d.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 Constant1d
18 * Class for the GNDS <**constant1d**> node.
19 */
20
21/* *********************************************************************************************************//**
22 *
23 * @param a_axes [in] The axes to copy for *this*.
24 * @param a_value [in] The GNDS **value** for *this*.
25 * @param a_domainMin [in] The minimum value for the domain.
26 * @param a_domainMax [in] The maximum value for the domain.
27 * @param a_index [in] Currently not used.
28 * @param a_outerDomainValue [in] If embedded in a higher dimensional function, the value of the domain of the next higher dimension.
29 ***********************************************************************************************************/
30
31Constant1d::Constant1d( Axes const &a_axes, double a_value, double a_domainMin, double a_domainMax, int a_index, double a_outerDomainValue ) :
32 Function1dForm( GIDI_constant1dChars, FormType::constant1d, a_axes, ptwXY_interpolationLinLin, a_index, a_outerDomainValue ),
33 m_value( a_value ),
34 m_domainMin( a_domainMin ),
35 m_domainMax( a_domainMax ) {
36
37}
38
39/* *********************************************************************************************************//**
40 *
41 * @param a_construction [in] Used to pass user options for parsing.
42 * @param a_node [in] The **HAPI::Node** to be parsed and used to construct the XYs2d.
43 * @param a_setupInfo [in] Information create my the Protare constructor to help in parsing.
44 * @param a_parent [in] The parent GIDI::Suite.
45 ***********************************************************************************************************/
46
47Constant1d::Constant1d( Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, Suite *a_parent ) :
48 Function1dForm( a_construction, a_node, a_setupInfo, FormType::constant1d, a_parent ),
49 m_value( a_node.attribute( GIDI_valueChars ).as_double( ) ),
50 m_domainMin( a_node.attribute( GIDI_domainMinChars ).as_double( ) ),
51 m_domainMax( a_node.attribute( GIDI_domainMaxChars ).as_double( ) ) {
52
53}
54
55/* *********************************************************************************************************//**
56 ***********************************************************************************************************/
57
61
62/* *********************************************************************************************************//**
63 * Returns the value of the constant function.
64 *
65 * @param a_x1 [in] This is ignored a the function is a constant.
66 * @return The value of the constant.
67 ***********************************************************************************************************/
68
69double Constant1d::evaluate( LUPI_maybeUnused double a_x1 ) const {
70
71// FIXME - Do we need to check domain?
72 return( m_value );
73}
74
75/* *********************************************************************************************************//**
76 * Evaluates *this* at the X-values in *a_Xs*[*a_offset*:] and adds the results to *a_results*[*a_offset*:].
77 * *a_Xs* and *a_results* must be the same size otherwise a throw is executed.
78 *
79 * @param a_offset [in] The offset in *a_Xs* to start.
80 * @param a_Xs [in] The list of domain values to evaluate *this* at.
81 * @param a_results [in] The list whose values are added to by the Y-values of *this*.
82 * @param a_scaleFactor [in] A factor applied to each evaluation before it is added to *a_results*.
83 ***********************************************************************************************************/
84
85void Constant1d::mapToXsAndAdd( std::size_t a_offset, std::vector<double> const &a_Xs, std::vector<double> &a_results, double a_scaleFactor ) const {
86
87 if( a_Xs.size( ) != a_results.size( ) ) throw Exception( "Constant1d::mapToXsAndAdd: a_Xs.size( ) != a_results.size( )." );
88
89 for( std::size_t index = a_offset; index < a_Xs.size( ); ++index ) {
90 a_results[index] += a_scaleFactor * m_value;
91 }
92}
93
94/* *********************************************************************************************************//**
95 * This methods returns an XYs1d representation of *this*. The calling function owns the created instance and is responible
96 * for freeing it.
97 *
98 * @param a_asLinlin [in] This argument is not used but retained to make the methods API at same as other asXYs1d functions.
99 * @param a_accuracy [in] This argument is not used but retained to make the methods API at same as other asXYs1d functions.
100 * @param a_lowerEps [in] This argument is not used but retained to make the methods API at same as other asXYs1d functions.
101 * @param a_upperEps [in] This argument is not used but retained to make the methods API at same as other asXYs1d functions.
102 *
103 * @return A pointer to an XYs1d instance that must be freed by the calling function.
104 ***********************************************************************************************************/
105
106XYs1d *Constant1d::asXYs1d( LUPI_maybeUnused bool a_asLinlin, LUPI_maybeUnused double a_accuracy, LUPI_maybeUnused double a_lowerEps, LUPI_maybeUnused double a_upperEps ) const {
107
108 std::vector<double> xys( 4 );
109
110 xys[0] = m_domainMin;
111 xys[1] = m_value;
112 xys[2] = m_domainMax;
113 xys[3] = m_value;
114
115 return( new XYs1d( axes( ), ptwXY_interpolationLinLin, xys ) );
116}
117
118/* *********************************************************************************************************//**
119 * Fills the argument *a_writeInfo* with the XML lines that represent *this*. Recursively enters each sub-node.
120 *
121 * @param a_writeInfo [in/out] Instance containing incremental indentation and other information and stores the appended lines.
122 * @param a_indent [in] The amount to indent *this* node.
123 * @param a_embedded [in] If *true*, *this* function is embedded in a higher dimensional function.
124 * @param a_inRegions [in] If *true*, *this* is in a Regions1d container.
125 ***********************************************************************************************************/
126
127void Constant1d::toXMLList_func( GUPI::WriteInfo &a_writeInfo, std::string const &a_indent, bool a_embedded, bool a_inRegions ) const {
128
129 std::string indent2 = a_writeInfo.incrementalIndent( a_indent );
130 std::string attributes;
131
132 if( a_embedded ) {
134 else {
135 if( a_inRegions ) {
136 attributes = a_writeInfo.addAttribute( GIDI_indexChars, intToString( index( ) ) ); }
137 else {
138 attributes = a_writeInfo.addAttribute( GIDI_labelChars, label( ) );
139 }
140 }
141
142 attributes += a_writeInfo.addAttribute( GIDI_valueChars, LUPI::Misc::doubleToShortestString( m_value ) );
143 attributes += a_writeInfo.addAttribute( GIDI_domainMinChars, LUPI::Misc::doubleToShortestString( m_domainMin ) );
144 attributes += a_writeInfo.addAttribute( GIDI_domainMaxChars, LUPI::Misc::doubleToShortestString( m_domainMax ) );
145
146 a_writeInfo.addNodeStarter( a_indent, moniker( ), attributes );
147 axes( ).toXMLList( a_writeInfo, indent2 );
148 a_writeInfo.addNodeEnder( moniker( ) );
149}
150
151} // End namespace Functions.
152
153} // End namespace GIDI.
#define GIDI_outerDomainValueChars
Definition GIDI.hpp:436
#define GIDI_valueChars
Definition GIDI.hpp:445
#define GIDI_labelChars
Definition GIDI.hpp:438
#define GIDI_indexChars
Definition GIDI.hpp:437
#define GIDI_domainMaxChars
Definition GIDI.hpp:447
#define GIDI_constant1dChars
Definition GIDI.hpp:287
#define GIDI_domainMinChars
Definition GIDI.hpp:446
#define LUPI_maybeUnused
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 evaluate(double a_x1) const
Constant1d(Axes const &a_axes, double value, double a_domainMin, double a_domainMax, int a_index=0, double a_outerDomainValue=0.0)
void toXMLList_func(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent, bool a_embedded, bool a_inRegions) const
XYs1d * asXYs1d(bool a_asLinlin, double a_accuray, double a_lowerEps, double a_upperEps) const
void mapToXsAndAdd(std::size_t a_offset, std::vector< double > const &a_Xs, std::vector< double > &a_results, double a_scaleFactor) const
Function1dForm(std::string const &a_moniker, FormType a_type, ptwXY_interpolation a_interpolation, int a_index, double a_outerDomainValue)
Definition GIDI_form.cc:348
Axes const & axes() const
Definition GIDI.hpp:1012
double outerDomainValue() const
Definition GIDI.hpp:1010
std::string const & moniker() const
Definition GUPI.hpp:102
std::string attribute() const
Definition GUPI.hpp:107
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
Definition GIDI.hpp:32
FormType
Definition GIDI.hpp:118
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
@ ptwXY_interpolationLinLin
Definition ptwXY.h:37