compareSimulationResults.pl, debug printout improvements
This commit is contained in:
parent
72531c955d
commit
104d65bebe
|
|
@ -177,41 +177,39 @@ sub compareResults {
|
||||||
use strict;
|
use strict;
|
||||||
my($refFile,$simFile,$clip,$nDigits,$relTol)=@_;
|
my($refFile,$simFile,$clip,$nDigits,$relTol)=@_;
|
||||||
my(@Ref,@Sim,$i,$j,$relErr,$maxRelErr,$absErr,$maxAbsErr);
|
my(@Ref,@Sim,$i,$j,$relErr,$maxRelErr,$absErr,$maxAbsErr);
|
||||||
my(@RefRes,@SimRes,$matchType,$mag,$lo,$hi);
|
my(@RefRes,@SimRes,@ColNames,$matchType,$mag,$lo,$hi);
|
||||||
|
|
||||||
return("ERROR: cannot open file $refFile") if (!open(IF,"$refFile"));
|
return("ERROR: cannot open file $refFile") if (!open(IF,"$refFile"));
|
||||||
while (<IF>) {
|
while (<IF>) {chomp;push(@Ref,$_)}
|
||||||
s/\s+$//;
|
|
||||||
push(@Ref,$_);
|
|
||||||
}
|
|
||||||
close(IF);
|
close(IF);
|
||||||
return("ERROR: cannot open file $simFile") if (!open(IF,"$simFile"));
|
return("ERROR: cannot open file $simFile") if (!open(IF,"$simFile"));
|
||||||
while (<IF>) {
|
while (<IF>) {chomp;push(@Sim,$_)}
|
||||||
s/\s+$//;
|
|
||||||
push(@Sim,$_);
|
|
||||||
}
|
|
||||||
close(IF);
|
close(IF);
|
||||||
|
if ($main::verbose && $#Ref != $#Sim) {print STDERR "Reference points: $#Ref\nSimulated points: $#Sim"}
|
||||||
return("FAIL (probably from some simulation failure)") if ($#Ref != $#Sim || $#Sim<1);
|
return("FAIL (probably from some simulation failure)") if ($#Ref != $#Sim || $#Sim<1);
|
||||||
|
if ($main::verbose && $Ref[0] ne $Sim[0]) {print STDERR "Reference quantities: $Ref[0]\nSimulated quantities: $Sim[0]"}
|
||||||
return("FAIL (simulation output quantities differ)") if ($Ref[0] ne $Sim[0]);
|
return("FAIL (simulation output quantities differ)") if ($Ref[0] ne $Sim[0]);
|
||||||
$maxAbsErr=0;$maxRelErr=0;$matchType=0;
|
$maxAbsErr=0;$maxRelErr=0;$matchType=0;
|
||||||
|
@ColNames=split(/\s+/,$Ref[0]);
|
||||||
for ($j=1;$j<=$#Ref;++$j) {
|
for ($j=1;$j<=$#Ref;++$j) {
|
||||||
@RefRes=split(/\s+/,$Ref[$j]);
|
@RefRes=split(/\s+/,$Ref[$j]);
|
||||||
@SimRes=split(/\s+/,$Sim[$j]);
|
@SimRes=split(/\s+/,$Sim[$j]);
|
||||||
return("FAIL (number of quantities simulated are different") if ($#RefRes != $#SimRes);
|
if ($main::verbose && $#RefRes != $#SimRes) {print STDERR "Line $j: Ref data: $#RefRes\tSim data: $#SimRes"}
|
||||||
|
return("FAIL (number of quantities simulated are different)") if ($#RefRes != $#SimRes);
|
||||||
for ($i=1;$i<=$#RefRes;++$i) { # ignore first column, this is the sweep variable
|
for ($i=1;$i<=$#RefRes;++$i) { # ignore first column, this is the sweep variable
|
||||||
if ($RefRes[$i] !~ /^$main::number$/ || $SimRes[$i] !~ /^$main::number$/) {
|
if ($RefRes[$i] !~ /^$main::number$/ || $SimRes[$i] !~ /^$main::number$/) {
|
||||||
return("FAIL (non-numeric results");
|
return("FAIL (non-numeric results");
|
||||||
}
|
}
|
||||||
next if ($RefRes[$i] == $SimRes[$i]);
|
next if ($RefRes[$i] == $SimRes[$i]);
|
||||||
$matchType=1 if ($matchType<1);
|
$matchType=1 if ($matchType<1);
|
||||||
#next if (abs($RefRes[$i]) < $clip && abs($SimRes[$i]) < $clip);
|
next if (abs($RefRes[$i]) < $clip && abs($SimRes[$i]) < $clip);
|
||||||
next if (abs($RefRes[$i]) < $clip || abs($SimRes[$i]) < $clip);
|
#next if (abs($RefRes[$i]) < $clip || abs($SimRes[$i]) < $clip);
|
||||||
if ($RefRes[$i]*$SimRes[$i] <= 0.0) {
|
if ($RefRes[$i]*$SimRes[$i] <= 0.0) {
|
||||||
$matchType=2 if ($matchType<2);
|
$matchType=2 if ($matchType<2);
|
||||||
$absErr=abs($RefRes[$i]-$SimRes[$i]);
|
$absErr=abs($RefRes[$i]-$SimRes[$i]);
|
||||||
$relErr=$absErr/(0.5*(abs($RefRes[$i])+abs($SimRes[$i])+$absErr));
|
$relErr=$absErr/(0.5*(abs($RefRes[$i])+abs($SimRes[$i])+$absErr));
|
||||||
$maxRelErr=$relErr if ($relErr > $maxRelErr);
|
$maxRelErr=$relErr if ($relErr > $maxRelErr);
|
||||||
if ($main::verbose) {print STDERR $RefRes[$i],$SimRes[$i],100*$relErr."\%"}
|
if ($main::verbose) {print STDERR $ColNames[$i],$RefRes[$i],$SimRes[$i],100*$relErr."\%"}
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
$lo=abs($RefRes[$i]);
|
$lo=abs($RefRes[$i]);
|
||||||
|
|
@ -229,7 +227,7 @@ sub compareResults {
|
||||||
$absErr=abs($RefRes[$i]-$SimRes[$i]);
|
$absErr=abs($RefRes[$i]-$SimRes[$i]);
|
||||||
$relErr=$absErr/(0.5*(abs($RefRes[$i])+abs($SimRes[$i])+$absErr));
|
$relErr=$absErr/(0.5*(abs($RefRes[$i])+abs($SimRes[$i])+$absErr));
|
||||||
next if ($relErr<$relTol);
|
next if ($relErr<$relTol);
|
||||||
if ($main::verbose) {print STDERR $RefRes[$i],$SimRes[$i],100*$relErr."\%"}
|
if ($main::verbose) {print STDERR $ColNames[$i],$RefRes[$i],$SimRes[$i],100*$relErr."\%"}
|
||||||
$matchType=2 if ($matchType<2);
|
$matchType=2 if ($matchType<2);
|
||||||
$maxRelErr=$relErr if ($relErr > $maxRelErr);
|
$maxRelErr=$relErr if ($relErr > $maxRelErr);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue