tension_splines.cpp
Go to the documentation of this file.
00001 
00009 /*****************************************************************************
00010 ** Includes
00011 *****************************************************************************/
00012 
00013 #include <iostream>
00014 #include <string>
00015 #include <gtest/gtest.h>
00016 #include <ecl/containers/array.hpp>
00017 #include <ecl/formatters/floats.hpp>
00018 #include <ecl/formatters/strings.hpp>
00019 #include "../../include/ecl/geometry/tension_spline.hpp"
00020 
00021 /*****************************************************************************
00022 ** Using
00023 *****************************************************************************/
00024 
00025 using std::cout; using std::endl;
00026 using std::string;
00027 using ecl::Array;
00028 using ecl::RightAlign;
00029 using ecl::Format;
00030 using ecl::TensionSpline;
00031 
00032 /*****************************************************************************
00033 ** Tests
00034 *****************************************************************************/
00035 
00036 TEST(TensionFunctionSplines,allEggsInOneBasket) {
00037         // Haven't got around to running this properly through gtests yet.
00038         SUCCEED();
00039 }
00040 /*****************************************************************************
00041 ** Main program
00042 *****************************************************************************/
00043 
00044 int main(int argc, char **argv) {
00045 
00046     Format<string> string_format; string_format.width(8); string_format.align(RightAlign);
00047     Format<double> format; format.width(8); format.precision(2); format.align(RightAlign);
00048 
00049     /*********************
00050     ** Initialisation
00051     **********************/
00052     Array<double> x_set(6);
00053     Array<double> y_set(6);
00054     x_set << 0.0, 1.0, 2.0, 3.0, 4.0, 5.0;
00055     y_set << 1.0, 2.0, 1.0, 3.0, 4.0, 4.0;
00056 //    Array<double> x_set(5);
00057 //    Array<double> y_set(5);
00058 //    x_set = 0.0, 0.43, 1, 1.4, 2.86;
00059 //    y_set = 0.3, 0.1, -0.27, -0.53, -0.43;
00060     int n = 50;
00061 
00062     cout << endl;
00063     cout << "***********************************************************" << endl;
00064     cout << "              Tension Spline Blueprint" << endl;
00065     cout << "***********************************************************" << endl;
00066     cout << endl;
00067 
00068     /*********************
00069     ** Generation
00070     **********************/
00071     TensionSpline spline_0_1 = TensionSpline::Natural(x_set, y_set, 0.1);
00072     TensionSpline spline_1 = TensionSpline::Natural(x_set, y_set, 1.0);
00073     TensionSpline spline_2 = TensionSpline::Natural(x_set, y_set, 2.0);
00074     TensionSpline spline_3 = TensionSpline::Natural(x_set, y_set, 3.0);
00075     TensionSpline spline_4 = TensionSpline::Natural(x_set, y_set, 4.0);
00076     TensionSpline spline_10 = TensionSpline::Natural(x_set, y_set, 10.0);
00077     cout << spline_1 << endl;
00078 
00079     cout << endl;
00080     cout << "***********************************************************" << endl;
00081     cout << "                   Output : Splines" << endl;
00082     cout << "***********************************************************" << endl;
00083     cout << endl;
00084 
00085     /*********************
00086     ** Output
00087     **********************/
00088     std::cout << string_format("t=0.1");
00089     std::cout << string_format("t=1");
00090     std::cout << string_format("t=2");
00091     std::cout << string_format("t=3");
00092     std::cout << string_format("t=4");
00093     std::cout << string_format("t=10") << std::endl;
00094     for ( int i = 0; i <= n; ++i ) {
00095         double x = i*(x_set.back()-x_set.front())/n;
00096         std::cout << format(spline_0_1(x));
00097         std::cout << format(spline_1(x));
00098         std::cout << format(spline_2(x));
00099         std::cout << format(spline_3(x));
00100         std::cout << format(spline_4(x));
00101         std::cout << format(spline_10(x));
00102         std::cout << std::endl;
00103     }
00104 
00105     cout << endl;
00106     cout << "***********************************************************" << endl;
00107     cout << "                 Output : Derivatives" << endl;
00108     cout << "***********************************************************" << endl;
00109     cout << endl;
00110 
00111     /*********************
00112     ** Output
00113     **********************/
00114     std::cout << string_format("t=0.1");
00115     std::cout << string_format("t=1");
00116     std::cout << string_format("t=2");
00117     std::cout << string_format("t=3");
00118     std::cout << string_format("t=4");
00119     std::cout << string_format("t=10") << std::endl;
00120     for ( int i = 0; i <= n; ++i ) {
00121         double x = i*(x_set.back()-x_set.front())/n;
00122         std::cout << format(spline_0_1.derivative(x));
00123         std::cout << format(spline_1.derivative(x));
00124         std::cout << format(spline_2.derivative(x));
00125         std::cout << format(spline_3.derivative(x));
00126         std::cout << format(spline_4.derivative(x));
00127         std::cout << format(spline_10.derivative(x));
00128         std::cout << std::endl;
00129     }
00130 
00131     cout << endl;
00132     cout << "***********************************************************" << endl;
00133     cout << "                 Output : 2nd Derivatives" << endl;
00134     cout << "***********************************************************" << endl;
00135     cout << endl;
00136 
00137     /*********************
00138     ** Output
00139     **********************/
00140     std::cout << string_format("t=0.1");
00141     std::cout << string_format("t=1");
00142     std::cout << string_format("t=2");
00143     std::cout << string_format("t=3");
00144     std::cout << string_format("t=4");
00145     std::cout << string_format("t=10") << std::endl;
00146     for ( int i = 0; i <= n; ++i ) {
00147         double x = i*(x_set.back()-x_set.front())/n;
00148         std::cout << format(spline_0_1.dderivative(x));
00149         std::cout << format(spline_1.dderivative(x));
00150         std::cout << format(spline_2.dderivative(x));
00151         std::cout << format(spline_3.dderivative(x));
00152         std::cout << format(spline_4.dderivative(x));
00153         std::cout << format(spline_10.dderivative(x));
00154         std::cout << std::endl;
00155     }
00156 
00157     cout << endl;
00158     cout << "***********************************************************" << endl;
00159     cout << "                      Passed" << endl;
00160     cout << "***********************************************************" << endl;
00161     cout << endl;
00162 
00163     testing::InitGoogleTest(&argc,argv);
00164     return RUN_ALL_TESTS();
00165 }


ecl_geometry
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 21:17:52