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 ofstream timesfile("times.detail");
00011 MoveoutCorrection::MoveoutCorrection(const double refslow,
00012     const ResPkModel &TheModel) :
00013   refslowness(refslow), Model(TheModel)
00014   {
00015   }
00016 
00017 void MoveoutCorrection::InterpolateTo(trealdata &oldx, trealdata &y,
00018     trealdata &newx, trealdata &newy)
00019   {
00020     gsl_interp_accel *gslacc = gsl_interp_accel_alloc();
00021     gsl_spline *spline = gsl_spline_alloc(gsl_interp_linear, oldx.size());
00022     cout << "Oldx: " << oldx.size() << endl;
00023     cout << "Newx: " << newx.size() << endl;
00024     gsl_spline_init(spline, &oldx[0], &y[0], newx.size());
00025     newy.clear();
00026     for (int i = 0; i < newx.size(); ++i)
00027       {
00028         newy.push_back(gsl_spline_eval(spline, newx.at(i), gslacc));
00029       }
00030 
00031     gsl_spline_free(spline);
00032     gsl_interp_accel_free(gslacc);
00033   }
00034 
00035 //double MoveoutCorrection::CalcTraveltime(const double rayparameter,
00036 //    const double depth)
00037 //  {
00038 //    Model.SetSourceDepth(depth);
00039 //    double precdist = Model.MatchSlowness(rayparameter, SeismicModel::DirectP);
00040 //    Model.SetRecDist().push_back(precdist);
00041 //    double ptime = Model.CalcArrival(SeismicModel::DirectP, Model.GetRecDist().size()-1);
00042 //    double srecdist = Model.MatchSlowness(rayparameter, SeismicModel::DirectS);
00043 //    Model.SetRecDist().back() = srecdist;
00044 //    double stime = Model.CalcArrival(SeismicModel::DirectS, Model.GetRecDist().size()-1);
00045 //    double distdiff = precdist - srecdist;
00046 //    double angle = PI/2. - asin(rayparameter*Model.GetPVelocity().at(Model.FindLayer(Model.GetSourceDepth())));
00047 //    double extratotaldist = sin(angle) * distdiff;
00048 //    double extravdist = cos(PI/2.0 - angle) * extratotaldist;
00049 //    double extratime = Model.CalcTravelTime(SeismicModel::DirectP, extravdist
00050 //        +depth, depth, rayparameter);
00051 //    timesfile << depth << "  " << stime << " " << ptime << " "<< extratime
00052 //        << endl;
00053 //    return stime + extratime - ptime;
00054 //  }
00055 
00056 double MoveoutCorrection::CalcTraveltime(const double rayparameter,
00057     const double depth)
00058   {
00059     int sourceindex = Model.FindLayer(depth);
00060     double deltat = 0.0;
00061     double currdepth = 0.0;
00062     const double p2 = rayparameter *rayparameter;
00063     for (int i = 0; i < sourceindex; ++i)
00064       {
00065         currdepth += Model.GetThickness().at(i);
00066         double u = 1./Model.GetPVelocity().at(i);
00067         deltat += Model.GetThickness().at(i) * (sqrt(pow(1./Model.GetSVelocity().at(i), 2)
00068               - p2) - sqrt(pow(1./Model.GetPVelocity().at(i), 2) - p2));
00069       }
00070     deltat += (depth - currdepth) * (sqrt(pow(1./Model.GetSVelocity().at(sourceindex), 2) - p2) 
00071           - sqrt(pow(1./Model.GetPVelocity().at(sourceindex), 2) - p2));
00072     return deltat;
00073   }
00074 
00075 void MoveoutCorrection::DoCorrection(SeismicDataComp &Rec, const double slowness)
00076   {
00077     const double maxdepth = 350;
00078     const int nelements = Rec.GetData().size();
00079     const double dt = Rec.GetDt();
00080     std::vector<double> refdeltat, deltat, depths, refdepths, actdepths, times,
00081         newtimes, amps, newamps;
00082     copy(Rec.GetData().begin(), Rec.GetData().end(), back_inserter(amps));
00083     cout << "Ref slow: " << refslowness << " Slow: " << slowness << endl;
00084     ofstream depthfile("depths");
00085     ofstream deltatfile("deltat");
00086     ofstream timesfile("times");
00087     for (double i = 1.0; i < maxdepth; i+=1.0)
00088       {
00089         depths.push_back(i);
00090         times.push_back(i*dt+Rec.GetB());
00091         refdeltat.push_back(CalcTraveltime(refslowness, i));
00092         deltat.push_back(CalcTraveltime(slowness, i));
00093         deltatfile << deltat.at(i) << " " << depths.at(i) << endl;
00094         cout << "Deltat: " << deltat.back() << " Ref Deltat: "
00095             << refdeltat.back() << endl;
00096       }
00097     InterpolateTo(deltat, depths, times, actdepths);
00098     InterpolateTo(depths, refdeltat, actdepths, newtimes);
00099     InterpolateTo(newtimes, amps, times, newamps);
00100 
00101 //    for (int i = 0; i < actdepths.size(); ++i)
00102 //      {
00103 //        depthfile << actdepths.at(i) << " " << amps.at(i) << endl;
00104 //
00105 //        timesfile << times.at(i) << " " << actdepths.at(i) << endl;
00106 //      }
00107     copy(newamps.begin(), newamps.end(), Rec.GetData().begin());
00108   }

Generated on Fri Jul 4 15:30:20 2008 for GPLIB++ by  doxygen 1.5.5