Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
InterpolantBase.cpp
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 *
3 *
4 * MoDELib is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef model_InterpolantBase_cpp_
9#define model_InterpolantBase_cpp_
10
11#include <iostream>
12#include <algorithm>
13#include <InterpolantBase.h>
14
15namespace model
16{
17
19/* init */ type(0)
20/* init */,period(0.0)
21{
22
23}
24
26/* init */ type(t)
27/* init */,period(std::fabs(p))
28{
29
30}
31
33 /* init */ MapType(data)
34 /* init */,extrapolation(extrap)
35 {
37 if(map().size()==0)
38 {
39 throw std::runtime_error("InterpolantBase: sortedData is empty.");
40 }
41
42 if(extrapolation.type==2)
43 {
44 if(extrapolation.period<xMax()-xMin())
45 {
46 throw std::runtime_error("InterpolantBase: extrapolation.period < xMax-xMin.");
47 }
48 }
49 }
50
52 /* init */ InterpolantBase(matrix2Map(data),extrap)
53 {
54 }
55
60
61 typename InterpolantBase::MapType InterpolantBase::matrix2Map(const MatrixType& data)
62 {
64 for(int r=0;r<data.rows();++r)
65 {
66 const auto success(temp.emplace(data(r,0),data(r,1)));
67 if(!success.second)
68 {
69 std::cout<<"x="<<data(r,0)<<", y="<<data(r,1)<<std::endl;
70 throw std::runtime_error("InterpolantBase::convertData found non-unique x values.");
71 }
72 }
73 return temp;
74 }
75
76typename InterpolantBase::MatrixType InterpolantBase::map2Matrix(const MapType& data)
77{
78 MatrixType temp(data.size(),2);
79 int k(0);
80 for(const auto& pair : data)
81 {
82 temp(k,0)=pair.first;
83 temp(k,1)=pair.second;
84 k++;
85 }
86 return temp;
87}
88
89 double InterpolantBase::xMin() const
90 {
91 return this->begin()->first;
92 }
93
94 double InterpolantBase::xMax() const
95 {
96 return this->rbegin()->first;
97 }
98
99 double InterpolantBase::f(const double& x) const
100 {
101 if(extrapolation.type==2)
102 {
103 return _f(std::fmod(x-xMin(),extrapolation.period)+xMin()+(x-xMin()<0.0? extrapolation.period : 0.0));
104 }
105 else
106 {
107 return _f(x);
108 }
109 }
110
111 double InterpolantBase::operator()(const double& x) const
112 {
113 return f(x);
114 }
115
116//double InterpolantBase::atPeriodic(const double& x,const double& a,const double& b) const
117//{
118// const double xL(std::min(a,b));
119// const double xH(std::max(a,b));
120//
121// if(xL>xMin() || xH<xMax())
122// {
123// throw std::runtime_error("InterpolantBase::atPeriodic periodic limits must include data range.");
124// return 0.0;
125// }
126//
127// const double y(std::fmod(x-xL, xH-xL)+xL); SOMETHING WRONG HERE
128//
129// return this->operator()(y);
130//}
131
132
133
135 {
136 return *this;
137 }
138
140 {
141 return *this;
142 }
143
144} // close namespace model
145#endif
Eigen::Matrix< double, Eigen::Dynamic, 2 > MatrixType
InterpolantBase(const MapType &data, const ExtrapolationMethod &extrap)
double f(const double &x) const
std::map< double, double > MapType
double operator()(const double &x) const
ExtrapolationMethod extrapolation
final point of the source segment t
function int_R syms a b c u real f
Definition int_R.m:4
x
Definition int_R.m:12
vertex p[3]
int k
enum insertvertexresult success
vertex temp