Browse Source

precision switch

Konstantin Ladutenko 6 years ago
parent
commit
b9176ded5f
3 changed files with 21 additions and 7 deletions
  1. 8 7
      examples/calc-spectra.py
  2. 3 0
      scattnlay/__init__.py
  3. 10 0
      scattnlay/main.py

+ 8 - 7
examples/calc-spectra.py

@@ -26,15 +26,16 @@
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
-#from scattnlay_mp_ import scattnlay_,scattcoeffs_,fieldnlay_
-from scattnlay_ import scattnlay_,scattcoeffs_,fieldnlay_
-# from fieldplot import fieldplot
+import sys
+sys.path.insert(0,'..')  # to be able to import scattnlay from the upper dir
 
-import matplotlib.pyplot as plt
+from scattnlay import scattnlay,scattcoeffs,fieldnlay, switch_to_double_precision, switch_to_multiple_precision
 
+import matplotlib.pyplot as plt
 import numpy as np
 import cmath
 
+#switch_to_multiple_precision()
 from_WL = 400
 to_WL = 800
 WL_points= 100
@@ -45,7 +46,7 @@ x = np.ones((1), dtype = np.float64)
 m = np.ones((1), dtype = np.complex128)
 
 
-core_r = 450000
+core_r = 45000
 
 
 
@@ -59,10 +60,10 @@ bn_vec = []
 for WL in WLs:
     x[0] = 2.0*np.pi*core_r/WL#/4.0*3.0
     m[0] = index_NP
-    terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay_(
+    terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(
         np.array(x), np.array(m))
     print(np.array([Qsca]))
-    terms, an, bn = scattcoeffs_(x, m,24)
+    terms, an, bn = scattcoeffs(x, m,24)
     # Qsca_vec.append(Qsca*np.pi*core_r**2*1e-5)
     Qsca_vec.append(Qsca)#*np.pi*core_r**2*1e-5)
     core_r_vec.append(core_r)

+ 3 - 0
scattnlay/__init__.py

@@ -30,4 +30,7 @@
 #    You should have received a copy of the GNU General Public License
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+from scattnlay.main import switch_to_double_precision
+from scattnlay.main import switch_to_multiple_precision
+switch_to_double_precision()
 from scattnlay.main import scattcoeffs, scattnlay, fieldnlay

+ 10 - 0
scattnlay/main.py

@@ -33,6 +33,16 @@
 from scattnlay_ import scattcoeffs_, scattnlay_,  fieldnlay_
 import numpy as np
 
+def switch_to_double_precision():
+    global scattcoeffs_, scattnlay_,  fieldnlay_
+    from scattnlay_ import scattcoeffs_, scattnlay_,  fieldnlay_
+
+
+def switch_to_multiple_precision():
+    global scattcoeffs_, scattnlay_,  fieldnlay_
+    from scattnlay_mp_ import scattcoeffs_, scattnlay_,  fieldnlay_
+
+
 def scattcoeffs(x, m, nmax=-1, pl=-1):
     """
     scattcoeffs(x, m[, nmax, pl])