Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
GIDI_Legendre1d.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
12#include <nf_Legendre.h>
13#include "GIDI.hpp"
14#include <HAPI.hpp>
15
16namespace GIDI {
17
18namespace Functions {
19
20/*! \class Legendre1d
21 * Class for the GNDS <**Legendre**> node.
22 */
23
24/* *********************************************************************************************************//**
25 * @param a_axes [in] The axes to copy for *this*.
26 * @param a_index [in] Currently not used.
27 * @param a_outerDomainValue [in] If embedded in a higher dimensional function, the value of the domain of the next higher dimension.
28 ***********************************************************************************************************/
29
30Legendre1d::Legendre1d( Axes const &a_axes, int a_index, double a_outerDomainValue ) :
31 Function1dForm( GIDI_LegendreChars, FormType::Legendre1d, a_axes, ptwXY_interpolationLinLin, a_index, a_outerDomainValue ) {
32
33}
34
35/* *********************************************************************************************************//**
36 *
37 * @param a_construction [in] Used to pass user options for parsing.
38 * @param a_node [in] The **HAPI::Node** to be parsed and used to construct the XYs2d.
39 * @param a_setupInfo [in] Information create my the Protare constructor to help in parsing.
40 * @param a_parent [in] The parent GIDI::Suite.
41 ***********************************************************************************************************/
42
43Legendre1d::Legendre1d( Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, Suite *a_parent ) :
44 Function1dForm( a_construction, a_node, a_setupInfo, FormType::Legendre1d, a_parent ) {
45
46 nf_Buffer<double> coeff;
47 parseValuesOfDoubles( a_construction, a_node.child( GIDI_valuesChars ), a_setupInfo, coeff );
48 m_coefficients = coeff.vector();
49}
50
51/* *********************************************************************************************************//**
52 * The Legendre1d copy constructor.
53 *
54 * @param a_Legendre1d [in] The Legendre1d instance to copy.
55 ***********************************************************************************************************/
56
57Legendre1d::Legendre1d( Legendre1d const &a_Legendre1d ) :
59 m_coefficients( a_Legendre1d.coefficients( ) ) {
60
61}
62
63/* *********************************************************************************************************//**
64 ***********************************************************************************************************/
65
69
70/* *********************************************************************************************************//**
71 * Returns the value of the function evaluated at the specified projectile's energy.
72 * Currently not implemented.
73 *
74 * @param a_x1 [in] The projectile's energy.
75 * @return The value of the function evaluated at *a_x1*.
76 ***********************************************************************************************************/
77
78double Legendre1d::evaluate( LUPI_maybeUnused double a_x1 ) const {
79
80 throw Exception( "Legendre1d::evaluate: not implemented." );
81}
82
83/* *********************************************************************************************************//**
84 * This methods returns an XYs1d representation of *this*. The calling function owns the created instance and is responible
85 * for freeing it.
86 *
87 * @param a_asLinlin [in] This argument is not used but retained to make the methods API at same as other asXYs1d functions.
88 * @param a_accuracy [in] The accuracy use to convert the data to lin=lin interpolation if needed. This argument is not needed or used for this cl
89 * @param a_lowerEps [in] This argument is not used but retained to make the methods API at same as other asXYs1d functions.
90 * @param a_upperEps [in] This argument is not used but retained to make the methods API at same as other asXYs1d functions.
91 *
92 * @return A pointer to an XYs1d instance that must be freed by the calling function.
93 ***********************************************************************************************************/
94
95XYs1d *Legendre1d::asXYs1d( LUPI_maybeUnused bool a_asLinlin, double a_accuracy, LUPI_maybeUnused double a_lowerEps, LUPI_maybeUnused double a_upperEps ) const {
96
97 int size1 = static_cast<int>( m_coefficients.size( ) );
98 nf_Legendre *legendre1 = nf_Legendre_new( nullptr, 0, size1 - 1, const_cast<double *>( m_coefficients.data( ) ) );
99 if( legendre1 == nullptr ) return( nullptr );
100
101 ptwXYPoints *xys = nf_Legendre_to_ptwXY( nullptr, legendre1, a_accuracy, 12, 1 );
102 nf_Legendre_free( legendre1 );
103 if( xys == nullptr ) return( nullptr );
104
105 return( new XYs1d( axes( ), xys ) );
106}
107
108/* *********************************************************************************************************//**
109 * Fills the argument *a_writeInfo* with the XML lines that represent *this*. Recursively enters each sub-node.
110 *
111 * @param a_writeInfo [in/out] Instance containing incremental indentation and other information and stores the appended lines.
112 * @param a_indent [in] The amount to indent *this* node.
113 * @param a_embedded [in] If *true*, *this* function is embedded in a higher dimensional function.
114 * @param a_inRegions [in] If *true*, *this* is in a Regions1d container.
115 ***********************************************************************************************************/
116
117void Legendre1d::toXMLList_func( GUPI::WriteInfo &a_writeInfo, std::string const &a_indent, bool a_embedded, bool a_inRegions ) const {
118
119 std::string indent2 = a_writeInfo.incrementalIndent( a_indent );
120 std::string attributes;
121
122 if( a_embedded ) {
124 else {
125 if( a_inRegions ) {
126 attributes = a_writeInfo.addAttribute( GIDI_indexChars, intToString( index( ) ) ); }
127 else {
128 if( keyValue( ) != "" ) attributes = a_writeInfo.addAttribute( keyName( ), keyValue( ) );
129 }
130 }
131
132 a_writeInfo.addNodeStarter( a_indent, moniker( ), attributes );
133
134 if( !a_embedded ) axes( ).toXMLList( a_writeInfo, indent2 );
135
136 doublesToXMLList( a_writeInfo, indent2, m_coefficients, 0, true );
137 a_writeInfo.addNodeEnder( moniker( ) );
138}
139
140} // End namespace Functions.
141
142} // End namespace GIDI.
#define GIDI_LegendreChars
Definition GIDI.hpp:291
#define GIDI_valuesChars
Definition GIDI.hpp:260
#define GIDI_outerDomainValueChars
Definition GIDI.hpp:436
#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 & keyName() const
Definition GIDI_form.cc:126
std::string const & keyValue() const
Definition GIDI_form.cc:149
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
void toXMLList_func(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent, bool a_embedded, bool a_inRegions) const
Legendre1d(Axes const &a_axes, int a_index=0, double a_outerDomainValue=0.0)
std::vector< double > const & coefficients() const
Definition GIDI.hpp:1225
double evaluate(double a_x1) const
XYs1d * asXYs1d(bool a_asLinlin, double a_accuray, double a_lowerEps, double a_upperEps) const
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
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
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
nf_Legendre * nf_Legendre_new(statusMessageReporting *smr, int initialSize, int maxOrder, double *Cls)
Definition nf_Legendre.c:22
nf_Legendre * nf_Legendre_free(nf_Legendre *nfL)
Definition nf_Legendre.c:64
ptwXYPoints * nf_Legendre_to_ptwXY(statusMessageReporting *smr, nf_Legendre *nfL, double accuracy, int biSectionMax, int checkForRoots)
struct nf_Legendre_s nf_Legendre
Definition nf_Legendre.h:24
@ ptwXY_interpolationLinLin
Definition ptwXY.h:37
struct ptwXYPoints_s ptwXYPoints