Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
GIDI_Ys1d.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 <stdlib.h>
11#include "GIDI.hpp"
12#include <HAPI.hpp>
13
14namespace GIDI {
15
16namespace Functions {
17
18/*! \class Ys1d
19 * Class to store GNDS <**Ys1d**> node.
20 */
21
22/* *********************************************************************************************************//**
23 *
24 * @param a_axes [in] The axes to copy for *this*.
25 * @param a_interpolation [in] The interpolation flag.
26 * @param a_index [in] If imbedded in a two dimensional function, the index of this instance.
27 * @param a_outerDomainValue [in] If imbedded in a two dimensional function, the domain value for *x2*.
28 ***********************************************************************************************************/
29
30Ys1d::Ys1d( Axes const &a_axes, ptwXY_interpolation a_interpolation, int a_index, double a_outerDomainValue ) :
31 Function1dForm( GIDI_Ys1dChars, FormType::Ys1d, a_axes, a_interpolation, a_index, a_outerDomainValue ),
32 m_start( 0 ) {
33
34}
35
36/* *********************************************************************************************************//**
37 *
38 * @param a_axes [in] The axes to copy for *this*.
39 * @param a_interpolation [in] The interpolation flag.
40 * @param a_start [in] The index of the x1 value the **Ys** data start at.
41 * @param a_Ys [in] The list of y values.
42 * @param a_index [in] If imbedded in a two dimensional function, the index of this instance.
43 * @param a_outerDomainValue [in] If imbedded in a two dimensional function, the domain value for *x2*.
44 ***********************************************************************************************************/
45
46Ys1d::Ys1d( Axes const &a_axes, ptwXY_interpolation a_interpolation, std::size_t a_start, std::vector<double> const &a_Ys, int a_index, double a_outerDomainValue ) :
47 Function1dForm( GIDI_Ys1dChars, FormType::Ys1d, a_axes, a_interpolation, a_index, a_outerDomainValue ),
48 m_start( a_start ),
49 m_Ys( a_Ys ) {
50
51}
52
53
54/* *********************************************************************************************************//**
55 * Constructs the instance from a **HAPI::Nodee** instance.
56 *
57 * @param a_construction [in] Used to pass user options for parsing.
58 * @param a_node [in] The Ys1d HAPI::Node to be parsed and to construct the instance.
59 * @param a_setupInfo [in] Information create my the Protare constructor to help in parsing.
60 * @param a_parent [in] If imbedded in a two dimensional function, its pointers.
61 ***********************************************************************************************************/
62
63Ys1d::Ys1d( Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, Suite *a_parent ) :
64 Function1dForm( a_construction, a_node, a_setupInfo, FormType::Ys1d, a_parent ),
65 m_start( static_cast<std::size_t>( a_node.child( GIDI_valuesChars ).attribute( GIDI_startChars ).as_int( ) ) ), // as_int returns 0 if "start" not present.
66 m_Ys( ) {
67
68 HAPI::Node values = a_node.child( GIDI_valuesChars );
69 nf_Buffer<double> data;
70 parseValuesOfDoubles( a_construction, values, a_setupInfo, data );
71 m_Ys.resize( data.size() );
72 for( size_t i1 = 0; i1 < data.size(); ++i1 ) m_Ys[i1] = data[i1];
73}
74
75/* *********************************************************************************************************//**
76 * The Ys1d copy constructor.
77 *
78 * @param a_Ys1d
79 ***********************************************************************************************************/
80
81Ys1d::Ys1d( Ys1d const &a_Ys1d ) :
82 Function1dForm( a_Ys1d ),
83 m_start( a_Ys1d.start( ) ),
84 m_Ys( a_Ys1d.Ys( ) ) {
85
86}
87
88/* *********************************************************************************************************//**
89 ***********************************************************************************************************/
90
92
93}
94
95/* *********************************************************************************************************//**
96 * Adds two **Ys1d** instances and returns the result.
97 *
98 * @param a_rhs [in] The **Ys1d** instance to add to this instance.
99 * @return An **Ys1d** instance that is the sum of this and *a_rhs*.
100 ***********************************************************************************************************/
101
102Ys1d Ys1d::operator+( Ys1d const &a_rhs ) const {
103
104 Ys1d _Ys1d( *this );
105
106 _Ys1d += a_rhs;
107 return( _Ys1d );
108}
109
110/* *********************************************************************************************************//**
111 * Adds an **Ys1d** instance to this.
112 *
113 * @param a_rhs [in] The **Ys1d** instance to add to this instance.
114 * @return This instance.
115 ***********************************************************************************************************/
116
117Ys1d &Ys1d::operator+=( Ys1d const &a_rhs ) {
118
119 if( length( ) == 0 ) m_start = a_rhs.length( ); // Allow for empty (uninitialized) this.
120 if( length( ) != a_rhs.length( ) ) throw Exception( "Ys1d::operator+=: lengths not equal." );
121
122 if( a_rhs.start( ) >= m_start ) {
123 std::size_t deltaStart = a_rhs.start( ) - m_start;
124 for( std::size_t i1 = 0; i1 < a_rhs.size( ); ++i1 ) m_Ys[i1+deltaStart] += a_rhs[i1]; }
125 else {
126 std::size_t deltaStart = m_start - a_rhs.start( );
127 std::vector<double> _Ys( a_rhs.Ys( ) );
128
129 for( std::size_t i1 = 0; i1 < size( ); ++i1 ) _Ys[i1+deltaStart] += m_Ys[i1];
130 m_Ys = std::move( _Ys );
131 m_start = a_rhs.start( );
132 }
133 return( *this );
134}
135
136/* *********************************************************************************************************//**
137 * This is currently not implemented.
138 *
139 * @return The domain minimum for the instance.
140 ***********************************************************************************************************/
141
142double Ys1d::domainMin( ) const {
143
144#if !defined(__NVCC__) && !defined(__HIP__)
145 throw Exception( "Ys1d::domainMin: not implemented" );
146#endif
147
148 return( 0. );
149}
150
151/* *********************************************************************************************************//**
152 * This is currently not implemented.
153 *
154 * @return The domain maximum for the instance.
155 ***********************************************************************************************************/
156
157double Ys1d::domainMax( ) const {
158
159#if !defined(__NVCC__) && !defined(__HIP__)
160 throw Exception( "Ys1d::domainMax: not implemented" );
161#endif
162
163 return( 0. );
164}
165
166/* *********************************************************************************************************//**
167 * This is currently not implemented.
168 *
169 * @param a_x1 [in] Domain value to evaluate this at.
170 * @return
171 ***********************************************************************************************************/
172
173double Ys1d::evaluate( LUPI_maybeUnused double a_x1 ) const {
174
175#if !defined(__NVCC__) && !defined(__HIP__)
176 throw Exception( "Ys1d::evaluate: not implemented" );
177#endif
178
179 return( 0. );
180}
181
182/* *********************************************************************************************************//**
183 * Fills the argument *a_writeInfo* with the XML lines that represent *this*. Recursively enters each sub-node.
184 *
185 * @param a_writeInfo [in/out] Instance containing incremental indentation and other information and stores the appended lines.
186 * @param a_indent [in] The amount to indent *this* node.
187 * @param a_embedded [in] If *true*, *this* function is embedded in a higher dimensional function.
188 * @param a_inRegions [in] If *true*, *this* is in a Regions1d container.
189 ***********************************************************************************************************/
190
191void Ys1d::toXMLList_func( GUPI::WriteInfo &a_writeInfo, std::string const &a_indent, LUPI_maybeUnused bool a_embedded, LUPI_maybeUnused bool a_inRegions ) const {
192
193 std::string indent2 = a_writeInfo.incrementalIndent( a_indent );
194 std::string attributes = a_writeInfo.addAttribute( GIDI_labelChars, label( ) );
195
196 a_writeInfo.addNodeStarter( a_indent, moniker( ), attributes );
197 axes( ).toXMLList( a_writeInfo, indent2 );
198 doublesToXMLList( a_writeInfo, indent2, m_Ys, m_start );
199 a_writeInfo.addNodeEnder( moniker( ) );
200}
201
202/* *********************************************************************************************************//**
203 * Writes the pair (index, y) values to *a_file*. The format string must have a long and a double conversion specifiers (e.g., " %10ld %.6f").
204 *
205 * @param a_file [in] The C FILE instance to write the data to.
206 * @param a_format [in] The format string passed to the C printf function.
207 ***********************************************************************************************************/
208
209void Ys1d::write( FILE *a_file, std::string const &a_format ) const {
210
211 std::size_t size = m_Ys.size( );
212 for( std::size_t index = 0; index < size; ++index ) fprintf( a_file, a_format.c_str( ), index + m_start, m_Ys[index] );
213}
214
215} // End namespace Functions.
216
217} // End namespace GIDI.
#define GIDI_valuesChars
Definition GIDI.hpp:260
#define GIDI_labelChars
Definition GIDI.hpp:438
#define GIDI_Ys1dChars
Definition GIDI.hpp:289
#define GIDI_startChars
Definition GIDI.hpp:412
#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
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 domainMax() const
Definition GIDI_Ys1d.cc:157
std::size_t length() const
Definition GIDI.hpp:1165
void write(FILE *a_file, std::string const &a_format) const
Definition GIDI_Ys1d.cc:209
double evaluate(double a_x1) const
Definition GIDI_Ys1d.cc:173
Ys1d operator+(Ys1d const &a_Ys1d) const
Definition GIDI_Ys1d.cc:102
void toXMLList_func(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent, bool a_embedded, bool a_inRegions) const
Definition GIDI_Ys1d.cc:191
std::size_t size() const
Definition GIDI.hpp:1154
Ys1d & operator+=(Ys1d const &a_Ys1d)
Definition GIDI_Ys1d.cc:117
Ys1d(Axes const &a_axes, ptwXY_interpolation a_interpolation, int a_index=0, double a_outerDomainValue=0.0)
Definition GIDI_Ys1d.cc:30
std::vector< double > const & Ys() const
Definition GIDI.hpp:1166
double domainMin() const
Definition GIDI_Ys1d.cc:142
std::size_t start() const
Definition GIDI.hpp:1163
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
Node child(const char *name) const
Definition HAPI_Node.cc:72
Definition GIDI.hpp:32
void parseValuesOfDoubles(Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, nf_Buffer< double > &a_vector)
Definition GIDI_misc.cc:88
FormType
Definition GIDI.hpp:118
void doublesToXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent, std::vector< double > const &a_values, std::size_t a_start=0, bool a_newLine=true, std::string const &a_valueType="")
Definition GIDI_misc.cc:180
enum ptwXY_interpolation_e ptwXY_interpolation