queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
QUESO::Sampled1D1DFunction Class Reference

Class for one-dimensional sampled functions. More...

#include <1D1DFunction.h>

Inheritance diagram for QUESO::Sampled1D1DFunction:
QUESO::Base1D1DFunction

Public Member Functions

Constructor/Destructor methods
 Sampled1D1DFunction ()
 Default constructor. It should not be called by the user. More...
 
 Sampled1D1DFunction (const std::vector< double > &domainValues, const std::vector< double > &imageValues)
 Constructor. More...
 
virtual ~Sampled1D1DFunction ()
 Destructor. More...
 
Mathematical methods
virtual double value (double domainValue) const
 Returns the value of the sampled function at point domainValue. More...
 
double deriv (double domainValue) const
 Bogus: Derivative of the function. More...
 
const std::vector< double > & domainValues () const
 Array of the domain values (values of the independent variable). More...
 
const std::vector< double > & imageValues () const
 Array of the image values (values of the dependent variable). More...
 
bool domainValueMatchesExactly (double domainValue) const
 Checks whether the domain value domainValue matches exactly one of the values in the function domain domainValues(). More...
 
void set (const std::vector< double > &domainValues, const std::vector< double > &imageValues)
 Sets the values of the independent (domainValues) and dependent (imageValues) variables of this sampled function. More...
 
I/O methods
virtual void printForMatlab (const BaseEnvironment &env, std::ofstream &ofsvar, const std::string &prefixName) const
 Prints the values of the function in Matlab/Octave format. More...
 
- Public Member Functions inherited from QUESO::Base1D1DFunction
 Base1D1DFunction (double minDomainValue, double maxDomainValue)
 Default constructor. More...
 
virtual ~Base1D1DFunction ()
 Destructor. More...
 
double minDomainValue () const
 Returns the minimum value of the domain of the (one-dimensional) function. More...
 
double maxDomainValue () const
 Returns the maximum value of the domain of the (one-dimensional) function. More...
 
virtual double multiplyAndIntegrate (const Base1D1DFunction &func, unsigned int quadratureOrder, double *resultWithMultiplicationByTAsWell) const
 TODO: Multiplies this function with function, and integrates it numerically. See template specialization. More...
 

Protected Attributes

std::vector< double > m_domainValues
 Array of the values in the domain of the function (values of the independent variable). More...
 
std::vector< double > m_imageValues
 Array of the values in the image of the function (values of the dependent variable). More...
 
- Protected Attributes inherited from QUESO::Base1D1DFunction
double m_minDomainValue
 
double m_maxDomainValue
 

Detailed Description

Class for one-dimensional sampled functions.

This class implements sampled one-dimensional functions. A sample function is one whose values are known only at discrete values of the independent variable; i.e., its values are only known at grid points. There are several QUESO classes which handle grids, all derived from BaseOneDGrid. Sampled functions are usually defined by arrays.

Definition at line 347 of file 1D1DFunction.h.

Constructor & Destructor Documentation

QUESO::Sampled1D1DFunction::Sampled1D1DFunction ( )

Default constructor. It should not be called by the user.

Definition at line 427 of file 1D1DFunction.C.

428  :
429  Base1D1DFunction(-INFINITY,INFINITY)
430 {
431 
432  // UQ_UNAVAILABLE_RANK,
433  // "SampledD1DFunction::deriv()",
434  // "invalid constructor");
435 }
Base1D1DFunction(double minDomainValue, double maxDomainValue)
Default constructor.
Definition: 1D1DFunction.C:33
QUESO::Sampled1D1DFunction::Sampled1D1DFunction ( const std::vector< double > &  domainValues,
const std::vector< double > &  imageValues 
)

Constructor.

When calling this constructor, the user provides the values of the independent variable (domainValues) and their respective values in the image set (independent variable, imageValue)

Definition at line 437 of file 1D1DFunction.C.

References m_domainValues, and m_imageValues.

440  :
442  m_domainValues (domainValues.size(),0.),
443  m_imageValues (imageValues.size(), 0.)
444 {
445  unsigned int tmpSize = m_domainValues.size();
446  for (unsigned int i = 0; i < tmpSize; ++i) {
448  m_imageValues [i] = imageValues [i];
449  }
450 }
std::vector< double > m_domainValues
Array of the values in the domain of the function (values of the independent variable).
Definition: 1D1DFunction.h:404
std::vector< double > m_imageValues
Array of the values in the image of the function (values of the dependent variable).
Definition: 1D1DFunction.h:407
const std::vector< double > & domainValues() const
Array of the domain values (values of the independent variable).
Definition: 1D1DFunction.C:523
const std::vector< double > & imageValues() const
Array of the image values (values of the dependent variable).
Definition: 1D1DFunction.C:529
Base1D1DFunction(double minDomainValue, double maxDomainValue)
Default constructor.
Definition: 1D1DFunction.C:33
QUESO::Sampled1D1DFunction::~Sampled1D1DFunction ( )
virtual

Destructor.

Definition at line 452 of file 1D1DFunction.C.

453 {
454 }

Member Function Documentation

double QUESO::Sampled1D1DFunction::deriv ( double  domainValue) const
virtual

Bogus: Derivative of the function.

Derivatives are not defined over sampled functions! Thus, this function simply checks if point domainValue belongs to the domain of this function, and in affirmative case, it returns 0.

Implements QUESO::Base1D1DFunction.

Definition at line 505 of file 1D1DFunction.C.

References QUESO::Base1D1DFunction::m_maxDomainValue, and QUESO::Base1D1DFunction::m_minDomainValue.

506 {
507  if ((domainValue < m_minDomainValue) || (domainValue > m_maxDomainValue)) {
508  std::cerr << "In Sampled1D1DFunction::deriv()"
509  << ": requested x (" << domainValue
510  << ") is out of the interval (" << m_minDomainValue
511  << ", " << m_maxDomainValue
512  << ")"
513  << std::endl;
514  }
515 
516  queso_require_msg(!((domainValue < m_minDomainValue) || (domainValue > m_maxDomainValue)), "x out of range");
517 
518  queso_error_msg("this function makes no sense for this class");
519  return 0.;
520 }
bool QUESO::Sampled1D1DFunction::domainValueMatchesExactly ( double  domainValue) const

Checks whether the domain value domainValue matches exactly one of the values in the function domain domainValues().

Definition at line 535 of file 1D1DFunction.C.

References m_domainValues.

536 {
537  bool result = false;
538 
539  unsigned int tmpSize = m_domainValues.size();
540  for (unsigned int i = 0; i < tmpSize; ++i) {
541  if (domainValue <= m_domainValues[i]) {
542  result = (domainValue == m_domainValues[i]);
543  break;
544  }
545  }
546 
547  return result;
548 }
std::vector< double > m_domainValues
Array of the values in the domain of the function (values of the independent variable).
Definition: 1D1DFunction.h:404
const std::vector< double > & QUESO::Sampled1D1DFunction::domainValues ( ) const

Array of the domain values (values of the independent variable).

Definition at line 523 of file 1D1DFunction.C.

References m_domainValues.

524 {
525  return m_domainValues;
526 }
std::vector< double > m_domainValues
Array of the values in the domain of the function (values of the independent variable).
Definition: 1D1DFunction.h:404
const std::vector< double > & QUESO::Sampled1D1DFunction::imageValues ( ) const

Array of the image values (values of the dependent variable).

Definition at line 529 of file 1D1DFunction.C.

References m_imageValues.

530 {
531  return m_imageValues;
532 }
std::vector< double > m_imageValues
Array of the values in the image of the function (values of the dependent variable).
Definition: 1D1DFunction.h:407
void QUESO::Sampled1D1DFunction::printForMatlab ( const BaseEnvironment env,
std::ofstream &  ofsvar,
const std::string &  prefixName 
) const
virtual

Prints the values of the function in Matlab/Octave format.

Definition at line 573 of file 1D1DFunction.C.

References m_domainValues, m_imageValues, and QUESO::BaseEnvironment::subIdString().

577 {
578  unsigned int tmpSize = m_domainValues.size();
579  if (tmpSize == 0) {
580  tmpSize = 1;
581  ofsvar << "\n" << prefixName << "Time_sub" << env.subIdString() << " = zeros(" << tmpSize << ",1);"
582  << "\n" << prefixName << "Value_sub" << env.subIdString() << " = zeros(" << tmpSize << ",1);";
583  }
584  else {
585  ofsvar << "\n" << prefixName << "Time_sub" << env.subIdString() << " = zeros(" << tmpSize << ",1);"
586  << "\n" << prefixName << "Value_sub" << env.subIdString() << " = zeros(" << tmpSize << ",1);";
587  for (unsigned int i = 0; i < tmpSize; ++i) {
588  ofsvar << "\n" << prefixName << "Time_sub" << env.subIdString() << "(" << i+1 << ",1) = " << m_domainValues[i] << ";"
589  << "\n" << prefixName << "Value_sub" << env.subIdString() << "(" << i+1 << ",1) = " << m_imageValues[i] << ";";
590  }
591  }
592 
593  return;
594 }
std::vector< double > m_domainValues
Array of the values in the domain of the function (values of the independent variable).
Definition: 1D1DFunction.h:404
std::vector< double > m_imageValues
Array of the values in the image of the function (values of the dependent variable).
Definition: 1D1DFunction.h:407
void QUESO::Sampled1D1DFunction::set ( const std::vector< double > &  domainValues,
const std::vector< double > &  imageValues 
)

Sets the values of the independent (domainValues) and dependent (imageValues) variables of this sampled function.

Definition at line 551 of file 1D1DFunction.C.

References m_domainValues, m_imageValues, QUESO::Base1D1DFunction::m_maxDomainValue, and QUESO::Base1D1DFunction::m_minDomainValue.

554 {
555  m_domainValues.clear();
556  m_imageValues.clear();
557 
558  unsigned int tmpSize = domainValues.size();
560  m_maxDomainValue = domainValues[tmpSize-1];
561 
562  m_domainValues.resize(tmpSize,0.);
563  m_imageValues.resize(tmpSize,0.);
564  for (unsigned int i = 0; i < tmpSize; ++i) {
566  m_imageValues [i] = imageValues [i];
567  }
568 
569  return;
570 }
std::vector< double > m_domainValues
Array of the values in the domain of the function (values of the independent variable).
Definition: 1D1DFunction.h:404
std::vector< double > m_imageValues
Array of the values in the image of the function (values of the dependent variable).
Definition: 1D1DFunction.h:407
const std::vector< double > & domainValues() const
Array of the domain values (values of the independent variable).
Definition: 1D1DFunction.C:523
const std::vector< double > & imageValues() const
Array of the image values (values of the dependent variable).
Definition: 1D1DFunction.C:529
double QUESO::Sampled1D1DFunction::value ( double  domainValue) const
virtual

Returns the value of the sampled function at point domainValue.

This function checks if point domainValue belongs to the domain of this function, and in affirmative case, it looks for the image value associated to the domain value passed to the function. If there isn't any, it calculates a linear approximation for the image value of domainValue, considering its neighbors points in the domain.

Implements QUESO::Base1D1DFunction.

Definition at line 457 of file 1D1DFunction.C.

References m_domainValues, m_imageValues, QUESO::Base1D1DFunction::m_maxDomainValue, QUESO::Base1D1DFunction::m_minDomainValue, and QUESO::queso_require_not_equal_to_msg.

458 {
459  if ((domainValue < m_minDomainValue) || (domainValue > m_maxDomainValue)) {
460  std::cerr << "In Sampled1D1DFunction::value()"
461  << ": requested x (" << domainValue
462  << ") is out of the interval (" << m_minDomainValue
463  << ", " << m_maxDomainValue
464  << ")"
465  << std::endl;
466  }
467 
468  queso_require_msg(!((domainValue < m_minDomainValue) || (domainValue > m_maxDomainValue)), "x out of range");
469 
470  double returnValue = 0.;
471 
472  unsigned int tmpSize = m_domainValues.size();
473  //std::cout << "In Sampled1D1DFunction::value()"
474  // << ": domainValue = " << domainValue
475  // << ", tmpSize = " << tmpSize
476  // << ", m_domainValues[0] = " << m_domainValues[0]
477  // << ", m_domainValues[max] = " << m_domainValues[tmpSize-1]
478  // << std::endl;
479 
480  queso_require_not_equal_to_msg(tmpSize, 0, "m_domainValues.size() = 0");
481 
482  queso_require_greater_equal_msg(domainValue, m_domainValues[0], "domainValue < m_domainValues[0]");
483 
484  queso_require_greater_equal_msg(m_domainValues[tmpSize-1], domainValue, "m_domainValues[max] < domainValue");
485 
486  unsigned int i = 0;
487  for (i = 0; i < tmpSize; ++i) {
488  if (domainValue <= m_domainValues[i]) break;
489  }
490 
491  if (domainValue == m_domainValues[i]) {
492  //if (domainValueWasMatchedExactly) *domainValueWasMatchedExactly = true;
493  returnValue = m_imageValues[i];
494  }
495  else {
496  //if (domainValueWasMatchedExactly) *domainValueWasMatchedExactly = false;
497  double ratio = (domainValue - m_domainValues[i-1])/(m_domainValues[i]-m_domainValues[i-1]);
498  returnValue = m_imageValues[i-1] + ratio * (m_imageValues[i]-m_imageValues[i-1]);
499  }
500 
501  return returnValue;
502 }
std::vector< double > m_domainValues
Array of the values in the domain of the function (values of the independent variable).
Definition: 1D1DFunction.h:404
std::vector< double > m_imageValues
Array of the values in the image of the function (values of the dependent variable).
Definition: 1D1DFunction.h:407
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix queso_require_not_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the absence of an options input file"))

Member Data Documentation

std::vector<double> QUESO::Sampled1D1DFunction::m_domainValues
protected

Array of the values in the domain of the function (values of the independent variable).

Definition at line 404 of file 1D1DFunction.h.

Referenced by domainValueMatchesExactly(), domainValues(), printForMatlab(), Sampled1D1DFunction(), set(), and value().

std::vector<double> QUESO::Sampled1D1DFunction::m_imageValues
protected

Array of the values in the image of the function (values of the dependent variable).

Definition at line 407 of file 1D1DFunction.h.

Referenced by imageValues(), printForMatlab(), Sampled1D1DFunction(), set(), and value().


The documentation for this class was generated from the following files:

Generated on Tue Jun 5 2018 19:49:17 for queso-0.57.1 by  doxygen 1.8.5