GPLIB++
SurfaceWaveObjective.cpp
Go to the documentation of this file.
1 #include "SurfaceWaveObjective.h"
2 #include <boost/bind.hpp>
3 #include "SeisTools.h"
4 #include <numeric>
5 #include <boost/shared_ptr.hpp>
6 #include "Sdisp96Model.h"
7 
8 using namespace std;
9 
10 namespace gplib
11  {
12  SurfaceWaveObjective::SurfaceWaveObjective(const SurfaceWaveData &Data) :
13  MeasuredData(Data)
14  {
15  poisson = sqrt(3.);
16  errorlevel = 0.02;
17  }
18 
20  const SurfaceWaveObjective& source)
21  {
22  if (this == &source)
23  return *this;
25  MeasuredData = source.MeasuredData;
26  SynthData = source.SynthData;
27  Synthetic = source.Synthetic;
28  errorlevel = source.errorlevel;
29  poisson = source.poisson;
30  return *this;
31  }
32 
34  PlottableObjective(Old), MeasuredData(Old.MeasuredData), SynthData(
35  Old.SynthData), Synthetic(Old.Synthetic)
36  {
37  errorlevel = Old.errorlevel;
38  poisson = Old.poisson;
39  }
40 
42  {
43  }
44 
46  {
47  const unsigned int nfulllayers = member.size() / 2;
48  Sdisp96Model Model;
49  ttranscribed thickness(nfulllayers), velocity(nfulllayers);
50  copy(member.begin(), member.begin() + nfulllayers, thickness.begin()); //copy values
51  copy(member.begin() + nfulllayers, member.begin() + 2 * nfulllayers,
52  velocity.begin());
53  //The model object has been newly created above, so it is safe to use back_inserter to fill the vectors
54  copy(thickness.begin(), thickness.end(), back_inserter(
55  Model.SetThicknesses()));
56  //Sh velocities and Sv velocities are the same
57  copy(velocity.begin(), velocity.end(), back_inserter(
58  Model.SetShVelocities()));
59  copy(velocity.begin(), velocity.end(), back_inserter(
60  Model.SetSvVelocities()));
61  //We calculate density from S-Velocity
62  transform(velocity.begin(), velocity.end(), back_inserter(
63  Model.SetDensities()), CalcDensity());
64  //PVelocity is calculated by multiplication of SVel by poisson's ratio
65  transform(velocity.begin(), velocity.end(), back_inserter(
66  Model.SetPhVelocities()), boost::bind(multiplies<double> (), _1,
67  poisson));
68  copy(Model.GetPhVelocities().begin(), Model.GetPhVelocities().end(),
69  back_inserter(Model.SetPvVelocities()));
70  //We give some fixed values to the attenuation parameters
71  fill_n(back_inserter(Model.SetEta()), nfulllayers, 1.0);
72  fill_n(back_inserter(Model.SetQmu()), nfulllayers, 100.0);
73  fill_n(back_inserter(Model.SetQkappa()), nfulllayers, 99999.00);
74 
75  Synthetic.SetModel(Model);
76  if (Synthetic.GetCalculationPeriods().empty())
77  {
78  Synthetic.SetCalculationPeriods(MeasuredData.GetPeriods());
79  }
80  Synthetic.PreParallel(GetParallelID());
81  }
82 
84  {
85  return GetRMS();
86 
87  }
88 
90  {
91  //We can safely calculate the synthetic data in parallel
92  SynthData = Synthetic.SafeParallel(GetParallelID());
93  assert(errorlevel > 1e-4);
94  // an errorlevel < 0.01% is absolutely unrealistic
95  const unsigned int ndata = min(SynthData.GetPhaseVelocities().size(),
96  MeasuredData.GetPhaseVelocities().size());
97  SetMisfit().resize(ndata); // we need vectors of the right size for misfit
98  SetSynthData().resize(ndata); // and data
99  double returnvalue = 0; // init returnvalue
100  // this loop calculates the misfit for each datum
101  for (unsigned int i = 0; i < ndata; ++i)
102  {
103  returnvalue += CalcMisfit(MeasuredData.GetPhaseVelocities().at(i),
104  SynthData.GetPhaseVelocities().at(i), 0.0, errorlevel, i);
105 
106  }
107 
108  SetRMS(std::pow(returnvalue / ndata, 1.0 / GetFitExponent())); //return misfit
109  }
110  }
const trealdata & GetPeriods() const
Read-only access to the vector of periods for the phase velocities.
ublas::vector< double > ttranscribed
Definition: gentypes.h:21
void PreParallel(const std::string &filename)
For a parallel execution, these are things that have to be done before any parallel block...
const trealdata & GetPhVelocities() const
SurfaceWaveData SafeParallel(const std::string &filename)
Operations that are safe to perform in parallel.
Calculate density from a given S-velocity, the formula is taken from Owen et al. JGR 89...
Definition: SeisTools.h:15
This class can write files specific for the synthetic surface wave codes that are part of the compute...
Definition: Sdisp96Model.h:12
This only adds a few plotting functions to GeneralObjective to define a common interface.
This class calculates the misfit between observed surface wave dispersion data and the data calculate...
const trealdata & GetPhaseVelocities() const
Read-only access to the vector of phase velocities.
void SetCalculationPeriods(const trealdata &c)
Set the vector of periods in s for which we want to calculate phase velocities.
virtual double PostParallel(const ttranscribed &member)
Some operations cannot be done in parallel, these are done after, returns the misfit value...
A class to read, write and store fundamental mode surface wave dispersion data.
int GetFitExponent()
Get the Fit exponent.
trealdata & SetShVelocities()
double CalcMisfit(const double measured, const double predicted, const double measerror, const double errorlevel, const int index)
SurfaceWaveObjective & operator=(const SurfaceWaveObjective &source)
trealdata & SetSvVelocities()
const std::string & GetParallelID()
Derived classes need to read the ParallelId for their forward calculations.
double GetRMS()
Get the current RMS.
virtual void SafeParallel(const ttranscribed &member)
The core performance calculation, has to be safe to be done in parallel.
void SetModel(const Sdisp96Model &m)
Set the model for which we want to calculate the data.
const trealdata & GetCalculationPeriods() const
Get the vector of periods in s for which we want to calculate phase velocities.
tdata & SetSynthData()
Only derived classes can write access the Synthetic data.
SurfaceWaveObjective(const SurfaceWaveObjective &Old)
tmisfit & SetMisfit()
Only derived classes can write access the Misfit.
trealdata & SetThicknesses()
trealdata & SetPvVelocities()
PlottableObjective & operator=(const PlottableObjective &source)
virtual void PreParallel(const ttranscribed &member)
Some operations cannot be done in parallel, these are done before.
void SetRMS(const double x)
trealdata & SetPhVelocities()