7 #include "OscLib/func/EarthModel.h" 8 #include "Utilities/func/MathUtil.h" 24 std::cerr << __FILE__ <<
":" << __LINE__
25 <<
" Model '" << which <<
"' is not supported." 26 <<
" Currently only PREM is supported." <<
std::endl;
74 if (r>1221.5&&r<=3480.0)
return 12.5815+x*(-1.2638+x*(-3.6426+x*(-5.5281)));
75 if (r>3480.0&&r<=5701.0)
return 7.9565+x*(-6.4761+x*(5.5283+x*(-3.0807)));
76 if (r<=1221.5)
return 13.0885-8.8381*x*
x;
77 if (r>5771.0&&r<=5971.0)
return 11.2494-8.0298*
x;
78 if (r>5971.0&&r<=6151.0)
return 7.1089-3.8045*
x;
79 if (r>6151.0&&r<=6291.0)
return 2.6910+0.6924*
x;
80 if (r>5701.0&&r<=5771.0)
return 5.3197-1.4836*
x;
81 if (r>6291.0&&r<=6346.6)
return 2.6910+0.6924*
x;
82 if (r>6346.6&&r<=6356.0)
return 2.90;
83 if (r>6356.0&&r<=6368.0)
return 2.60;
84 if (r>6368.0&&r<=6371.0)
return 1.020;
107 static double crustD[2] = { 0.0,
109 static double upperMantleD[6] = { 15.0,
115 static double middleMantleD[6] = {350.0,
121 static double lowerMantleD[14] = {650.0,
135 static double outerCoreD[14] = { 2878.0,
149 static double innerCoreD[8] ={ 5121.0,
157 static double crustRho[2] = { 2.840,
159 static double upperMantleRho[6] = { 3.313,
165 static double middleMantleRho[6] = {3.700,
171 static double lowerMantleRho[14] = {4.200,
185 static double outerCoreRho[14] = { 9.927,
199 static double innerCoreRho[7] = { 12.229,
212 if (d>=crustD[0] && d<crustD[1]) {
213 for (i=0; i<1; ++
i) {
214 if (d>=crustD[i] && d<crustD[i+1]) {
219 if (d>=upperMantleD[0] && d<upperMantleD[5]) {
220 for (i=0; i<5; ++
i) {
221 if (d>=upperMantleD[i] && d<upperMantleD[i+1]) {
222 return upperMantleRho[
i];
226 if (d>=middleMantleD[0] && d<middleMantleD[5]) {
227 for (i=0; i<5; ++
i) {
228 if (d>=middleMantleD[i] && d<middleMantleD[i+1]) {
229 return middleMantleRho[
i];
233 if (d>=lowerMantleD[0] && d<lowerMantleD[13]) {
234 for (i=0; i<13; ++
i) {
235 if (d>=lowerMantleD[i] && d<lowerMantleD[i+1]) {
236 return lowerMantleRho[
i];
240 if (d>=outerCoreD[0] && d<outerCoreD[13]) {
241 for (i=0; i<13; ++
i) {
242 if (d>=outerCoreD[i] && d<outerCoreD[i+1]) {
243 return outerCoreRho[
i];
247 if (d>=innerCoreD[0] && d<innerCoreD[7]) {
248 for (i=0; i<7; ++
i) {
249 if (d>=innerCoreD[i] && d<innerCoreD[i+1]) {
250 return innerCoreRho[
i];
270 for (
int i=0;
i<nsample; ++
i) {
271 r = r1 + (r2-r1)*((
float)
i+0.5)/(float)nsample;
274 return sum/(float)nsample;
280 unsigned int nsample = 20;
286 double r1 = rRegionLo;
287 double r2 = rRegionHi;
291 double ave = this->
AveNe(r1, r2, nsample);
293 for (
unsigned int j=0; j<nsample; ++j) {
294 r = r1+(r2-r1)*((
float)j+0.5)/(float)nsample;
296 if (fabs(ne-ave)/ne>tol) { isok =
false;
break; }
316 if (r2<=r1) r2 = r1+0.5;
325 std::vector<double>& rhi,
326 std::vector<double>& ne)
328 rlo.resize(
fRlo.size());
329 rhi.resize(
fRlo.size());
331 for (
unsigned int i=0;
i<
fRlo.size(); ++
i) {
342 std::list<double>& Ls,
343 std::list<double>& Ns)
346 static const double crustNe = 2.6*0.5;
359 Lnu = rdet*(sqrt(
util::sqr(rnu/rdet)+cosQ*cosQ-1.0)-cosQ);
363 x1 = x2+sqrt(1.0-cosQ*cosQ)*Lnu;
386 &xouta, &youta, &xoutb, &youtb);
387 L = util::pythag(x1-xoutb, y1-youtb);
391 L = util::pythag(x2-xoutb, y2-youtb);
393 Ns.push_back(crustNe);
402 for (i=0; i<
fRhi.size()-1; ++
i) {
404 &xouta, &youta, &xoutb, &youtb);
407 &xina, &yina, &xinb, &yinb);
416 L = util::pythag(xouta-xoutb, youta-youtb);
419 Ns.push_back(
fNe[i]);
421 else if (n1==2 && n2==2) {
426 L = util::pythag(xouta-xina, youta-yina);
428 Ns.push_front(
fNe[i]);
430 L = util::pythag(xoutb-xinb, youtb-yinb);
432 Ns.push_back(
fNe[i]);
441 &xouta, &youta, &xoutb, &youtb);
443 &xina, &yina, &xinb, &yinb);
453 L = util::pythag(xouta-x2, youta-y2);
456 L = util::pythag(xouta-xoutb, youta-youtb);
459 Ns.push_back(
fNe[i]);
461 else if (n1==2 && n2==2) {
466 L = util::pythag(xouta-xina, youta-yina);
468 Ns.push_front(
fNe[i]);
474 L = util::pythag(x2-xinb, y2-yinb);
477 L = util::pythag(xoutb-xinb, youtb-yinb);
480 Ns.push_back(
fNe[i]);
485 L = util::pythag(xouta-x1, youta-y1);
494 L = util::pythag(xoutb-x2, youtb-y2);
496 Ns.push_back(crustNe);
507 for (; itr!=itrEnd; ++itr) {
510 std::cout << ltot <<
" " << Lnu <<
std::endl;
511 if (fabs(ltot-Lnu)>1e-6) abort();
518 double x2,
double y2,
520 double* xa,
double* ya,
521 double* xb,
double* yb)
525 double drsqr = dx*dx + dy*dy;
526 double D = x1*y2 - x2*y1;
527 double arg = r*r*drsqr - D*
D;
528 if (arg<0.0)
return 0;
531 if (dy<0.0) sgndy = -1.0;
533 *xa = ( D*dy - sgndy * dx * sqrt(arg) ) / drsqr;
534 *ya = (-D*dx - fabs(dy) * sqrt(arg) ) / drsqr;
535 *xb = ( D*dy + sgndy * dx * sqrt(arg) ) / drsqr;
536 *yb = (-D*dx + fabs(dy) * sqrt(arg) ) / drsqr;
538 if (arg==0.0)
return 1;
EarthModel(const char *which, double tol)
std::vector< double > fNe
std::vector< double > fRregion
void resize(Vector< T > &vec1, Index n1, const V &val)
void MakeLayers(double tol)
double DensityStacey(double r)
void GetLayers(std::vector< double > &rlo, std::vector< double > &rhi, std::vector< double > &ne)
int IntersectLineAndCircle(double x1, double y1, double x2, double y2, double r, double *xa, double *ya, double *xb, double *yb)
void LineProfile(double prodL, double cosQ, double rdet, std::list< double > &Ls, std::list< double > &Ns)
double AveNe(double r1, double r2, int nsample)
double DensityPREM(double r)
std::vector< double > fRlo
std::vector< double > fRhi
QTextStream & endl(QTextStream &s)