queso-0.51.1
Protected Attributes | List of all members
QUESO::Sampled1D1DFunction Class Reference

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

#include <1D1DFunction.h>

Inheritance diagram for QUESO::Sampled1D1DFunction:
Inheritance graph
[legend]
Collaboration diagram for QUESO::Sampled1D1DFunction:
Collaboration graph
[legend]

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 475 of file 1D1DFunction.C.

476  :
477  Base1D1DFunction(-INFINITY,INFINITY)
478 {
479  //UQ_FATAL_TEST_MACRO(true,
480  // UQ_UNAVAILABLE_RANK,
481  // "SampledD1DFunction::deriv()",
482  // "invalid constructor");
483 }
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 485 of file 1D1DFunction.C.

References m_domainValues, and m_imageValues.

488  :
490  m_domainValues (domainValues.size(),0.),
491  m_imageValues (imageValues.size(), 0.)
492 {
493  unsigned int tmpSize = m_domainValues.size();
494  for (unsigned int i = 0; i < tmpSize; ++i) {
496  m_imageValues [i] = imageValues [i];
497  }
498 }
Base1D1DFunction(double minDomainValue, double maxDomainValue)
Default constructor.
Definition: 1D1DFunction.C:33
const std::vector< double > & domainValues() const
Array of the domain values (values of the independent variable).
Definition: 1D1DFunction.C:589
const std::vector< double > & imageValues() const
Array of the image values (values of the dependent variable).
Definition: 1D1DFunction.C:595
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
QUESO::Sampled1D1DFunction::~Sampled1D1DFunction ( )
virtual

Destructor.

Definition at line 500 of file 1D1DFunction.C.

501 {
502 }

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 565 of file 1D1DFunction.C.

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

566 {
567  if ((domainValue < m_minDomainValue) || (domainValue > m_maxDomainValue)) {
568  std::cerr << "In Sampled1D1DFunction::deriv()"
569  << ": requested x (" << domainValue
570  << ") is out of the interval (" << m_minDomainValue
571  << ", " << m_maxDomainValue
572  << ")"
573  << std::endl;
574  }
575 
576  UQ_FATAL_TEST_MACRO(((domainValue < m_minDomainValue) || (domainValue > m_maxDomainValue)),
578  "Sampled1D1DFunction::deriv()",
579  "x out of range");
580 
581  UQ_FATAL_TEST_MACRO(true,
583  "Sampled1d1DFunction::deriv()",
584  "this function makes no sense for this class");
585  return 0.;
586 }
const int UQ_UNAVAILABLE_RANK
Definition: Defines.h:74
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
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 601 of file 1D1DFunction.C.

References m_domainValues.

602 {
603  bool result = false;
604 
605  unsigned int tmpSize = m_domainValues.size();
606  for (unsigned int i = 0; i < tmpSize; ++i) {
607  if (domainValue <= m_domainValues[i]) {
608  result = (domainValue == m_domainValues[i]);
609  break;
610  }
611  }
612 
613  return result;
614 }
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 589 of file 1D1DFunction.C.

References m_domainValues.

590 {
591  return m_domainValues;
592 }
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 595 of file 1D1DFunction.C.

References m_imageValues.

596 {
597  return m_imageValues;
598 }
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 639 of file 1D1DFunction.C.

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

643 {
644  unsigned int tmpSize = m_domainValues.size();
645  if (tmpSize == 0) {
646  tmpSize = 1;
647  ofsvar << "\n" << prefixName << "Time_sub" << env.subIdString() << " = zeros(" << tmpSize << ",1);"
648  << "\n" << prefixName << "Value_sub" << env.subIdString() << " = zeros(" << tmpSize << ",1);";
649  }
650  else {
651  ofsvar << "\n" << prefixName << "Time_sub" << env.subIdString() << " = zeros(" << tmpSize << ",1);"
652  << "\n" << prefixName << "Value_sub" << env.subIdString() << " = zeros(" << tmpSize << ",1);";
653  for (unsigned int i = 0; i < tmpSize; ++i) {
654  ofsvar << "\n" << prefixName << "Time_sub" << env.subIdString() << "(" << i+1 << ",1) = " << m_domainValues[i] << ";"
655  << "\n" << prefixName << "Value_sub" << env.subIdString() << "(" << i+1 << ",1) = " << m_imageValues[i] << ";";
656  }
657  }
658 
659  return;
660 }
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 617 of file 1D1DFunction.C.

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

620 {
621  m_domainValues.clear();
622  m_imageValues.clear();
623 
624  unsigned int tmpSize = domainValues.size();
626  m_maxDomainValue = domainValues[tmpSize-1];
627 
628  m_domainValues.resize(tmpSize,0.);
629  m_imageValues.resize(tmpSize,0.);
630  for (unsigned int i = 0; i < tmpSize; ++i) {
632  m_imageValues [i] = imageValues [i];
633  }
634 
635  return;
636 }
const std::vector< double > & domainValues() const
Array of the domain values (values of the independent variable).
Definition: 1D1DFunction.C:589
const std::vector< double > & imageValues() const
Array of the image values (values of the dependent variable).
Definition: 1D1DFunction.C:595
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
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 505 of file 1D1DFunction.C.

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

506 {
507  if ((domainValue < m_minDomainValue) || (domainValue > m_maxDomainValue)) {
508  std::cerr << "In Sampled1D1DFunction::value()"
509  << ": requested x (" << domainValue
510  << ") is out of the interval (" << m_minDomainValue
511  << ", " << m_maxDomainValue
512  << ")"
513  << std::endl;
514  }
515 
516  UQ_FATAL_TEST_MACRO(((domainValue < m_minDomainValue) || (domainValue > m_maxDomainValue)),
518  "Sampled1D1DFunction::value()",
519  "x out of range");
520 
521  double returnValue = 0.;
522 
523  unsigned int tmpSize = m_domainValues.size();
524  //std::cout << "In Sampled1D1DFunction::value()"
525  // << ": domainValue = " << domainValue
526  // << ", tmpSize = " << tmpSize
527  // << ", m_domainValues[0] = " << m_domainValues[0]
528  // << ", m_domainValues[max] = " << m_domainValues[tmpSize-1]
529  // << std::endl;
530 
531  UQ_FATAL_TEST_MACRO(tmpSize == 0,
533  "Sampled1D1DFunction::value()",
534  "m_domainValues.size() = 0");
535 
536  UQ_FATAL_TEST_MACRO(domainValue < m_domainValues[0],
538  "Sampled1D1DFunction::value()",
539  "domainValue < m_domainValues[0]");
540 
541  UQ_FATAL_TEST_MACRO(m_domainValues[tmpSize-1] < domainValue,
543  "Sampled1D1DFunction::value()",
544  "m_domainValues[max] < domainValue");
545 
546  unsigned int i = 0;
547  for (i = 0; i < tmpSize; ++i) {
548  if (domainValue <= m_domainValues[i]) break;
549  }
550 
551  if (domainValue == m_domainValues[i]) {
552  //if (domainValueWasMatchedExactly) *domainValueWasMatchedExactly = true;
553  returnValue = m_imageValues[i];
554  }
555  else {
556  //if (domainValueWasMatchedExactly) *domainValueWasMatchedExactly = false;
557  double ratio = (domainValue - m_domainValues[i-1])/(m_domainValues[i]-m_domainValues[i-1]);
558  returnValue = m_imageValues[i-1] + ratio * (m_imageValues[i]-m_imageValues[i-1]);
559  }
560 
561  return returnValue;
562 }
const int UQ_UNAVAILABLE_RANK
Definition: Defines.h:74
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
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223

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 Thu Apr 23 2015 19:26:17 for queso-0.51.1 by  doxygen 1.8.5