GPLIB++
MoveoutCorrection.cpp
Go to the documentation of this file.
1 #include "MoveoutCorrection.h"
2 #include <vector>
3 #include <iostream>
4 #include <fstream>
5 #include <gsl/gsl_errno.h>
6 #include <gsl/gsl_spline.h>
7 
8 using namespace std;
9 
10 namespace gplib
11  {
12  MoveoutCorrection::MoveoutCorrection(const double refslow,
13  const ResPkModel &TheModel) :
14  refslowness(refslow), Model(TheModel)
15  {
16  }
17 
18  void MoveoutCorrection::InterpolateTo(trealdata &oldx, trealdata &y,
19  trealdata &newx, trealdata &newy)
20  {
21  gsl_interp_accel *gslacc = gsl_interp_accel_alloc();
22  gsl_spline *spline = gsl_spline_alloc(gsl_interp_linear, oldx.size());
23  cout << "Oldx: " << oldx.size() << endl;
24  cout << "Newx: " << newx.size() << endl;
25  gsl_spline_init(spline, &oldx[0], &y[0], newx.size());
26  newy.clear();
27  for (int i = 0; i < newx.size(); ++i)
28  {
29  newy.push_back(gsl_spline_eval(spline, newx.at(i), gslacc));
30  }
31 
32  gsl_spline_free(spline);
33  gsl_interp_accel_free(gslacc);
34  }
35 
36  //double MoveoutCorrection::CalcTraveltime(const double rayparameter,
37  // const double depth)
38  // {
39  // Model.SetSourceDepth(depth);
40  // double precdist = Model.MatchSlowness(rayparameter, SeismicModel::DirectP);
41  // Model.SetRecDist().push_back(precdist);
42  // double ptime = Model.CalcArrival(SeismicModel::DirectP, Model.GetRecDist().size()-1);
43  // double srecdist = Model.MatchSlowness(rayparameter, SeismicModel::DirectS);
44  // Model.SetRecDist().back() = srecdist;
45  // double stime = Model.CalcArrival(SeismicModel::DirectS, Model.GetRecDist().size()-1);
46  // double distdiff = precdist - srecdist;
47  // double angle = PI/2. - asin(rayparameter*Model.GetPVelocity().at(Model.FindLayer(Model.GetSourceDepth())));
48  // double extratotaldist = sin(angle) * distdiff;
49  // double extravdist = cos(PI/2.0 - angle) * extratotaldist;
50  // double extratime = Model.CalcTravelTime(SeismicModel::DirectP, extravdist
51  // +depth, depth, rayparameter);
52  // timesfile << depth << " " << stime << " " << ptime << " "<< extratime
53  // << endl;
54  // return stime + extratime - ptime;
55  // }
56 
57  double MoveoutCorrection::CalcTraveltime(const double rayparameter,
58  const double depth)
59  {
60  int sourceindex = Model.FindLayer(depth);
61  double deltat = 0.0;
62  double currdepth = 0.0;
63  const double p2 = rayparameter * rayparameter;
64  for (int i = 0; i < sourceindex; ++i)
65  {
66  currdepth += Model.GetThickness().at(i);
67  double u = 1. / Model.GetPVelocity().at(i);
68  deltat += Model.GetThickness().at(i) * (sqrt(pow(1.
69  / Model.GetSVelocity().at(i), 2) - p2) - sqrt(pow(1.
70  / Model.GetPVelocity().at(i), 2) - p2));
71  }
72  deltat += (depth - currdepth) * (sqrt(pow(1. / Model.GetSVelocity().at(
73  sourceindex), 2) - p2) - sqrt(pow(1. / Model.GetPVelocity().at(
74  sourceindex), 2) - p2));
75  return deltat;
76  }
77 
79  const double slowness)
80  {
81  const double maxdepth = 350;
82  const int nelements = Rec.GetData().size();
83  const double dt = Rec.GetDt();
84  std::vector<double> refdeltat, deltat, depths, refdepths, actdepths,
85  times, newtimes, amps, newamps;
86  copy(Rec.GetData().begin(), Rec.GetData().end(), back_inserter(amps));
87  cout << "Ref slow: " << refslowness << " Slow: " << slowness << endl;
88  ofstream depthfile("depths");
89  ofstream deltatfile("deltat");
90  ofstream timesfile("times");
91  for (double i = 1.0; i < maxdepth; i += 1.0)
92  {
93  depths.push_back(i);
94  times.push_back(i * dt + Rec.GetB());
95  refdeltat.push_back(CalcTraveltime(refslowness, i));
96  deltat.push_back(CalcTraveltime(slowness, i));
97  deltatfile << deltat.at(i) << " " << depths.at(i) << endl;
98  cout << "Deltat: " << deltat.back() << " Ref Deltat: "
99  << refdeltat.back() << endl;
100  }
101  InterpolateTo(deltat, depths, times, actdepths);
102  InterpolateTo(depths, refdeltat, actdepths, newtimes);
103  InterpolateTo(newtimes, amps, times, newamps);
104 
105  // for (int i = 0; i < actdepths.size(); ++i)
106  // {
107  // depthfile << actdepths.at(i) << " " << amps.at(i) << endl;
108  //
109  // timesfile << times.at(i) << " " << actdepths.at(i) << endl;
110  // }
111  copy(newamps.begin(), newamps.end(), Rec.GetData().begin());
112  }
113  }
std::vector< double > & GetData()
Access for data vector, for ease of use and efficiency we return a reference.
int FindLayer(const double depth)
Returns the index of the layer that correponds to depth in km.
double GetB() const
void DoCorrection(SeismicDataComp &Rec, const double slowness)
const trealdata & GetSVelocity() const
Read-only access to the vector of S-velocities in km/s in each layer.
Definition: SeismicModel.h:81
double GetDt() const
Return dt in s.
This class stores and writes model for the respktn 1D seismic code that we use for receiver function ...
Definition: ResPkModel.h:18
const trealdata & GetPVelocity() const
Read-only access to the vector of P-velocities in km/s in each layer.
Definition: SeismicModel.h:71
const trealdata & GetThickness() const
Read-only access to the vector of thicknesses in km in each layer.
Definition: SeismicModel.h:101