25 #include <queso/1D1DFunction.h>
26 #include <queso/1DQuadrature.h>
34 double minDomainValue,
35 double maxDomainValue)
37 m_minDomainValue(minDomainValue),
38 m_maxDomainValue(maxDomainValue)
42 "Base1D1DFunction::constructor()",
69 "Base1D1DFunction::multiplyAndIntegrate()",
70 "not implemented yet");
72 if (resultWithMultiplicationByTAsWell) {
73 func.
value((
double) quadratureOrder);
83 double minDomainValue,
84 double maxDomainValue,
85 double (*valueRoutinePtr)(
double domainValue,
const void* routinesDataPtr),
86 double (*derivRoutinePtr)(
double domainValue,
const void* routinesDataPtr),
87 const void* routinesDataPtr)
90 m_valueRoutinePtr (valueRoutinePtr),
91 m_derivRoutinePtr (derivRoutinePtr),
92 m_routinesDataPtr (routinesDataPtr)
104 std::cerr <<
"In Generic1D1DFunction::value()"
105 <<
": requested x (" << domainValue
114 "Generic1D1DFunction::value()",
124 std::cerr <<
"In Generic1D1DFunction::deriv()"
125 <<
": requested x (" << domainValue
134 "Generic1D1DFunction::deriv()",
144 double minDomainValue,
145 double maxDomainValue,
146 double constantValue)
149 m_constantValue (constantValue)
161 std::cerr <<
"In Constant1D1DFunction::value()"
162 <<
": requested x (" << domainValue
171 "Constant1D1DFunction::value()",
181 std::cerr <<
"In Constant1D1DFunction::deriv()"
182 <<
": requested x (" << domainValue
191 "Constant1D1DFunction::deriv()",
201 double minDomainValue,
202 double maxDomainValue,
203 double referenceDomainValue,
204 double referenceImageValue,
208 m_referenceDomainValue (referenceDomainValue),
209 m_referenceImageValue (referenceImageValue),
210 m_rateValue (rateValue)
222 std::cerr <<
"In Linear1D1DFunction::value()"
223 <<
": requested x (" << domainValue
232 "Linear1D1DFunction::value()",
244 std::cerr <<
"In Linear1D1DFunction::deriv()"
245 <<
": requested x (" << domainValue
254 "Linear1D1DFunction::deriv()",
264 double minDomainValue,
265 double maxDomainValue,
266 const std::vector<double>& referenceDomainValues,
267 double referenceImageValue0,
268 const std::vector<double>& rateValues)
271 m_numRefValues (referenceDomainValues.size()),
272 m_referenceDomainValues(referenceDomainValues),
273 m_rateValues (rateValues)
277 "PiecewiseLinear1D1DFunction::constructor()",
278 "num ref values = 0");
282 "PiecewiseLinear1D1DFunction::constructor()",
283 "num rate values is inconsistent");
288 "PiecewiseLinear1D1DFunction::constructor()",
289 "reference domain values are inconsistent");
300 std::cout <<
"In PiecewiseLinear1D1DFunction::constructor():"
303 std::cout <<
"i = " << i
323 std::cerr <<
"In PiecewiseLinear1D1DFunction::value()"
324 <<
": requested x (" << domainValue
333 "PiecewiseLinear1D1DFunction::value()",
341 bool referenceDomainValueFound =
false;
342 while (referenceDomainValueFound ==
false) {
344 referenceDomainValueFound =
true;
349 referenceDomainValueFound =
true;
356 std::cout <<
"In PiecewiseLinear1D1DFunction::value()"
357 <<
": domainValue = " << domainValue
362 <<
", imageValue = " << imageValue
373 std::cerr <<
"In PiecewiseLinear1D1DFunction::deriv()"
374 <<
": requested x (" << domainValue
383 "PiecewiseLinear1D1DFunction::deriv()",
391 bool referenceDomainValueFound =
false;
392 while (referenceDomainValueFound ==
false) {
394 referenceDomainValueFound =
true;
400 "PiecewiseLinear1D1DFunction::deriv()",
413 double minDomainValue,
414 double maxDomainValue,
434 std::cerr <<
"In Quadratic1D1DFunction::value()"
435 <<
": requested x (" << domainValue
444 "Quadratic1D1DFunction::value()",
447 double imageValue = m_a*domainValue*domainValue + m_b*domainValue + m_c;
456 std::cerr <<
"In Quadratic1D1DFunction::deriv()"
457 <<
": requested x (" << domainValue
466 "Quadratic1D1DFunction::deriv()",
469 return 2.*m_a*domainValue + m_b;
486 const std::vector<double>& domainValues,
487 const std::vector<double>& imageValues)
490 m_domainValues (domainValues.size(),0.),
491 m_imageValues (imageValues.size(), 0.)
494 for (
unsigned int i = 0; i < tmpSize; ++i) {
508 std::cerr <<
"In Sampled1D1DFunction::value()"
509 <<
": requested x (" << domainValue
518 "Sampled1D1DFunction::value()",
521 double returnValue = 0.;
533 "Sampled1D1DFunction::value()",
534 "m_domainValues.size() = 0");
538 "Sampled1D1DFunction::value()",
539 "domainValue < m_domainValues[0]");
543 "Sampled1D1DFunction::value()",
544 "m_domainValues[max] < domainValue");
547 for (i = 0; i < tmpSize; ++i) {
568 std::cerr <<
"In Sampled1D1DFunction::deriv()"
569 <<
": requested x (" << domainValue
578 "Sampled1D1DFunction::deriv()",
583 "Sampled1d1DFunction::deriv()",
584 "this function makes no sense for this class");
588 const std::vector<double>&
594 const std::vector<double>&
606 for (
unsigned int i = 0; i < tmpSize; ++i) {
618 const std::vector<double>& domainValues,
619 const std::vector<double>& imageValues)
624 unsigned int tmpSize = domainValues.size();
630 for (
unsigned int i = 0; i < tmpSize; ++i) {
641 std::ofstream& ofsvar,
642 const std::string& prefixName)
const
647 ofsvar <<
"\n" << prefixName <<
"Time_sub" << env.
subIdString() <<
" = zeros(" << tmpSize <<
",1);"
648 <<
"\n" << prefixName <<
"Value_sub" << env.
subIdString() <<
" = zeros(" << tmpSize <<
",1);";
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) {
695 std::cerr <<
"In ScalarTimes1D1DFunction::deriv()"
696 <<
": requested x (" << domainValue
705 "ScalarTimes1D1DFunction::deriv()",
710 "ScalarTimesFunc1D1DFunction::deriv()",
711 "not implemented yet");
723 Base1D1DFunction(std::max(func1.minDomainValue(),func2.minDomainValue()),std::min(func1.maxDomainValue(),func2.maxDomainValue())),
749 std::cerr <<
"In FuncTimes1D1DFunction::deriv()"
750 <<
": requested x (" << domainValue
759 "FuncTimes1D1DFunction::deriv()",
764 "FuncTimesFunc1D1DFunction::deriv()",
765 "not implemented yet");
777 Base1D1DFunction(std::max(func1.minDomainValue(),func2.minDomainValue()),std::min(func1.maxDomainValue(),func2.maxDomainValue())),
803 std::cerr <<
"In FuncPlus1D1DFunction::deriv()"
804 <<
": requested x (" << domainValue
813 "FuncPlus1D1DFunction::deriv()",
818 "FuncPlusFunc1D1DFunction::deriv()",
819 "not implemented yet");
828 const std::vector<double>& positionValues,
829 const std::vector<double>* functionValues)
832 m_positionValues(positionValues),
833 m_functionValues(positionValues.size(),1.)
835 if (functionValues) {
838 "LagrangePolynomial1D1DFunction::constructor()",
854 double scaleFactor = 1.;
859 scaleFactor *= (domainValue-posJ)/(posK-posJ);
889 std::cerr <<
"In LagrangePolynomial1D1DFunction::deriv()"
890 <<
": requested x (" << domainValue
899 "LagrangePolynomial1D1DFunction::deriv()",
904 "LagrangePolynomial1D1DFunction::deriv()",
905 "not implemented yet");
914 const std::vector<double>& positionValues,
915 unsigned int basisIndex)
918 m_positionValues(positionValues),
919 m_basisIndex (basisIndex)
923 "LagrangeBasis1D1DFunction::constructor()",
934 double scaleFactor = 1.;
941 scaleFactor *= (domainValue-posJ)/(posK-posJ);
954 std::cerr <<
"In LagrangeBasis1D1DFunction::deriv()"
955 <<
": requested x (" << domainValue
964 "LagrangeBasis1D1DFunction::deriv()",
969 "LagrangeBasis1D1DFunction::deriv()",
970 "not implemented yet");
979 unsigned int initialPos,
984 unsigned int quadratureOrder)
986 double resultValue = 0.;
990 "SubF1F2Gaussian2dKdeIntegral()",
991 "not implemented yet for initialPos != 0");
994 "SubF1F2Gaussian2dKdeIntegral()",
998 const std::vector<double>& quadPositions = quadObj.positions();
999 const std::vector<double>& quadWeights = quadObj.weights ();
1002 "SubF1F2Gaussian2dKdeIntegral()",
1003 "quadObj has invalid state");
1005 unsigned int numQuadraturePositions = quadPositions.size();
1007 for (
unsigned int k = 0; k < dataSize; ++k) {
1010 double x1k = scalarSeq1[k];
1011 double x2k = scalarSeq2[k];
1012 for (
unsigned int j = 0; j < numQuadraturePositions; ++j) {
1013 value1 += func1.
value(scaleValue1*quadPositions[j]+x1k)*quadWeights[j];
1014 value2 += func2.
value(scaleValue2*quadPositions[j]+x2k)*quadWeights[j];
1016 resultValue += value1*value2;
1018 resultValue *= 1./(2.*M_PI)/((
double) dataSize);
const std::string & subIdString() const
Access to the attribute m_subIdString; which stores the string for the sub-environment, and it will be used, for instance, to create the output files for each sub-environment.
double deriv(double domainValue) const
Returns the value of the derivative of the constant function at point domainValue.
PiecewiseLinear1D1DFunction(double minDomainValue, double maxDomainValue, const std::vector< double > &referenceDomainValues, double referenceImageValue0, const std::vector< double > &rateValues)
Default constructor.
double deriv(double domainValue) const
TODO: Returns the value of the derivative of the function func1 by another function func2 at the poin...
double deriv(double domainValue) const
TODO: Returns the value of the derivative of the function multiplied by the given scalar at point dom...
virtual double value(double domainValue) const =0
Returns the value of the (one-dimensional) function. See template specialization. ...
virtual double multiplyAndIntegrate(const Base1D1DFunction &func, unsigned int quadratureOrder, double *resultWithMultiplicationByTAsWell) const
TODO: Multiplies this function with function, and integrates it numerically. See template specializat...
double(* m_valueRoutinePtr)(double domainValue, const void *routinesDataPtr)
~LagrangeBasis1D1DFunction()
Destructor.
virtual ~Sampled1D1DFunction()
Destructor.
std::vector< double > m_positionValues
double value(double domainValue) const
Returns the value of the linear function at point domainValue.
const std::vector< double > & imageValues() const
Array of the image values (values of the dependent variable).
std::vector< double > m_imageValues
Array of the values in the image of the function (values of the dependent variable).
virtual double deriv(double domainValue) const =0
Returns the value of the derivative of the function. See template specialization. ...
const std::vector< double > & domainValues() const
Array of the domain values (values of the independent variable).
unsigned int m_basisIndex
~Linear1D1DFunction()
Destructor.
int worldRank() const
Returns the process world rank.
Constant1D1DFunction(double minDomainValue, double maxDomainValue, double constantValue)
Default constructor.
Base1D1DFunction(double minDomainValue, double maxDomainValue)
Default constructor.
const int UQ_UNAVAILABLE_RANK
double m_referenceImageValue
Reference value in the function image; in .
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 sampl...
double maxDomainValue() const
Returns the maximum value of the domain of the (one-dimensional) function.
double deriv(double domainValue) const
TODO: Returns the value of the derivative of the Lagrange basis at point domainValue.
double value(double domainValue) const
Returns the value of the multiplication of a function func1 by another function func2 at the point do...
Class for handling scalar samples.
std::vector< double > m_referenceDomainValues
Reference values in the piecewise-linear function domain; in , for each =1 .. m_numRefValues.
const Base1D1DFunction & m_func2
double value(double domainValue) const
Returns the value of the addition of function func1 and func2 evaluated at the point domainValue...
FuncTimesFunc1D1DFunction(const Base1D1DFunction &func1, const Base1D1DFunction &func2)
Default constructor.
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
double SubF1F2Gaussian2dKdeIntegral(const ScalarSequence< T > &scalarSeq1, const ScalarSequence< T > &scalarSeq2, unsigned int initialPos, double scaleValue1, double scaleValue2, const Base1D1DFunction &func1, const Base1D1DFunction &func2, unsigned int quadratureOrder)
Calculates the integral of a 2D Gaussian KDE.
FuncPlusFunc1D1DFunction(const Base1D1DFunction &func1, const Base1D1DFunction &func2)
Default constructor.
Linear1D1DFunction(double minDomainValue, double maxDomainValue, double referenceDomainValue, double referenceImageValue, double rateValue)
Default constructor.
std::vector< double > m_positionValues
double m_referenceDomainValue
Reference value in the function domain; in .
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
const Base1D1DFunction & m_func2
double value(double domainValue) const
Returns the value of the Lagrange basis at point domainValue.
double value(double domainValue) const
Returns the value of the piecewise-linear function at point domainValue.
std::vector< double > m_referenceImageValues
Reference values in the piecewise-linear function image; in , for each =1 .. m_numRefValues.
~FuncTimesFunc1D1DFunction()
Destructor.
bool domainValueMatchesExactly(double domainValue) const
Checks whether the domain value domainValue matches exactly one of the values in the function domain ...
Generic1D1DFunction(double minDomainValue, double maxDomainValue, double(*valueRoutinePtr)(double domainValue, const void *routinesDataPtr), double(*derivRoutinePtr)(double domainValue, const void *routinesDataPtr), const void *routinesDataPtr)
Default constructor.
~PiecewiseLinear1D1DFunction()
Destructor.
virtual void printForMatlab(const BaseEnvironment &env, std::ofstream &ofsvar, const std::string &prefixName) const
Prints the values of the function in Matlab/Octave format.
~ScalarTimesFunc1D1DFunction()
Destructor.
double deriv(double domainValue) const
Bogus: Derivative of the function.
double value(double domainValue) const
Returns the value of the Lagrange polynomial at point domainValue.
double value(double domainValue) const
Returns the value of the (one-dimensional) function at point domainValue, already multiplied by the s...
~Generic1D1DFunction()
Destructor.
double value(double domainValue) const
Returns the value of the constant function at point domainValue.
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
double deriv(double domainValue) const
TODO: Returns the value of the derivative of the Lagrange polynomial at point domainValue.
std::vector< double > m_domainValues
Array of the values in the domain of the function (values of the independent variable).
LagrangeBasis1D1DFunction(const std::vector< double > &positionValues, unsigned int basisIndex)
Default constructor.
std::vector< double > m_rateValues
Rate value; in , for each =1 .. m_numRefValues.
virtual ~Base1D1DFunction()
Destructor.
unsigned int m_numRefValues
Number of points which will be evaluated.
Class for Hermite-Gauss quadrature rule for one-dimensional functions.
const BaseEnvironment & env() const
Access to QUESO environment.
Quadratic1D1DFunction(double minDomainValue, double maxDomainValue, double a, double b, double c)
Default constructor.
double value(double domainValue) const
Returns the value of the (one-dimensional) function at point domainValue.
~FuncPlusFunc1D1DFunction()
Destructor.
double deriv(double domainValue) const
Returns the value of the derivative of the piecewise-linear function at point domainValue.
std::vector< double > m_functionValues
~Quadratic1D1DFunction()
Destructor.
LagrangePolynomial1D1DFunction(const std::vector< double > &positionValues, const std::vector< double > *functionValues)
Default constructor.
double deriv(double domainValue) const
TODO: Returns the value of the derivative of the addition of two functions.
const Base1D1DFunction & m_func1
const Base1D1DFunction & m_func
double deriv(double domainValue) const
Returns the value of the derivative of the function at point domainValue.
double(* m_derivRoutinePtr)(double domainValue, const void *routinesDataPtr)
ScalarTimesFunc1D1DFunction(double scalar, const Base1D1DFunction &func)
Default constructor.
Class for one-dimensional functions.
Sampled1D1DFunction()
Default constructor. It should not be called by the user.
double deriv(double domainValue) const
Returns the value of the derivative of the linear function at point domainValue.
const void * m_routinesDataPtr
const Base1D1DFunction & m_func1
double minDomainValue() const
Returns the minimum value of the domain of the (one-dimensional) function.
~Constant1D1DFunction()
Destructor.
~LagrangePolynomial1D1DFunction()
Destructor.
virtual double value(double domainValue) const
Returns the value of the sampled function at point domainValue.
double m_rateValue
Rate value; in .