forked from christophersanborn/Radiative3D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsources.cpp
170 lines (147 loc) · 5.1 KB
/
sources.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// sources.cpp
//
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib> /* rand(), srand(), RAND_MAX, exit() */
#include "sources.hpp"
#include "phonons.hpp"
using namespace std;
// ************************************************
// *** CLASS IMPLEMENTATION: Sources::PhononSource
// ************************************************
//
//////
// Static Members:
//
int PhononSource::nTOA = 0;
S2::S2Set * PhononSource::pTOA = NULL;
//////
// Static Methods:
//
//////
// Constructors:
//
//////
// CONSTRUCTOR: PhononSource(int, int)
//
// Sets up the two Probability Distribution (ProbDist object)
// vectors: mPDists and mWholeProbs. The two parameters define the
// number of input conditions, and the number of output conditions.
// These determine the size of the vectors and the length of the
// WholeProbs arrays.
//
// The mPDists vector will have nraytypes_out number of elements,
// and each contianed ProbDist object will have length nTOA.
//
// The mWholeProbs vector will have nraytypes_in number of elements,
// and each contained ProbDist object will have length
// nraytypes_out.
//
// Note that this BASE CLASS constructor constructs and allocates
// (resizes) the ProbDist vectors, but does NOT populate them with
// actual probability values. That is the task of derived classes,
// which will be specialized to the particular type of source
// (e.g. event-source, scattering, etc.) being modeled.
//
// NOTE: It is assumed that the static member nTOA has been properly
// set prior to construction of the first PhononSource object. If
// not... there will be problems.
//
PhononSource::PhononSource(int nraytypes_in, int nraytypes_out) :
mPDists (nraytypes_out, ProbDist(nTOA) ),
mWholeProbs (nraytypes_in, ProbDist(nraytypes_out) )
{}
//////
// METHOD: PhononSource :: output_differential_probabilities()
//
// Used for diagnostic purposes
//
void PhononSource::output_differential_probabilities(raytype inray,
raytype outray,
const char* symbol,
Real scalefactor) {
ProbDist & Dist = mPDists[outray];
Real rel_prob = mWholeProbs[inray]
.GetDiffProb(outray); // Relative scaling
S2::S2Set & takeoffs = (*pTOA); // Alias for takeoff-angle array
for (int ctr = 0; ctr < nTOA; ctr++) {
Real prob = rel_prob * Dist.GetDiffProb(ctr);
cout << setw(16) << takeoffs[ctr].Lon()
<< setw(16) << takeoffs[ctr].Lat()
<< setw(16) << sqrt(prob * nTOA) * scalefactor
<< " " << symbol << endl; // Symbol holds a GMT flag marker code.
}
}
void PhononSource::output_random_rayset(int nrays, raytype inray) {
S2::S2Set & takeoffs = (*pTOA); // An alias for the takeoff angle array
vector< vector<int> > counts;
counts.clear();
counts.resize(3);
vector<int> & P_count = counts[RAY_P];
vector<int> & SH_count = counts[RAY_SH];
vector<int> & SV_count = counts[RAY_SV];
P_count.clear();
SH_count.clear();
SV_count.clear();
P_count.resize(nTOA,0);
SH_count.resize(nTOA,0);
SV_count.resize(nTOA,0);
// Cast rays
for (int ctr = 0; ctr < nrays; ctr++) {
raytype rt = (raytype) mWholeProbs[inray].GetRandomIndex();
Index toa_index = mPDists[rt].GetRandomIndex();
counts[rt][toa_index]++;
}
// Output Rays:
// P_waves:
for (int ctr = 0; ctr < nTOA; ctr++) {
int num = P_count[ctr];
const char * symbol = "c";
if (num != 0) {
Real val = (Real) num / nrays;
cout << setw(16) << takeoffs[ctr].Lon()
<< setw(16) << takeoffs[ctr].Lat()
<< setw(16) << sqrt(val * 3.0 * nTOA) * 0.2
<< " " << symbol << endl; // Symbol holds a GMT flag marker code.
}
}
// SH_waves:
for (int ctr = 0; ctr < nTOA; ctr++) {
int num = SH_count[ctr];
const char * symbol = "-";
if (num != 0) {
Real val = (Real) num / nrays;
cout << setw(16) << takeoffs[ctr].Lon()
<< setw(16) << takeoffs[ctr].Lat()
<< setw(16) << sqrt(val * 3.0 * nTOA) * 0.2
<< " " << symbol << endl; // Symbol holds a GMT flag marker code.
}
}
// SV_waves:
for (int ctr = 0; ctr < nTOA; ctr++) {
int num = SV_count[ctr];
const char * symbol = "y";
if (num != 0) {
Real val = (Real) num / nrays;
cout << setw(16) << takeoffs[ctr].Lon()
<< setw(16) << takeoffs[ctr].Lat()
<< setw(16) << sqrt(val * 3.0 * nTOA) * 0.2
<< " " << symbol << endl; // Symbol holds a GMT flag marker code.
}
}
}
//////
// METHOD: PhononSource::GenerateRandomPhonon()
//
Phonon PhononSource::GenerateRandomPhonon(raytype inray) {
// Determine output raytype:
raytype rt = (raytype) mWholeProbs[inray].GetRandomIndex();
// Get a Take-off Angle (TOA) index:
Index toa_index = mPDists[rt].GetRandomIndex();
// Resolve TOA index to a ThetaPhi direction:
S2::ThetaPhi dir = (*pTOA)[toa_index];
// Return a Phonon constructed from direction and raytype:
return Phonon(dir, rt);
}