26static double getAdjustedX(
double a_x,
double a_epsilon ) {
28 double xp = a_epsilon;
32 xp = a_x * ( 1.0 - a_epsilon ); }
34 xp = a_x * ( 1.0 + a_epsilon );
56 data1dListParse( a_construction, a_node.child( GIDI_function1dsChars ), a_setupInfo, m_function1ds );
57 checkSequentialDomainLimits1d( m_function1ds, m_Xs );
62 std::string name( child.name( ) );
64 if( name == GIDI_axesChars ) continue;
65 if( name == GIDI_uncertaintyChars ) continue;
67 Function1dForm *_form = data1dParse( a_construction, child, a_setupInfo, nullptr );
68 if( _form == nullptr ) throw Exception(
"Regions1d::Regions1d: data1dParse returned nullptr." );
78 for( std::vector<Function1dForm *>::iterator iter = m_function1ds.begin( ); iter < m_function1ds.end( ); ++iter )
delete *iter;
89 if( m_Xs.size( ) == 0 )
throw Exception(
"Regions1d::domainMin: Regions1d has no regions" );
101 if( m_Xs.size( ) == 0 )
throw Exception(
"Regions1d::domainMax: Regions1d has not regions" );
102 return( m_Xs[m_Xs.size( )-1] );
117 if( m_Xs.size( ) == 0 ) {
118 m_Xs.push_back( _domainMin ); }
120 if( m_Xs.back( ) != _domainMin )
throw Exception(
"Regions1d::append: regions do not abut." );
123 m_Xs.push_back( _domainMax );
124 m_function1ds.push_back( a_function );
137 if( m_Xs.size( ) == 0 )
throw Exception(
"Regions1d::evaluate: Regions1d has not regions" );
143 return( m_function1ds.back( )->evaluate( a_x1 ) );
148 return( m_function1ds[
static_cast<std::size_t
>(iX1)]->
evaluate( a_x1 ) );
161void Regions1d::mapToXsAndAdd( std::size_t a_offset, std::vector<double>
const &a_Xs, std::vector<double> &a_results,
double a_scaleFactor )
const {
163 for(
auto iter = m_function1ds.begin( ); iter < m_function1ds.end( ); ++iter ) {
164 (*iter)->mapToXsAndAdd( a_offset, a_Xs, a_results, a_scaleFactor );
183 XYs1d *xys1d1 =
nullptr, *xys1d2 =
nullptr;
185 if( a_lowerEps < 1e-14 ) a_lowerEps = 0.0;
186 if( a_upperEps < 1e-14 ) a_upperEps = 0.0;
189 bool firstRegion =
true;
191 for(
auto regionIter = m_function1ds.begin( ); regionIter != m_function1ds.end( ); ++regionIter ) {
193 xys1d2 =
static_cast<XYs1d *
>( *regionIter );
206 std::vector<double> xs;
207 std::vector<double> ys;
209 for(
auto regionIter = m_function1ds.begin( ); regionIter != m_function1ds.end( ); ++regionIter ) {
210 xys1d2 = (*regionIter)->asXYs1d( a_asLinlin, a_accuracy, a_lowerEps, a_upperEps );
211 if( xys1d2 ==
nullptr ) {
216 std::vector<double> xs2( xys1d2->xs( ) );
217 if( xs2.size( ) < 2 )
continue;
219 std::size_t xySize = xs.size( );
220 std::vector<double> ys2( xys1d2->ys( ) );
222 double y1u = ys.back( );
226 xs.resize( xySize - 1 );
227 ys.resize( xySize - 1 ); }
229 bool addLower =
false, addUpper =
false;
230 double x1l = xs[xySize-2];
231 double x1u = xs.back( );
234 double x1up = 0.0, x2lp= 0.0;
236 if( a_lowerEps != 0.0 ) {
237 double x1lp = getAdjustedX( x1l, 0.8 * a_lowerEps );
238 x1up = getAdjustedX( x1u, -a_lowerEps );
240 addLower = x1lp < x1up;
243 if( a_upperEps > 0 ) {
244 x2lp = getAdjustedX( x2l, a_upperEps );
245 double x2up = getAdjustedX( x2u, 0.8 * -a_upperEps );
247 addUpper = x2lp < x2up;
253 ys.back( ) = xys1d1->
evaluate( x1up );
255 ys.push_back( 0.5 * ( y1u + y2l ) );
257 ys2[0] = xys1d2->evaluate( x2lp ); }
260 ys.back( ) = xys1d1->
evaluate( x1up );
262 else if( addUpper ) {
264 ys2[0] = xys1d2->evaluate( x2lp ); }
266 ys2[0] = 0.5 * ( y1u + y2l );
267 xs.resize( xySize - 1 );
268 ys.resize( xySize - 1 );
272 xs.insert( xs.end( ), xs2.begin( ), xs2.end( ) );
273 ys.insert( ys.end( ), ys2.begin( ), ys2.end( ) );
294 std::string attributes;
308 a_writeInfo.
push_back( indent2 +
"<function1ds>" );
309 for( std::vector<Function1dForm *>::const_iterator iter = m_function1ds.begin( ); iter != m_function1ds.end( ); ++iter ) (*iter)->toXMLList_func( a_writeInfo, indent3,
false,
true );
310 a_writeInfo.
push_back(
"</function1ds>" );
323 for(
auto regionIter = m_function1ds.begin( ); regionIter != m_function1ds.end( ); ++regionIter ) {
324 (*regionIter)->write( a_file, a_format );
#define GIDI_outerDomainValueChars
#define GNDS_formatVersion_1_10Chars
void toXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent="") const
void write(FILE *a_file, std::string const &a_format) const
void append(Function1dForm *a_function)
Regions1d(Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, Suite *a_parent)
void mapToXsAndAdd(std::size_t a_offset, std::vector< double > const &a_Xs, std::vector< double > &a_results, double a_scaleFactor) const
double evaluate(double a_x1) const
XYs1d * asXYs1d(bool a_asLinlin, double a_accuray, double a_lowerEps, double a_upperEps) const
void toXMLList_func(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent, bool a_embedded, bool a_inRegions) const
double evaluate(double a_x1) const
LUPI::FormatVersion m_formatVersion
std::string const & moniker() const
void push_back(std::string const &a_line)
void addNodeEnder(std::string const &a_moniker)
std::string incrementalIndent(std::string const &indent)
void addNodeStarter(std::string const &indent, std::string const &a_moniker, std::string const &a_attributes="")
std::string addAttribute(std::string const &a_name, std::string const &a_value) const
long binarySearchVector(double a_x, std::vector< double > const &a_Xs)
std::string intToString(int a_value)
std::string doubleToShortestString(double a_value, int a_significantDigits=15, int a_favorEFormBy=0)
ptwXY_interpolation ptwXY_getInterpolation(ptwXYPoints *ptwXY)
enum ptwXY_interpolation_e ptwXY_interpolation
@ ptwXY_interpolationLinLin