tension_splines.cpp
Go to the documentation of this file.
1 
9 /*****************************************************************************
10 ** Includes
11 *****************************************************************************/
12 
13 #include <iostream>
14 #include <string>
15 #include <gtest/gtest.h>
16 #include <ecl/containers/array.hpp>
19 #include "../../include/ecl/geometry/tension_spline.hpp"
20 
21 /*****************************************************************************
22 ** Using
23 *****************************************************************************/
24 
25 using std::cout; using std::endl;
26 using std::string;
27 using ecl::Array;
28 using ecl::RightAlign;
29 using ecl::Format;
30 using ecl::TensionSpline;
31 
32 /*****************************************************************************
33 ** Tests
34 *****************************************************************************/
35 
36 TEST(TensionFunctionSplines,allEggsInOneBasket) {
37  // Haven't got around to running this properly through gtests yet.
38  SUCCEED();
39 }
40 /*****************************************************************************
41 ** Main program
42 *****************************************************************************/
43 
44 int main(int argc, char **argv) {
45 
46  Format<string> string_format; string_format.width(8); string_format.align(RightAlign);
47  Format<double> format; format.width(8); format.precision(2); format.align(RightAlign);
48 
49  /*********************
50  ** Initialisation
51  **********************/
52  Array<double> x_set(6);
53  Array<double> y_set(6);
54  x_set << 0.0, 1.0, 2.0, 3.0, 4.0, 5.0;
55  y_set << 1.0, 2.0, 1.0, 3.0, 4.0, 4.0;
56 // Array<double> x_set(5);
57 // Array<double> y_set(5);
58 // x_set = 0.0, 0.43, 1, 1.4, 2.86;
59 // y_set = 0.3, 0.1, -0.27, -0.53, -0.43;
60  int n = 50;
61 
62  cout << endl;
63  cout << "***********************************************************" << endl;
64  cout << " Tension Spline Blueprint" << endl;
65  cout << "***********************************************************" << endl;
66  cout << endl;
67 
68  /*********************
69  ** Generation
70  **********************/
71  TensionSpline spline_0_1 = TensionSpline::Natural(x_set, y_set, 0.1);
72  TensionSpline spline_1 = TensionSpline::Natural(x_set, y_set, 1.0);
73  TensionSpline spline_2 = TensionSpline::Natural(x_set, y_set, 2.0);
74  TensionSpline spline_3 = TensionSpline::Natural(x_set, y_set, 3.0);
75  TensionSpline spline_4 = TensionSpline::Natural(x_set, y_set, 4.0);
76  TensionSpline spline_10 = TensionSpline::Natural(x_set, y_set, 10.0);
77  cout << spline_1 << endl;
78 
79  cout << endl;
80  cout << "***********************************************************" << endl;
81  cout << " Output : Splines" << endl;
82  cout << "***********************************************************" << endl;
83  cout << endl;
84 
85  /*********************
86  ** Output
87  **********************/
88  std::cout << string_format("t=0.1");
89  std::cout << string_format("t=1");
90  std::cout << string_format("t=2");
91  std::cout << string_format("t=3");
92  std::cout << string_format("t=4");
93  std::cout << string_format("t=10") << std::endl;
94  for ( int i = 0; i <= n; ++i ) {
95  double x = i*(x_set.back()-x_set.front())/n;
96  std::cout << format(spline_0_1(x));
97  std::cout << format(spline_1(x));
98  std::cout << format(spline_2(x));
99  std::cout << format(spline_3(x));
100  std::cout << format(spline_4(x));
101  std::cout << format(spline_10(x));
102  std::cout << std::endl;
103  }
104 
105  cout << endl;
106  cout << "***********************************************************" << endl;
107  cout << " Output : Derivatives" << endl;
108  cout << "***********************************************************" << endl;
109  cout << endl;
110 
111  /*********************
112  ** Output
113  **********************/
114  std::cout << string_format("t=0.1");
115  std::cout << string_format("t=1");
116  std::cout << string_format("t=2");
117  std::cout << string_format("t=3");
118  std::cout << string_format("t=4");
119  std::cout << string_format("t=10") << std::endl;
120  for ( int i = 0; i <= n; ++i ) {
121  double x = i*(x_set.back()-x_set.front())/n;
122  std::cout << format(spline_0_1.derivative(x));
123  std::cout << format(spline_1.derivative(x));
124  std::cout << format(spline_2.derivative(x));
125  std::cout << format(spline_3.derivative(x));
126  std::cout << format(spline_4.derivative(x));
127  std::cout << format(spline_10.derivative(x));
128  std::cout << std::endl;
129  }
130 
131  cout << endl;
132  cout << "***********************************************************" << endl;
133  cout << " Output : 2nd Derivatives" << endl;
134  cout << "***********************************************************" << endl;
135  cout << endl;
136 
137  /*********************
138  ** Output
139  **********************/
140  std::cout << string_format("t=0.1");
141  std::cout << string_format("t=1");
142  std::cout << string_format("t=2");
143  std::cout << string_format("t=3");
144  std::cout << string_format("t=4");
145  std::cout << string_format("t=10") << std::endl;
146  for ( int i = 0; i <= n; ++i ) {
147  double x = i*(x_set.back()-x_set.front())/n;
148  std::cout << format(spline_0_1.dderivative(x));
149  std::cout << format(spline_1.dderivative(x));
150  std::cout << format(spline_2.dderivative(x));
151  std::cout << format(spline_3.dderivative(x));
152  std::cout << format(spline_4.dderivative(x));
153  std::cout << format(spline_10.dderivative(x));
154  std::cout << std::endl;
155  }
156 
157  cout << endl;
158  cout << "***********************************************************" << endl;
159  cout << " Passed" << endl;
160  cout << "***********************************************************" << endl;
161  cout << endl;
162 
163  testing::InitGoogleTest(&argc,argv);
164  return RUN_ALL_TESTS();
165 }
double dderivative(const double &x) const
Spline second derivative.
int main(int argc, char **argv)
Storage container for a tension spline interpolation.
double derivative(const double &x) const
Spline derivative.
TEST(TensionFunctionSplines, allEggsInOneBasket)
RightAlign
reference back()
reference front()


ecl_geometry
Author(s): Daniel Stonier
autogenerated on Mon Feb 28 2022 22:18:49