GPLIB++
CollapseModel.cpp
Go to the documentation of this file.
1 #include "CollapseModel.h"
2 #include "FatalException.h"
3 #include "NumUtil.h"
4 
5 namespace gplib
6  {
7  void CollapseModel(ttranscribed &Thickness, ttranscribed &ParmValue)
8  {
9  std::vector<double> CollThick, CollValue;
10  const unsigned int size = Thickness.size();
11  if (size != ParmValue.size())
12  throw FatalException(
13  "Cannot collapse model with differing number of depths and parameter values !");
14  unsigned int index = 0; //we need the loop index afterwards
15  for (/* index initialized above*/; index < size - 1; ++index)
16  {
17  //if layer parameters are identical and combined layer thickness is less than 100km
18  //the seismic code seems to have problems when the thickness of a single layer exceeds
19  //this value
20  if ((fcmp(ParmValue(index), ParmValue(index + 1),
21  std::numeric_limits<double>::epsilon()) == 0) && ((Thickness(index) + Thickness(index
22  + 1)) < 100.0))
23  {
24  CollValue.push_back(ParmValue(index));
25  CollThick.push_back(Thickness(index) + Thickness(index + 1));
26  ++index; //skip the next layer
27  }
28  else //if layers are different
29  {
30  CollThick.push_back(Thickness(index));
31  CollValue.push_back(ParmValue(index));
32  }
33  }
34  if (index == size - 1) // if we didn't collapse the last layer
35  {
36  CollThick.push_back(Thickness(index));
37  CollValue.push_back(ParmValue(index));
38  }
39  Thickness.resize(CollThick.size());
40  ParmValue.resize(CollValue.size());
41  copy(CollThick.begin(), CollThick.end(), Thickness.begin());
42  copy(CollValue.begin(), CollValue.end(), ParmValue.begin());
43  }
44  }
ublas::vector< double > ttranscribed
Definition: gentypes.h:21
const int size
Definition: perftest.cpp:14
void CollapseModel(ttranscribed &Thickness, ttranscribed &ParmValue)
Remove layers with identical parameters from the model and collapse them into a single layer each...
The basic exception class for all errors that arise in gplib.