GPLIB++
MultiAnisoSurfaceWaveObjective.cpp
Go to the documentation of this file.
2 #include "FatalException.h"
3 #include "convert.h"
4 #include <boost/bind.hpp>
5 #include <numeric>
6 namespace gplib
7  {
9  {
10  }
11 
13  {
14  }
15 
17  const ParkSurfaceWaveData &Measured, const double back,
18  const double avel)
19  {
20  boost::shared_ptr<AnisoSurfaceWaveObjective> CurrObj(
21  new AnisoSurfaceWaveObjective(Measured, back, avel));
22  IndividualObjectives.push_back(CurrObj);
23  backazimuths.push_back(back);
24  }
25 
27  {
28  if (IndividualObjectives.empty())
29  throw FatalException(
30  "In Multi1DRecObjective: No Objective functions set !");
31  const size_t nobjs = IndividualObjectives.size();
32  for (size_t i = 0; i < nobjs; ++i)
33  {
34  IndividualObjectives.at(i)->SetParallelID(GetParallelID()
35  + stringify(i));
36  IndividualObjectives.at(i)->PreParallel(member);
37  }
38  }
39 
41  const ttranscribed &member)
42  {
43  std::vector<double> values;
44  transform(IndividualObjectives.begin(), IndividualObjectives.end(),
45  back_inserter(values), boost::bind(
47  double sumsquares = inner_product(values.begin(), values.end(),
48  values.begin(), 0.0);
49  return sqrt(sumsquares / values.size());
50  }
51 
53  const ttranscribed &member)
54  {
55  for_each(IndividualObjectives.begin(), IndividualObjectives.end(),
56  boost::bind(&AnisoSurfaceWaveObjective::SafeParallel, _1, member));
57  }
58 
61  {
62  const size_t nobjs = Old.IndividualObjectives.size();
63  IndividualObjectives.clear();
64  backazimuths.clear();
65  copy(Old.backazimuths.begin(), Old.backazimuths.end(), back_inserter(
66  backazimuths));
67  for (size_t i = 0; i < nobjs; ++i)
68  {
69  boost::shared_ptr<AnisoSurfaceWaveObjective> Obj(
70  Old.IndividualObjectives.at(i)->clone());
71  IndividualObjectives.push_back(Obj);
72  }
73  }
74 
75  void MultiAnisoSurfaceWaveObjective::WriteData(const std::string &filename)
76  {
77  const size_t nobjs = IndividualObjectives.size();
78  for (size_t i = 0; i < nobjs; ++i)
79  {
80  IndividualObjectives.at(i)->WriteData(filename + stringify(i)); // write one output file for each BAZ
81  }
82  }
83 
84  // MODES : We need one model for each baz
85  void MultiAnisoSurfaceWaveObjective::WriteModel(const std::string &filename)
86  {
87  const size_t nobjs = IndividualObjectives.size();
88  for (size_t i = 0; i < nobjs; ++i)
89  {
90  IndividualObjectives.at(i)->WriteModel(filename + stringify(i)); // write one model file for each BAZ
91  }
92  }
93 
94  // MODES: we plot the inverted parameters
95  void MultiAnisoSurfaceWaveObjective::WritePlot(const std::string &filename)
96  {
97  IndividualObjectives.front()->WritePlot(filename); //all models are the same, so we only write the first
98  }
99 
101  const MultiAnisoSurfaceWaveObjective& source)
102  {
103  if (this == &source)
104  return *this;
105  const size_t nobjs = source.IndividualObjectives.size();
106  IndividualObjectives.clear();
107  backazimuths.clear();
108  copy(source.backazimuths.begin(), source.backazimuths.end(),
109  back_inserter(backazimuths));
110  for (size_t i = 0; i < nobjs; ++i)
111  {
112  boost::shared_ptr<AnisoSurfaceWaveObjective> Obj(
113  source.IndividualObjectives.at(i)->clone());
114  IndividualObjectives.push_back(Obj);
115  }
116  return *this;
117  }
118  }
ublas::vector< double > ttranscribed
Definition: gentypes.h:21
virtual void SafeParallel(const ttranscribed &member)
The core performance calculation, has to be safe to be done in parallel.
virtual void PreParallel(const ttranscribed &member)
Some operations cannot be done in parallel, these are done before.
Minimize the misfit for several surface wave dispersion curves simultaneously.
MultiAnisoSurfaceWaveObjective & operator=(const MultiAnisoSurfaceWaveObjective &source)
virtual double PostParallel(const ttranscribed &member)
Some operations cannot be done in parallel, these are done after, returns the misfit value...
This class calculates the misfit for anisotropic surface wave dispersion data.
const std::string & GetParallelID()
Derived classes need to read the ParallelId for their forward calculations.
void AddMeasurement(const ParkSurfaceWaveData &Measured, const double back, const double avel)
virtual double PostParallel(const ttranscribed &member)
Some operations cannot be done in parallel, these are done after, returns the misfit value...
virtual void SafeParallel(const ttranscribed &member)
The core performance calculation, has to be safe to be done in parallel.
The basic exception class for all errors that arise in gplib.