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     //double MoveoutCorrection::CalcTraveltime(const double rayparameter,
00037     //    const double depth)
00038     //  {
00039     //    Model.SetSourceDepth(depth);
00040     //    double precdist = Model.MatchSlowness(rayparameter, SeismicModel::DirectP);
00041     //    Model.SetRecDist().push_back(precdist);
00042     //    double ptime = Model.CalcArrival(SeismicModel::DirectP, Model.GetRecDist().size()-1);
00043     //    double srecdist = Model.MatchSlowness(rayparameter, SeismicModel::DirectS);
00044     //    Model.SetRecDist().back() = srecdist;
00045     //    double stime = Model.CalcArrival(SeismicModel::DirectS, Model.GetRecDist().size()-1);
00046     //    double distdiff = precdist - srecdist;
00047     //    double angle = PI/2. - asin(rayparameter*Model.GetPVelocity().at(Model.FindLayer(Model.GetSourceDepth())));
00048     //    double extratotaldist = sin(angle) * distdiff;
00049     //    double extravdist = cos(PI/2.0 - angle) * extratotaldist;
00050     //    double extratime = Model.CalcTravelTime(SeismicModel::DirectP, extravdist
00051     //        +depth, depth, rayparameter);
00052     //    timesfile << depth << "  " << stime << " " << ptime << " "<< extratime
00053     //        << endl;
00054     //    return stime + extratime - ptime;
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         //    for (int i = 0; i < actdepths.size(); ++i)
00106         //      {
00107         //        depthfile << actdepths.at(i) << " " << amps.at(i) << endl;
00108         //
00109         //        timesfile << times.at(i) << " " << actdepths.at(i) << endl;
00110         //      }
00111         copy(newamps.begin(), newamps.end(), Rec.GetData().begin());
00112       }
00113   }

Generated on Tue May 4 16:52:14 2010 for GPLIB++ by  doxygen 1.5.8