MoveoutCorrection.cpp
Go to the documentation of this file.00001 #include "MoveoutCorrection.h"
00002 #include <vector>
00003 #include <iostream>
00004 #include <fstream>
00005 #include <gsl/gsl_errno.h>
00006 #include <gsl/gsl_spline.h>
00007
00008 using namespace std;
00009
00010 namespace gplib
00011 {
00012 MoveoutCorrection::MoveoutCorrection(const double refslow,
00013 const ResPkModel &TheModel) :
00014 refslowness(refslow), Model(TheModel)
00015 {
00016 }
00017
00018 void MoveoutCorrection::InterpolateTo(trealdata &oldx, trealdata &y,
00019 trealdata &newx, trealdata &newy)
00020 {
00021 gsl_interp_accel *gslacc = gsl_interp_accel_alloc();
00022 gsl_spline *spline = gsl_spline_alloc(gsl_interp_linear, oldx.size());
00023 cout << "Oldx: " << oldx.size() << endl;
00024 cout << "Newx: " << newx.size() << endl;
00025 gsl_spline_init(spline, &oldx[0], &y[0], newx.size());
00026 newy.clear();
00027 for (int i = 0; i < newx.size(); ++i)
00028 {
00029 newy.push_back(gsl_spline_eval(spline, newx.at(i), gslacc));
00030 }
00031
00032 gsl_spline_free(spline);
00033 gsl_interp_accel_free(gslacc);
00034 }
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 double MoveoutCorrection::CalcTraveltime(const double rayparameter,
00058 const double depth)
00059 {
00060 int sourceindex = Model.FindLayer(depth);
00061 double deltat = 0.0;
00062 double currdepth = 0.0;
00063 const double p2 = rayparameter * rayparameter;
00064 for (int i = 0; i < sourceindex; ++i)
00065 {
00066 currdepth += Model.GetThickness().at(i);
00067 double u = 1. / Model.GetPVelocity().at(i);
00068 deltat += Model.GetThickness().at(i) * (sqrt(pow(1.
00069 / Model.GetSVelocity().at(i), 2) - p2) - sqrt(pow(1.
00070 / Model.GetPVelocity().at(i), 2) - p2));
00071 }
00072 deltat += (depth - currdepth) * (sqrt(pow(1. / Model.GetSVelocity().at(
00073 sourceindex), 2) - p2) - sqrt(pow(1. / Model.GetPVelocity().at(
00074 sourceindex), 2) - p2));
00075 return deltat;
00076 }
00077
00078 void MoveoutCorrection::DoCorrection(SeismicDataComp &Rec,
00079 const double slowness)
00080 {
00081 const double maxdepth = 350;
00082 const int nelements = Rec.GetData().size();
00083 const double dt = Rec.GetDt();
00084 std::vector<double> refdeltat, deltat, depths, refdepths, actdepths,
00085 times, newtimes, amps, newamps;
00086 copy(Rec.GetData().begin(), Rec.GetData().end(), back_inserter(amps));
00087 cout << "Ref slow: " << refslowness << " Slow: " << slowness << endl;
00088 ofstream depthfile("depths");
00089 ofstream deltatfile("deltat");
00090 ofstream timesfile("times");
00091 for (double i = 1.0; i < maxdepth; i += 1.0)
00092 {
00093 depths.push_back(i);
00094 times.push_back(i * dt + Rec.GetB());
00095 refdeltat.push_back(CalcTraveltime(refslowness, i));
00096 deltat.push_back(CalcTraveltime(slowness, i));
00097 deltatfile << deltat.at(i) << " " << depths.at(i) << endl;
00098 cout << "Deltat: " << deltat.back() << " Ref Deltat: "
00099 << refdeltat.back() << endl;
00100 }
00101 InterpolateTo(deltat, depths, times, actdepths);
00102 InterpolateTo(depths, refdeltat, actdepths, newtimes);
00103 InterpolateTo(newtimes, amps, times, newamps);
00104
00105
00106
00107
00108
00109
00110
00111 copy(newamps.begin(), newamps.end(), Rec.GetData().begin());
00112 }
00113 }