Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
GIDI_gridded1d.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 Gridded1d
18 * Class for the GNDS <**gridded1d**> 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
29Gridded1d::Gridded1d( Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, Suite *a_parent ) :
30 Function1dForm( a_construction, a_node, a_setupInfo, FormType::gridded1d, a_parent ) {
31
32 Grid const *axis = dynamic_cast<Grid const *>( axes( )[0] );
33 m_grid = axis->data( ).vector();
34
35 parseFlattened1d( a_construction, a_node.child( GIDI_arrayChars ), a_setupInfo, m_data );
36}
37
38/* *********************************************************************************************************//**
39 ***********************************************************************************************************/
40
44
45/* *********************************************************************************************************//**
46 * Only for internal use. Called by ProtareTNSL instance to zero the lower energy multi-group data covered by the ProtareSingle that
47 * contains the TNSL data covers the lower energy multi-group data.
48 *
49 * @param a_maxTNSL_index [in] All elements up to *a_maxTNSL_index* exclusive are zero-ed.
50 ***********************************************************************************************************/
51
52void Gridded1d::modifiedMultiGroupElasticForTNSL( std::size_t a_maxTNSL_index ) {
53
54 m_data.setToValueInFlatRange( 0, a_maxTNSL_index, 0.0 );
55}
56
57/* *********************************************************************************************************//**
58 * Returns the value of the function at the point *a_x1*.
59 * Currently not implemented.
60 *
61 * @param a_x1 [in] The is ignored.
62 * @return The value of the function at the point *a_x1*.
63 ***********************************************************************************************************/
64
65double Gridded1d::evaluate( LUPI_maybeUnused double a_x1 ) const {
66
67 throw Exception( "Gridded1d::evaluate: not implement." );
68}
69
70/* *********************************************************************************************************//**
71 * Fills the argument *a_writeInfo* with the XML lines that represent *this*. Recursively enters each sub-node.
72 *
73 * @param a_writeInfo [in/out] Instance containing incremental indentation and other information and stores the appended lines.
74 * @param a_indent [in] The amount to indent *this* node.
75 * @param a_embedded [in] If *true*, *this* function is embedded in a higher dimensional function.
76 * @param a_inRegions [in] If *true*, *this* is in a Regions1d container.
77 ***********************************************************************************************************/
78
79void Gridded1d::toXMLList_func( GUPI::WriteInfo &a_writeInfo, std::string const &a_indent, bool a_embedded, bool a_inRegions ) const {
80
81// BRB. This is not correct as it is not converted to a flattened array.
82
83 std::string indent2 = a_writeInfo.incrementalIndent( a_indent );
84 std::string indent3 = a_writeInfo.incrementalIndent( indent2 );
85 std::string attributes;
86
87 if( a_embedded ) {
89 else {
90 if( a_inRegions ) {
91 attributes = a_writeInfo.addAttribute( GIDI_indexChars, intToString( index( ) ) ); }
92 else {
93 if( label( ) != "" ) attributes = a_writeInfo.addAttribute( GIDI_labelChars, label( ) );
94 }
95 }
96
97 a_writeInfo.addNodeStarter( a_indent, moniker( ), attributes );
98
99 axes( ).toXMLList( a_writeInfo, indent2 );
100
101 attributes = a_writeInfo.addAttribute( GIDI_shapeChars, size_t_ToString( m_data.size( ) ) );
102 attributes += a_writeInfo.addAttribute( "compression", "flattened" );
103 a_writeInfo.addNodeStarter( indent2, GIDI_arrayChars, attributes );
104
105 std::vector<double> doubles;
106 doubles.reserve( m_data.size( ) );
107 std::size_t i1, i2;
108 for( i1 = 0; i1 < m_data.size( ); ++i1 ) {
109 if( m_data[i1] != 0.0 ) break;
110 }
111 for( i2 = m_data.size( ); i2 > i1; --i2 ) {
112 if( m_data[i2-1] != 0.0 ) break;
113 }
114 std::size_t start( i1 );
115 if( start == m_data.size( ) ) start = 0;
116 a_writeInfo.push_back( indent3 + "<values valueType=\"Integer32\" label=\"starts\">" + size_t_ToString( start ) + "</values>" );
117 for( ; i1 < i2; ++i1 ) doubles.push_back( m_data[i1] );
118 a_writeInfo.push_back( indent3 + "<values valueType=\"Integer32\" label=\"lengths\">" + size_t_ToString( doubles.size( ) ) + "</values>" );
119
120 doublesToXMLList( a_writeInfo, indent3, doubles );
121 a_writeInfo.addNodeEnder( GIDI_arrayChars );
122 a_writeInfo.addNodeEnder( moniker( ) );
123}
124
125/* *********************************************************************************************************//**
126 * This method writes *this* to a *a_file*.
127 *
128 * @param a_file [in] The C FILE instance to write the data to.
129 * @param a_format [in] The format string passed to each region's write method.
130 ***********************************************************************************************************/
131
132void Gridded1d::write( FILE *a_file, std::string const &a_format ) const {
133
134 std::size_t index = 0;
135 char const *fmt = a_format.c_str( );
136
137 for( ; index < m_data.size( ); ++index ) {
138 fprintf( a_file, fmt, m_grid[index], m_data[index] );
139 }
140 if( m_data.size( ) > 0 ) printf( fmt, m_grid[index], m_data[index-1] );
141}
142
143} // End namespace Functions.
144
145} // End namespace GIDI.
#define GIDI_outerDomainValueChars
Definition GIDI.hpp:436
#define GIDI_labelChars
Definition GIDI.hpp:438
#define GIDI_shapeChars
Definition GIDI.hpp:261
#define GIDI_arrayChars
Definition GIDI.hpp:258
#define GIDI_indexChars
Definition GIDI.hpp:437
#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 outerDomainValue() const
Definition GIDI.hpp:1010
Gridded1d(Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, Suite *a_parent)
void write(FILE *a_file, std::string const &a_format) const
double evaluate(double a_x1) const
void modifiedMultiGroupElasticForTNSL(std::size_t a_maxTNSL_index)
void toXMLList_func(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent, bool a_embedded, bool a_inRegions) const
std::string const & moniker() const
Definition GUPI.hpp:102
void push_back(std::string const &a_line)
Definition GUPI.hpp:53
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
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
std::string size_t_ToString(std::size_t a_value)
Definition GIDI_misc.cc:428
int parseFlattened1d(Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, Vector &data)
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
const axis_t axis_to_type< N >::axis
Definition pugixml.cc:9668