GPLIB++
SeismicModelDiff.cpp
Go to the documentation of this file.
1 #include "SeismicModelDiff.h"
2 #include "NumUtil.h"
3 #include <iostream>
4 #include <numeric>
5 using namespace std;
6 
7 namespace gplib
8  {
9  SeismicModelDiff::SeismicModelDiff(const ResPkModel &Seis) :
10  Model(Seis)
11  {
12  }
13 
15  {
16  }
17 
19  GeneralObjective(Old), Model(Old.Model)
20  {
21  }
22 
24  const SeismicModelDiff& source)
25  {
26  if (this == &source)
27  return *this;
29  Model = source.Model;
30  return *this;
31  }
32 
33  //! Calculate the roughness of the model given by the parameter member
35  {
36  const unsigned int length = member.size() / 3; //we have 3 parameters in the model, so size/3 layers
37  double roughness = 0.0; // init returnvalue
38 
39  vector<double> memberdepth, refdepth;
40  partial_sum(member.begin() + length, member.begin() + 2 * length,
41  back_inserter(memberdepth));
42  partial_sum(Model.GetThickness().begin(), Model.GetThickness().end(),
43  back_inserter(refdepth));
44  refdepth.back() += 1000.0; // the last layer is a halfspace
45  vector<double> layerthick(memberdepth); //vector to contain the depths to interfaces in both models, contruct from inversion model
46  copy(refdepth.begin(), refdepth.end(), back_inserter(layerthick)); // and insert reference model interfaces at back
47  sort(layerthick.begin(), layerthick.end()); //then put them in right order
48  adjacent_difference(layerthick.begin(), layerthick.end(),
49  layerthick.begin());
50  layerthick.erase(remove(layerthick.begin(), layerthick.end(), 0.0),
51  layerthick.end()); //remove layers of 0 thickness
52  unsigned int refindex = 0;
53  unsigned int memberindex = 0;
54  unsigned int thickindex = 0;
55  double currthick = 0.0;
56  while (refindex < Model.GetThickness().size() && memberindex < length)
57  {
58  int difference = fcmp(memberdepth.at(memberindex), refdepth.at(
59  refindex), std::numeric_limits<double>::epsilon());
60  currthick = layerthick.at(thickindex);
61  roughness += pow2((member(memberindex + 2 * length)
62  - Model.GetSVelocity().at(refindex)) / Model.GetSVelocity().at(
63  refindex) * currthick);
64  switch (difference)
65  {
66  case 1: // memberdepth bigger
67 
68  ++refindex;
69  break;
70  case -1:
71 
72  ++memberindex;
73  break;
74  case 0:
75 
76  ++refindex;
77  ++memberindex;
78  break;
79  }
80  thickindex++;
81  }
82  SetRMS(roughness);
83  }
84 
86  {
87  return GetRMS();
88  }
89  }
ublas::vector< double > ttranscribed
Definition: gentypes.h:21
virtual void SafeParallel(const ttranscribed &member)
Calculate the roughness of the model given by the parameter member.
GeneralObjective & operator=(const GeneralObjective &source)
SeismicModelDiff calculates the roughness of a joint MT- receiver functions model compared to a seism...
double GetRMS()
Get the current RMS.
const trealdata & GetSVelocity() const
Read-only access to the vector of S-velocities in km/s in each layer.
Definition: SeismicModel.h:81
The basic object for any objective function, mainly an interface class and some storage.
SeismicModelDiff & operator=(const SeismicModelDiff &source)
virtual double PostParallel(const ttranscribed &member)
Some operations cannot be done in parallel, these are done after, returns the misfit value...
void SetRMS(const double x)
This class stores and writes model for the respktn 1D seismic code that we use for receiver function ...
Definition: ResPkModel.h:18
const trealdata & GetThickness() const
Read-only access to the vector of thicknesses in km in each layer.
Definition: SeismicModel.h:101
SeismicModelDiff(const ResPkModel &Seis)