47 int &n0,
int &n1,
double t,
int start)
51 if(probe[n].first > t && !(std::fabs(probe[n].first - t) <= TOL)){
52 std::cerr <<
"Interval error!" << std::endl;
55 while(n < probe.size() && probe[
n].first < t &&
56 !(std::fabs(probe[n].first - t) <=
TOL))
58 if(n >= probe.size()){
59 std::cerr <<
"Ran off the end of the probe data!" << std::endl;
62 if(std::fabs(probe[n].first - t) <= TOL){
74 double dt = probe[n1].first - probe[n0].first;
75 if(dt < 0 || (std::fabs(dt) <= TOL))
79 double slope = (probe[n1].second - probe[n0].second)/
80 (probe[n1].first - probe[n0].first);
81 return(probe[n0].second + slope*(t - probe[n0].first));
85 main(
int argc,
char *argv[])
89 std::vector<std::string> args;
92 args.push_back(std::string(argv[nn++]));
93 std::string program_name(args[0]);
96 std::cerr <<
"Usage: " << program_name <<
" [-t0 time0] [-t1 time1] "
97 <<
"<probe file 1> <probe file 2>" << std::endl;
104 double t1 = 10000000.0;
107 std::vector<std::string>::iterator ai = args.begin();
108 while(ai != args.end() && !minset){
111 if(ai == args.end()){
112 std::cerr << program_name <<
": Expected argument after -t0 option."
117 std::istringstream Istr(timeopt);
124 std::cerr << program_name <<
": Invalid value for t0 option, "
125 << t0 <<
"." << std::endl;
134 while(ai != args.end() && !maxset){
137 if(ai == args.end()){
138 std::cerr << program_name <<
": Expected argument after -t1 option."
144 std::istringstream Istr(timeopt);
150 std::cerr << program_name <<
": Invalid value for t1 option, "
151 << t1 <<
"." << std::endl;
160 std::cerr << program_name <<
": Invalid time interval, " << t0 <<
" - "
165 while(acount < argc && args[acount][0] ==
'-'){
170 std::cerr <<
"Usage: " << program_name <<
" [-t0 time0] [-t1 time1] "
171 <<
"<probe file 1> <probe file 2>" << std::endl;
174 std::string probe1_file(args[acount++]);
176 std::cerr <<
"Usage: " << program_name <<
" [-t0 time0] [-t1 time1] "
177 <<
"<probe file 1> <probe file 2>" << std::endl;
180 std::string probe2_file(args[acount]);
185 Inf1.open(probe1_file.c_str());
187 std::cerr << program_name <<
": Unable to open probe file, " << probe1_file
191 Inf2.open(probe2_file.c_str());
193 std::cerr << program_name <<
": Unable to open probe file, " << probe2_file
197 std::vector<std::pair<double,double> > probe1;
198 std::vector<std::pair<double,double> > probe2;
201 std::cout << program_name <<
": Reading probe 1 ..." << std::flush;
203 std::pair<double,double> inpair;
204 Inf1 >> inpair.first >> dum >> dum >> dum >> dum >> inpair.second
206 probe1.push_back(inpair);
212 std::cout <<
"... done" << std::endl
213 << program_name <<
": Probe1(" << n <<
"): (" << probe1[0].first
214 <<
", " << probe1[0].second <<
") - (" << probe1[n-1].first
215 <<
", " << probe1[n-1].second <<
")" << std::endl;
217 std::cout << program_name <<
": Reading probe 2 ...";
219 std::pair<double,double> inpair;
220 Inf2 >> inpair.first >> dum >> dum >> dum >> dum >> inpair.second
222 probe2.push_back(inpair);
232 int n1 = probe1.size();
233 int n2 = probe2.size();
234 double probe_tmin = (probe1[0].first < probe2[0].first ?
235 probe2[0].first : probe1[0].first);
236 double probe_tmax = (probe1[n1-1].first > probe2[n2-1].first ?
237 probe2[n2-1].first : probe1[n1-1].first);
238 std::cout <<
"... done" << std::endl
239 << program_name <<
": Probe2(" << n <<
"): (" << probe2[0].first
240 <<
", " << probe2[0].second <<
") - (" << probe2[n-1].first
241 <<
", " << probe2[n-1].second <<
")" << std::endl;
242 if(minset && (probe1[0].first > t0 || probe2[0].first > t0))
243 std::cout << program_name <<
": t0(" << t0 <<
") is less than the "
244 <<
" earliest common probe time: " << probe_tmin
245 <<
", resetting." << std::endl;
248 if(maxset && (probe1[n1-1].first < t1 || probe2[n2-1].first < t1))
249 std::cout << program_name <<
": t1(" << t1 <<
") is greater than the "
250 <<
" latest common probe time: " << probe_tmax <<
", resetting."
254 std::cout << program_name <<
": Comparing probes in time interval (" << t0
255 <<
", " << t1 <<
")" << std::endl;
265 double integral = 0.0;
266 double normal1 = 0.0;
267 double normal2 = 0.0;
269 double infnorm = 0.0;
280 tf = ((probe1[n11].first < probe2[n21].first) &&
281 (probe1[n11].first > ti) ? probe1[n11].first :
289 std::cerr << program_name <<
": Encountered 0 interval. "
290 <<
"Cannot proceed." << std::endl
291 <<
"Here's some debugging information:" << std::endl
292 <<
"Getting probe 1 data. (" << n10 <<
"," << n11
293 <<
"," << tf <<
"," << probe1[n10].first <<
")"
294 << std::flush << std::endl;
296 std::cerr <<
"Got probe 1 data. (" << n10 <<
"," << n11
297 <<
"," << tf <<
"," << probe1[n10].first <<
")"
298 << std::flush << std::endl
299 <<
"Getting probe 2 data. (" << n20 <<
"," << n21
300 <<
"," << tf <<
"," << probe2[n20].first <<
")"
301 << std::flush << std::endl;
303 std::cerr <<
"Got probe 2 data. (" << n20 <<
"," << n21
304 <<
"," << tf <<
"," << probe2[n20].first <<
")"
305 << std::flush << std::endl
306 <<
"probe1(" << n10 <<
"," << n11 <<
")["
307 << probe1[n11].first <<
"]" << std::endl
308 <<
"probe2(" << n20 <<
"," << n21 <<
")["
309 << probe2[n21].first <<
"]" << std::endl;
323 double dp1 = pp10 - pp11;
324 double dp2 = pp20 - pp21;
327 double p12 = pp10 - pp20;
328 double A12 = A1 - A2;
331 double infterm = (p12*dt + A12*dt*dt/2.0);
332 if(std::fabs(infterm) > std::fabs(infnorm))
336 normal1 += (pp10*dt + A1*dt*dt/2.0);
337 normal2 += (pp20*dt + A2*dt*dt/2.0);
340 integral += (p12*p12*dt + p12*A12*dt*dt + A12*A12*dt*dt*dt/3.0);
352 double normal =
std::sqrt(normal1*normal1+normal2*normal2);
354 std::cout.precision(12);
355 std::cout << program_name <<
": Error Integral = "
356 << std::scientific << integral << std::endl
357 << program_name <<
": Probe 1 Area = "
358 << std::scientific << normal1 << std::endl
359 << program_name <<
": Probe 2 Area = "
360 << std::scientific << normal2 << std::endl
361 << program_name <<
": Max Error = "
362 << std::scientific << infnorm << std::endl
363 << program_name <<
": Normalized Errors:" << std::endl
364 << program_name <<
": L2 = "
365 << std::scientific << integral/normal << std::endl
366 << program_name <<
": LINF = "
367 << std::scientific << infnorm/normal << std::endl;
int main(int argc, char *argv[])
double determine_probe_value(std::vector< std::pair< double, double > > &probe, int &n0, int &n1, double t, int start)