-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathConstantCorrelationFunction.cpp
112 lines (98 loc) · 2.83 KB
/
ConstantCorrelationFunction.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//#############################################################################
//
// FILENAME: ConstantCorrelationFunction.cpp
//
// CLASSIFICATION: Unclassified
//
// DESCRIPTION:
//
// The constant correlation function class is derived from
// the SPDCorrelationFunction base class. This class is used to represent
// a correlation function which has a value of 1.0 for deltaTime within
// "delta time epsilon" of 0.0, and a user defined constant value elsewhere.
//
// The class is a wrapper around the equation
//
// rho(deltaTime) = A
//
// LIMITATIONS: None
//
//
// SOFTWARE HISTORY:
// Date Author Comment
// ----------- ------ -------
// 12-Nov-2023 JPK Initial Coding
// 22-Nov-2023 JPK Added checkParameter() static method.
//
// NOTES:
//
//#############################################################################
#define CSM_LIBRARY
#include "ConstantCorrelationFunction.h"
#include "Error.h"
#include <cmath>
#include <sstream>
namespace csm
{
static const std::string COCF_NAME = "Constant";
static const std::string PARAM_NAME = "Rho";
ConstantCorrelationFunction::ConstantCorrelationFunction()
:
SPDCorrelationFunction (COCF_NAME,0.0),
theRho (0.0)
{}
ConstantCorrelationFunction::
ConstantCorrelationFunction(double corrCoeff,
double deltaTimeEpsilon)
:
SPDCorrelationFunction (COCF_NAME,deltaTimeEpsilon),
theRho (corrCoeff)
{
checkParameter(theRho);
}
void ConstantCorrelationFunction::setCorrelationCoefficient(double argRho)
{
theRho = argRho;
checkParameter(theRho);
}
ConstantCorrelationFunction::~ConstantCorrelationFunction()
{}
double ConstantCorrelationFunction::
getCorrelationCoefficient(double deltaTime) const
{
if (deltaTime != 0.0)
{
if (std::fabs(deltaTime) >= deltaTimeEpsilon())
{
return theRho;
}
}
//***
// if delta time is bounded by epsilon, correlation coefficient is 1.0
//***
return 1.0;
}
std::vector<SPDCorrelationFunction::Parameter>
ConstantCorrelationFunction::parameters() const
{
return std::vector<SPDCorrelationFunction::
Parameter>(1,
std::make_pair(PARAM_NAME,theRho));
}
void ConstantCorrelationFunction::checkParameter(double corrCoeff)
{
static const std::string METHOD_NAME =
"ConstantCorrelationFunction::checkParameter";
if (fabs(corrCoeff) > 1.0)
{
std::stringstream errorStrm;
errorStrm << "Provided correlation coefficient : "
<< corrCoeff
<< " is outside the valid range [-1.0,1.0]";
throw Error(
Error::INVALID_USE,
errorStrm.str(),
METHOD_NAME);
}
}
} // namespace csm