31#include "ithacaInterpolator.H"
34#include "splinterRBF.H"
37ithacaInterpolator::ithacaInterpolator(
const Foam::dictionary& dict)
39 package_ = dict.lookupOrDefault<Foam::word>(
"package",
"mathtoolbox");
40 algorithm_ = dict.lookupOrDefault<Foam::word>(
"algorithm",
"RBF");
42 if (package_ ==
"mathtoolbox")
44 if (algorithm_ ==
"RBF" || algorithm_ ==
"rbf")
46 mtb_ = std::make_unique<mtbRBF>(dict);
48 else if (algorithm_ ==
"GPR" || algorithm_ ==
"gpr")
50 mtbGPR_ = std::make_unique<mtbGPR>(dict);
55 <<
"Unknown algorithm for mathtoolbox package: " << algorithm_
56 <<
". Valid options are: RBF, GPR"
57 << Foam::exit(Foam::FatalError);
60 else if (package_ ==
"splinter")
62 if (algorithm_ !=
"RBF" && algorithm_ !=
"rbf")
65 <<
"Unknown algorithm for splinter package: " << algorithm_
66 <<
". Valid option is: RBF"
67 << Foam::exit(Foam::FatalError);
69 splinter_ = std::make_unique<splinterRBF>(dict);
74 <<
"Unknown package: " << package_
75 <<
". Valid options are: mathtoolbox, splinter"
76 << Foam::exit(Foam::FatalError);
80ithacaInterpolator::~ithacaInterpolator() =
default;
82void ithacaInterpolator::fit(
const Eigen::MatrixXd& X,
const Eigen::VectorXd& y)
84 if (package_ ==
"mathtoolbox")
97 <<
"mathtoolbox algorithm not initialized"
98 << Foam::exit(Foam::FatalError);
101 else if (package_ ==
"splinter")
103 if (algorithm_ !=
"RBF" && algorithm_ !=
"rbf")
106 <<
"Unknown algorithm for splinter package: " << algorithm_
107 <<
". Valid option is: RBF"
108 << Foam::exit(Foam::FatalError);
110 splinter_->fit(X, y);
115 <<
"Unknown package: " << package_
116 << Foam::exit(Foam::FatalError);
120double ithacaInterpolator::predict(
const Eigen::VectorXd& x)
122 if (package_ ==
"mathtoolbox")
126 return mtb_->predict(x);
130 return mtbGPR_->predict(x);
135 <<
"mathtoolbox algorithm not initialized"
136 << Foam::exit(Foam::FatalError);
139 else if (package_ ==
"splinter")
141 if (algorithm_ !=
"RBF" && algorithm_ !=
"rbf")
144 <<
"Unknown algorithm for splinter package: " << algorithm_
145 <<
". Valid option is: RBF"
146 << Foam::exit(Foam::FatalError);
148 return splinter_->predict(x);
153 <<
"Unknown package: " << package_
154 << Foam::exit(Foam::FatalError);
159Eigen::VectorXd ithacaInterpolator::predict(
const Eigen::MatrixXd& X)
161 if (package_ ==
"mathtoolbox")
165 return mtb_->predict(X);
169 return mtbGPR_->predict(X);
174 <<
"mathtoolbox algorithm not initialized"
175 << Foam::exit(Foam::FatalError);
178 else if (package_ ==
"splinter")
180 if (algorithm_ !=
"RBF" && algorithm_ !=
"rbf")
183 <<
"Unknown algorithm for splinter package: " << algorithm_
184 <<
". Valid option is: RBF"
185 << Foam::exit(Foam::FatalError);
187 return splinter_->predict(X);
192 <<
"Unknown package: " << package_
193 << Foam::exit(Foam::FatalError);
195 return Eigen::VectorXd();
198void ithacaInterpolator::printInfo()
const
200 if (package_ ==
"mathtoolbox")
208 mtbGPR_->printInfo();
213 <<
"mathtoolbox algorithm not initialized"
214 << Foam::exit(Foam::FatalError);
217 else if (package_ ==
"splinter")
219 if (algorithm_ !=
"RBF" && algorithm_ !=
"rbf")
222 <<
"Unknown algorithm for splinter package: " << algorithm_
223 <<
". Valid option is: RBF"
224 << Foam::exit(Foam::FatalError);
226 splinter_->printInfo();
231 <<
"Unknown package: " << package_
232 << Foam::exit(Foam::FatalError);