Przeglądaj źródła

./go.sh and all tests for ScattCoef are passing without errors.

Konstantin Ladutenko 10 lat temu
rodzic
commit
634765655f
2 zmienionych plików z 30 dodań i 7 usunięć
  1. 7 7
      go.sh
  2. 23 0
      nmie.cc

+ 7 - 7
go.sh

@@ -3,15 +3,15 @@ echo Compile with gcc -O2
 rm -rf *.bin
 
 clang++ -g -O1 -fsanitize=address  -fno-optimize-sibling-calls -fno-omit-frame-pointer -std=c++11 standalone.cc nmie.cc ucomplex.cc -lm -o scattnlay.bin
-#g++ -O2 -std=c++11 standalone.cc nmie.cc ucomplex.cc -lm -o scattnlay.bin
+g++ -O2 -std=c++11 standalone.cc nmie.cc ucomplex.cc -lm -o scattnlay.bin
 cp scattnlay.bin ../scattnlay
 cd tests/shell
-# for file in `ls *.sh`;  do 
-#     if [ "$file" != "test03.sh" ]; then
-# 	./$file
-# 	echo $file
-#     fi
-# done
+for file in `ls *.sh`;  do 
+    if [ "$file" != "test03.sh" ]; then
+	./$file
+	echo $file
+    fi
+done
 PROGRAM='../../../scattnlay'
 ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer-3.4 $PROGRAM -l 5 0.4642 1.8000 1.7000 0.7114 0.8000 0.7000 0.7393 1.2000 0.0900 0.9168 2.8000 0.2000 1.0000 1.5000 0.4000 -c test01
 

+ 23 - 0
nmie.cc

@@ -49,6 +49,28 @@ complex C_ZERO = {0.0, 0.0};
 complex C_ONE = {1.0, 0.0};
 complex C_I = {0.0, 1.0};
 
+int compare(std::string operation,  complex *a, std::vector< std::complex<double> > b) {
+  for (int i = 0; i < b.size(); ++i) {
+    //if (i > 50) continue;
+    double diff_r = std::abs((a[i].r - b[i].real())/a[i].r);
+    double diff_i = std::abs((a[i].i - b[i].imag())/a[i].i);
+    double epsilon= 1e-16;
+    if (diff_r > epsilon ||diff_i > epsilon) {
+      printf("\n*** WARNING!! Non-zero diff!!! ***\n");
+      printf("Op: %s at i=%i, diff_r=%g, diff_i=%g, a_r=%g, a_i = %g\n",
+    	     operation.c_str(), i, diff_r, diff_i, a[i].r, a[i].i);
+    }
+    double factor = 1.0;
+    if ((diff_r > epsilon * factor && a[i].r/a[0].r > epsilon)
+	|| (diff_i > epsilon*factor && a[i].i/a[0].i > epsilon)) {
+      printf("\n******** ERROR!! Non-zero diff!!! ********\n");
+      printf("Op: %s at i=%i, diff_r=%g, diff_i=%g, a_r=%g, a_i = %g\n",
+	     operation.c_str(), i, diff_r, diff_i, a[i].r, a[i].i);
+    }
+  }
+  return 0;
+}
+
 int firstLayer(int L, int pl) {
   if (pl >= 0) {
     return pl;
@@ -1064,6 +1086,7 @@ int nMieScatt_std(double x[], complex m[], double Theta[], complex S1[], complex
     n_max = ScattCoeff_std(x, m, L, pl, x_std, m_std, n_max, an_std, bn_std);
     if (n_max != tmp_n_max) printf("n_max mismatch\n");
     // TODO: Check an, bn and an_std, bn_std are equal
+    compare("an vs an_std: ", an, an_std);
 
   }
   Pi = (double **) malloc(n_max*sizeof(double *));