8 #include <boost/bind.hpp>
9 #include <boost/numeric/conversion/cast.hpp>
15 SurfaceWaveModel::SurfaceWaveModel() :
16 refperiod(50), anisotropic(1), name(
"surf"), carddeckmodel(1),
17 ninnercore(0), noutercore(0)
26 pvvelocities(Old.pvvelocities), phvelocities(Old.phvelocities),
27 svvelocities(Old.svvelocities), shvelocities(Old.shvelocities),
28 densities(Old.densities), thicknesses(Old.thicknesses), eta(Old.eta),
29 qmu(Old.qmu), qkappa(Old.qkappa), refperiod(Old.refperiod),
30 anisotropic(Old.anisotropic), name(Old.name), carddeckmodel(
31 Old.carddeckmodel), ninnercore(Old.ninnercore), noutercore(
52 copy(source.pvvelocities.begin(), source.pvvelocities.end(),
53 back_inserter(pvvelocities));
54 copy(source.phvelocities.begin(), source.phvelocities.end(),
55 back_inserter(phvelocities));
56 copy(source.svvelocities.begin(), source.svvelocities.end(),
57 back_inserter(svvelocities));
58 copy(source.shvelocities.begin(), source.shvelocities.end(),
59 back_inserter(shvelocities));
60 copy(source.densities.begin(), source.densities.end(), back_inserter(
62 copy(source.thicknesses.begin(), source.thicknesses.end(),
63 back_inserter(thicknesses));
64 copy(source.eta.begin(), source.eta.end(), back_inserter(eta));
65 copy(source.qmu.begin(), source.qmu.end(), back_inserter(qmu));
66 copy(source.qkappa.begin(), source.qkappa.end(), back_inserter(qkappa));
68 refperiod = source.refperiod;
69 anisotropic = source.anisotropic;
71 carddeckmodel = source.carddeckmodel;
72 ninnercore = source.ninnercore;
73 noutercore = source.noutercore;
79 assert(pvvelocities.size() == phvelocities.size());
80 assert(pvvelocities.size() == svvelocities.size());
81 assert(pvvelocities.size() == shvelocities.size());
82 assert(pvvelocities.size() == densities.size());
83 assert(pvvelocities.size() == thicknesses.size());
84 assert(pvvelocities.size() == eta.size());
85 assert(pvvelocities.size() == qmu.size());
86 assert(pvvelocities.size() == qkappa.size());
105 const unsigned int ninsert = 1;
106 assert(index-1 < thicknesses.size());
109 thicknesses.insert(thicknesses.begin() + index, ninsert, 0.0);
110 pvvelocities.insert(pvvelocities.begin() + index, ninsert,
111 pvvelocities.at(index));
112 phvelocities.insert(phvelocities.begin() + index, ninsert,
113 phvelocities.at(index));
114 svvelocities.insert(svvelocities.begin() + index, ninsert,
115 svvelocities.at(index));
116 shvelocities.insert(shvelocities.begin() + index, ninsert,
117 shvelocities.at(index));
118 densities.insert(densities.begin() + index, ninsert,
119 densities.at(index));
120 eta.insert(eta.begin() + index, ninsert, eta.at(index));
121 qmu.insert(qmu.begin() + index, ninsert, qmu.at(index));
122 qkappa.insert(qkappa.begin() + index, ninsert, qkappa.at(index));
127 assert(maxthick > 0.0);
128 assert(index < thicknesses.size());
129 double currthick = thicknesses.at(index);
130 unsigned int ninsert = boost::numeric_cast<
unsigned int>(floor(
131 currthick / maxthick));
134 double diffthick = currthick - ninsert * maxthick;
138 thicknesses.at(index) = diffthick;
144 thicknesses.at(index) = maxthick;
146 thicknesses.insert(thicknesses.begin() + index, ninsert, maxthick);
147 pvvelocities.insert(pvvelocities.begin() + index, ninsert,
148 pvvelocities.at(index));
149 phvelocities.insert(phvelocities.begin() + index, ninsert,
150 phvelocities.at(index));
151 svvelocities.insert(svvelocities.begin() + index, ninsert,
152 svvelocities.at(index));
153 shvelocities.insert(shvelocities.begin() + index, ninsert,
154 shvelocities.at(index));
155 densities.insert(densities.begin() + index, ninsert, densities.at(
157 eta.insert(eta.begin() + index, ninsert, eta.at(index));
158 qmu.insert(qmu.begin() + index, ninsert, qmu.at(index));
159 qkappa.insert(qkappa.begin() + index, ninsert, qkappa.at(index));
162 if (index + ninsert + 1 < thicknesses.size())
165 return index + ninsert + 1;
167 return index + ninsert;
174 trealdata thisdepth(thicknesses.size(), 0.0), backgrounddepth(
175 Background.thicknesses.size());
176 partial_sum(thicknesses.begin(), thicknesses.end(), thisdepth.begin());
177 partial_sum(Background.thicknesses.begin(),
178 Background.thicknesses.end(), backgrounddepth.begin());
180 const unsigned int layerindex = distance(backgrounddepth.begin(),
181 upper_bound(backgrounddepth.begin(), backgrounddepth.end(),
184 assert(layerindex < Background.thicknesses.size());
185 trealdata localthick(Background.thicknesses.begin() + layerindex,
186 Background.thicknesses.end());
187 localthick.front() = backgrounddepth.at(layerindex) - thisdepth.back();
190 copy(localthick.begin(), localthick.end(), back_inserter(thicknesses));
191 copy(Background.pvvelocities.begin() + layerindex,
192 Background.pvvelocities.end(), back_inserter(pvvelocities));
193 copy(Background.phvelocities.begin() + layerindex,
194 Background.phvelocities.end(), back_inserter(phvelocities));
195 copy(Background.svvelocities.begin() + layerindex,
196 Background.svvelocities.end(), back_inserter(svvelocities));
197 copy(Background.shvelocities.begin() + layerindex,
198 Background.shvelocities.end(), back_inserter(shvelocities));
199 copy(Background.densities.begin() + layerindex,
200 Background.densities.end(), back_inserter(densities));
201 copy(Background.eta.begin() + layerindex, Background.eta.end(),
203 copy(Background.qmu.begin() + layerindex, Background.qmu.end(),
205 copy(Background.qkappa.begin() + layerindex, Background.qkappa.end(),
206 back_inserter(qkappa));
207 ninnercore = Background.ninnercore;
208 noutercore = Background.noutercore;
211 void SurfaceWaveModel::WriteLayer(std::ostream &stream,
212 const unsigned int index,
const trealdata &depth)
const
214 stream << setw(10) << setprecision(6) << (6371 - depth.at(index))
216 stream << setw(10) << setprecision(6) << densities.at(index) * 1000
217 <<
" " << pvvelocities.at(index) * 1000 <<
" ";
218 stream << svvelocities.at(index) * 1000 <<
" " << qkappa.at(index)
219 <<
" " << qmu.at(index) <<
" ";
220 stream << phvelocities.at(index) * 1000 <<
" "
221 << shvelocities.at(index) * 1000 <<
" " << eta.at(index) <<
" ";
222 stream << depth.at(index);
229 ofstream outfile(filename.c_str());
231 const unsigned int size = thicknesses.size();
232 for (
unsigned int i = 0; i <
size; ++i)
234 outfile << cumthick <<
" " << svvelocities.at(i) << endl;
235 cumthick += thicknesses.at(i);
236 outfile << cumthick <<
" " << svvelocities.at(i) << endl;
238 outfile << cumthick * 2.0 <<
" " << svvelocities.at(size - 1) << endl;
void AddDiscontinuity(const int index)
Insert a layer with 0 thickness to create a discontinuity for the forward code.
double GetMaxDepth(const double depth)
void WritePlot(const std::string &filename) const
Write out an ascii file for plotting with xmgrace or similar programs.
A class to store 1D model for calculation of synthetic surface wave data.
virtual ~SurfaceWaveModel()
SurfaceWaveModel & operator=(const SurfaceWaveModel &source)
void MergeModel(const SurfaceWaveModel &Background)
Merge this model with another background model, the depth range below this model will be filled with ...
int SplitLayer(const int index, const double maxthick)
Splits a layer into several layers with a maximum thickness of maxthick, but otherwise identical prop...
void CheckConsistency() const