GPLIB++
cadianiso.cpp
Go to the documentation of this file.
1 #include "cadijoint.h"
2 #include <iostream>
3 #include "Aniso1DMTObjective.h"
4 #include "MTStation.h"
5 #include "gentypes.h"
6 #include "CLevanisoConf.h"
7 #include "MTFitSetup.h"
8 #include <boost/bind.hpp>
9 #include "PTensor1DMTObjective.h"
10 #include <boost/shared_ptr.hpp>
11 #include "PTensorMTStation.h"
12 
13 using namespace std;
14 using namespace gplib;
15 
16 boost::shared_ptr<PlottableObjective> MTObjective;
17 CLevanisoConf Configuration;
18 
19 void misfit(float *p, float *misfit, int *m)
20  {
21  const int nlayers = abs(*m) / 4;
22  const int nparam = nlayers * 4;
23  ttranscribed mtmember(nparam);
24  for (int i = 0; i < nparam; ++i)
25  {
26  mtmember(i) = p[i];
27  }
28  *misfit = 0.0;
29  if (Configuration.weights.at(0) > 0)
30  {
31  //cout << "Calculating MT misfit" << endl;
32  *misfit += Configuration.weights.at(0) * MTObjective->CalcPerformance(
33  mtmember);
34  }
35  }
36 
37 void init(int* nd, float* ranges)
38  {
40  PTensorMTStation PTData;
41  Configuration.GetData("levaniso.conf");
42  try
43  {
44  MTData.GetData(Configuration.mtinputdata);
45  } catch (FatalException &e)
46  {
47  cerr << e.what() << endl;
48  }
49 
50  if (Configuration.mtfit == "ptensor")
51  {
52 
53  PTData.GetData(Configuration.ptensordata);
54  boost::shared_ptr<PTensor1DMTObjective> PTObjective(
55  new PTensor1DMTObjective(PTData));
56  MTObjective = PTObjective;
57  }
58  else
59  {
60 
61  MTData.GetData(Configuration.mtinputdata);
62  boost::shared_ptr<Aniso1DMTObjective> AnisoObjective(
63  new Aniso1DMTObjective(MTData));
64  SetupMTFitParameters(Configuration, *AnisoObjective);
65  MTObjective = AnisoObjective;
66  }
67 
68  const int nlayers = Configuration.minres.size();
69  const int nparams = nlayers * 4;
70  *nd = nparams;
71  ttranscribed mtmember(nparams);
72  copy(Configuration.startres.begin(), Configuration.startres.end(),
73  mtmember.begin());
74  copy(Configuration.startthick.begin(), Configuration.startthick.end(),
75  mtmember.begin() + nlayers);
76  copy(Configuration.startaniso.begin(), Configuration.startaniso.end(),
77  mtmember.begin() + 2 * nlayers);
78  copy(Configuration.startstrike.begin(), Configuration.startstrike.end(),
79  mtmember.begin() + 3 * nlayers);
80  MTObjective->CalcPerformance(mtmember);
81 
82  for (int i = 0; i < nlayers; ++i)
83  {
84  ranges[2 * i] = Configuration.minres.at(i);
85  ranges[2 * i + 1] = Configuration.maxres.at(i);
86  }
87  for (int i = 0; i < nlayers; ++i)
88  {
89  ranges[2 * i + 2 * nlayers] = Configuration.minthick.at(i);
90  ranges[2 * i + 2 * nlayers + 1] = Configuration.maxthick.at(i);
91  }
92  for (int i = 0; i < nlayers; ++i)
93  {
94  ranges[2 * i + 4 * nlayers] = Configuration.minaniso.at(i);
95  ranges[2 * i + 4 * nlayers + 1] = Configuration.maxaniso.at(i);
96  }
97  for (int i = 0; i < nlayers; ++i)
98  {
99  ranges[2 * i + 6 * nlayers] = Configuration.minstrike.at(i);
100  ranges[2 * i + 6 * nlayers + 1] = Configuration.maxstrike.at(i);
101  }
102  cout << "Init finished ! " << endl;
103  ;
104  }
void SetupMTFitParameters(const tConfObject &Configuration, C1DMTObjective &Objective)
Definition: MTFitSetup.h:8
ublas::vector< double > ttranscribed
Definition: gentypes.h:21
This is a special objective function to fit phase tensor MT data.
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: cadianiso.cpp:19
virtual void GetData(const std::string filename)
read in data from file, determines format by ending
Definition: MTStation.cpp:597
boost::shared_ptr< PlottableObjective > MTObjective
Definition: cadianiso.cpp:16
void init(int *nd, float *ranges)
Definition: cadianiso.cpp:37
The class MTStation is used to store the transfer functions and related information for a MT-site...
Definition: MTStation.h:17
CMTStation MTData
Definition: cadijoint.cpp:15
void GetData(const std::string &filename)
CLevanisoConf Configuration
Definition: cadianiso.cpp:17
The basic exception class for all errors that arise in gplib.