GPLIB++
cadijoint.cpp
Go to the documentation of this file.
1 #include "cadijoint.h"
2 #include <iostream>
3 #include "C1DMTObjective.h"
4 #include "CMTStation.h"
5 #include "gentypes.h"
6 #include "C1DRecObjective.h"
7 #include "SeismicDataComp.h"
8 #include "CLevmarConf.h"
9 #include "MTFitSetup.h"
10 #include <boost/bind.hpp>
11 
12 using namespace std;
13 using namespace gplib;
14 
15 CMTStation MTData, Best;
17 CLevmarConf Configuration;
20  Configuration.sigma, Configuration.wlevel, Configuration.slowness);
21 
22 void misfit(float *p, float *misfit, int *m)
23  {
24  const int nlayers = abs(*m) / 3;
25  const int nparam = nlayers * 2;
26  ttranscribed mtmember(nparam), recmember(nparam);
27  for (int i = 0; i < nparam; ++i)
28  {
29  mtmember(i) = p[i];
30  }
31  for (int i = 0; i < nparam; ++i)
32  recmember(i) = p[i + nlayers];
33  *misfit = 0.0;
34  if (Configuration.weights.at(0) > 0)
35  {
36  //cout << "Calculating MT misfit" << endl;
37  *misfit += Configuration.weights.at(0) * MTObjective.CalcPerformance(
38  mtmember);
39  }
40  if (Configuration.weights.at(1) > 0)
41  {
42  //cout << "Calculating Rec misfit" << endl;
43  *misfit += RecObjective.CalcPerformance(recmember)
44  * Configuration.weights.at(1);
45  }
46  }
47 
48 void init(int* nd, float* ranges)
49  {
50 
51  string version = "$Id: levjoint.cpp 1131 2007-05-15 22:25:06Z max $";
52  cout << endl << endl;
53  cout << "Program " << version << endl;
54  cout << " Levenberg Marquardt to jointly invert seismic and MT data "
55  << endl;
56  cout << " look at levmar.conf for configuration and setup " << endl;
57  cout << " output files will be of the form " << endl;
58  cout << " best_lev + ending " << endl;
59 
60  Configuration.GetData("levmar.conf");
61  try
62  {
63  MTData.GetData(Configuration.mtinputdata);
64  RecData.GetData(Configuration.recinputdata, SeismicDataComp::sac);
65  } catch (FatalException &e)
66  {
67  cerr << e.what() << endl;
68  }
69 
71 
73  Configuration.omega, Configuration.sigma, Configuration.wlevel,
74  Configuration.slowness);
78 
79  const int nlayers = Configuration.minres.size();
80  const int nparams = nlayers * 3;
81  *nd = nparams;
82  ttranscribed mtmember(nlayers * 2), recmember(nlayers * 2);
83  copy(Configuration.startres.begin(), Configuration.startres.end(),
84  mtmember.begin());
85  copy(Configuration.startthick.begin(), Configuration.startthick.end(),
86  mtmember.begin() + nlayers);
87  copy(Configuration.startthick.begin(), Configuration.startthick.end(),
88  recmember.begin());
89  copy(Configuration.startsvel.begin(), Configuration.startsvel.end(),
90  recmember.begin() + nlayers);
91  MTObjective.CalcPerformance(mtmember);
92  RecObjective.CalcPerformance(recmember);
93 
94  for (int i = 0; i < nlayers; ++i)
95  {
96  ranges[2 * i] = Configuration.minres.at(i);
97  ranges[2 * i + 1] = Configuration.maxres.at(i);
98  }
99  for (int i = 0; i < nlayers; ++i)
100  {
101  ranges[2 * i + 2 * nlayers] = Configuration.minthick.at(i);
102  ranges[2 * i + 2 * nlayers + 1] = Configuration.maxthick.at(i);
103  }
104  for (int i = 0; i < nlayers; ++i)
105  {
106  ranges[2 * i + 4 * nlayers] = Configuration.minsvel.at(i);
107  ranges[2 * i + 4 * nlayers + 1] = Configuration.maxsvel.at(i);
108  }
109  cout << "Init finished ! " << endl;
110  ;
111  }
void SetupMTFitParameters(const tConfObject &Configuration, C1DMTObjective &Objective)
Definition: MTFitSetup.h:8
ublas::vector< double > ttranscribed
Definition: gentypes.h:21
std::vector< double > & GetData()
Access for data vector, for ease of use and efficiency we return a reference.
double CalcPerformance(const ttranscribed &member)
For serial execution CalcPerformance calls the three Parallel functions for more convenient use...
void init(int *nd, float *ranges)
Definition: cadijoint.cpp:48
void SetErrorLevel(const double level)
Set the errorlevel for fit, this is relative to the maximum amplitude, not for each individual data p...
C1DRecObjective RecObjective(RecData, Configuration.shift, Configuration.omega, Configuration.sigma, Configuration.wlevel, Configuration.slowness)
void misfit(float *p, float *misfit, int *m)
These two functions provide the interface between the C++ implementation and the C interfacea of CADI...
Definition: cadijoint.cpp:22
C1DMTObjective MTObjective(MTData)
CMTStation MTData
Definition: cadijoint.cpp:15
CLevmarConf Configuration
Definition: cadijoint.cpp:17
void SetPoisson(const double ratio)
Set poisson's ratio, at the moment the same for all layers, used for calculating P-velocity.
string version
Definition: makeinput.cpp:16
Calculate the misfit between observed receiver function for a given 1D model by calculating a synthet...
void SetTimeWindow(const double start, const double end)
Set the time window used for misfit calculations, start and end are in seconds.
CMTStation Best
Definition: cadijoint.cpp:15
C1DMTObjective is the base class for MT misfit calculations from 1D models, it provides common functi...
SeismicDataComp RecData
Definition: cadijoint.cpp:16
The basic exception class for all errors that arise in gplib.