13 SeismicModel::SeismicModel(
const int nlayers) :
14 SourceDepth(0.0), dt(0.0), npts(0)
27 copy(source.PVelocity.begin(), source.PVelocity.end(), back_inserter(
29 copy(source.SVelocity.begin(), source.SVelocity.end(), back_inserter(
31 copy(source.Density.begin(), source.Density.end(), back_inserter(
33 copy(source.Thickness.begin(), source.Thickness.end(), back_inserter(
35 copy(source.Qp.begin(), source.Qp.end(), back_inserter(this->Qp));
36 copy(source.Qs.begin(), source.Qs.end(), back_inserter(this->Qs));
37 SourceDepth = source.SourceDepth;
46 const int nelements = source.PVelocity.size();
49 PVelocity.assign(nelements, 0);
50 SVelocity.assign(nelements, 0);
51 Density.assign(nelements, 0);
52 Thickness.assign(nelements, 0);
53 Qp.assign(nelements, 0);
54 Qs.assign(nelements, 0);
56 copy(source.PVelocity.begin(), source.PVelocity.end(),
58 copy(source.SVelocity.begin(), source.SVelocity.end(),
60 copy(source.Density.begin(), source.Density.end(), Density.begin());
61 copy(source.Thickness.begin(), source.Thickness.end(),
63 copy(source.Qp.begin(), source.Qp.end(), Qp.begin());
64 copy(source.Qs.begin(), source.Qs.end(), Qs.begin());
65 SourceDepth = source.SourceDepth;
75 PVelocity.assign(nlayers, 0);
76 SVelocity.assign(nlayers, 0);
77 Density.assign(nlayers, 0);
78 Thickness.assign(nlayers, 0);
79 Qp.assign(nlayers, 0);
80 Qs.assign(nlayers, 0);
83 bool SeismicModel::FuzzComp(
const double elem1,
const double elem2,
84 const double tolerance)
86 return (std::abs(elem1 - elem2) < tolerance);
93 double currentbottom = 0;
98 while (depth > currentbottom && i < Thickness.size())
100 currentbottom += Thickness.at(i);
105 return min(i, Thickness.size() - 1);
112 double currdepth = 0;
114 const int sourcelayer =
FindLayer(SourceDepth) - 1;
117 velocity = &SVelocity;
119 velocity = &PVelocity;
120 for (
int i = 0; i < sourcelayer; ++i)
122 x += Thickness.at(i) * tan(asin(slowness * velocity->at(i)));
123 currdepth += Thickness.at(i);
125 x += (SourceDepth - currdepth) * tan(asin(slowness * velocity->at(
131 const double sdepth,
const double rdepth,
const double p)
136 double currdepth = accumulate(Thickness.begin(), Thickness.begin()
140 velocity = &SVelocity;
142 velocity = &PVelocity;
143 double t = p * hdistance;
144 double eta = sqrt(1 / pow(velocity->at(recindex), 2) - p * p);
145 t += (currdepth - rdepth) * eta;
146 for (
int i = recindex; i < sourceindex; ++i)
148 currdepth += Thickness.at(i);
149 eta = sqrt(1 / pow(velocity->at(i), 2) - p * p);
150 t += eta * Thickness.at(i);
152 eta = sqrt(1 / pow(velocity->at(sourceindex), 2) - p * p);
153 t += (sdepth - currdepth) * eta;
158 const double recdist)
160 const double tolerance = 0.001;
161 double angle = PI / 4.;
165 double currdepth = 0;
169 velocity = &SVelocity;
171 velocity = &PVelocity;
172 while (!FuzzComp(recdist, distance, tolerance))
175 p = sin(angle) / velocity->at(0);
177 if (distance > recdist)
178 angle -= PI * pow(0.5, preclevel);
180 angle += PI * pow(0.5, preclevel);
188 bool haveErrors =
false;
189 if (!SVelErrors.empty() && !ThickErrors.empty())
191 ofstream outfile(filename.c_str());
193 const unsigned int size = Thickness.size();
194 for (
unsigned int i = 0; i <
size; ++i)
196 outfile << cumthick <<
" " << SVelocity.at(i);
198 outfile <<
" " << ThickErrors.at(i) <<
" " << SVelErrors.at(i);
200 cumthick += Thickness.at(i);
201 outfile << cumthick <<
" " << SVelocity.at(i);
203 outfile <<
" " << ThickErrors.at(i) <<
" " << SVelErrors.at(i);
210 ofstream outfile((filename +
".plot").c_str());
212 const unsigned int size = Thickness.size();
213 for (
unsigned int i = 0; i <
size; ++i)
215 outfile << cumthick <<
" " << SVelocity.at(i) <<
" "
216 << PVelocity.at(i) <<
" " << Density.at(i) << endl;
217 cumthick += Thickness.at(i);
218 outfile << cumthick <<
" " << SVelocity.at(i) <<
" "
219 << PVelocity.at(i) <<
" " << Density.at(i) << endl;
221 outfile << cumthick * 2.0 <<
" " << SVelocity.at(size - 1) <<
" "
222 << PVelocity.at(size - 1) <<
" " << Density.at(size - 1) << endl;
double CalcArrival(const tArrivalType mode, const double recdist)
void WritePlot(const std::string &filename)
Write out an ascii file for plotting with xmgrace etc.
int FindLayer(const double depth)
Returns the index of the layer that correponds to depth in km.
tArrivalType
Do we want to calculate the arrival of a direct S-Wave or a P-wave.
The class SeismicModel is the base class for some of the model format for seismic codes...
SeismicModel & operator=(const SeismicModel &source)
void Init(const int nlayers)
Init provides a convenient way to allocate memory in all structures for a given number of layers...
SeismicModel(const int nlayers=0)
void PlotVelWithErrors(const std::string &filename)
Write out an ascii file with error bars for plotting with xmgrace etc.
double CalcTravelTime(const tArrivalType mode, const double sdepth, const double rdepth, const double p)
double MatchSlowness(const double slowness, const tArrivalType mode)
Given a slowness in s/km and a wave type calculate the distance that matches this slowness...