-
Notifications
You must be signed in to change notification settings - Fork 1
/
Calculations.py
50 lines (40 loc) · 1.65 KB
/
Calculations.py
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
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 28 17:31:36 2019
@author: Jacob
"""
import warnings
from geometric_functions_for_DDLS import GeneralDims, OptimizingFunction
import numpy as np
from scipy.optimize import fsolve
from statistics import mode
from statistics import StatisticsError
from modelGrapher import grapher
### SOLVER:
warnings.filterwarnings("ignore")
print("Note: All warnings in the Calculation module are being suppressed.")
amtg = 300 # amount of starting guesses
digits = 6 # desired digits when solving
def Solver(modelname, T, D_tr, D_rot):
zeros=[]
if modelname == 'prolate':
for val in np.linspace(1.000001, 80.9,amtg):
zeros.append(fsolve(OptimizingFunction(modelname, T, D_tr, D_rot), val)[0])
if modelname == 'oblate':
for val in np.linspace(.000001,0.99999,amtg):
zeros.append(fsolve(OptimizingFunction(modelname, T, D_tr, D_rot), val)[0])
if modelname == 'cylinder':
for val in np.linspace(0.01,9.9,amtg):
zeros.append(fsolve(OptimizingFunction(modelname, T, D_tr, D_rot), val)[0])
try:
rho = mode([round(z,digits) for z in zeros])
print("Aspect ratio: " + str(rho))
length, width = GeneralDims(modelname, rho, T, D_tr, D_rot)
print(f"Length: {round(10**9 * length)} nm")
print(f"Width: {round(10**9 * width)} nm")
return length,width
except StatisticsError or RuntimeWarning:
print("No solution.")
def runner(model, T, D_tr, D_rot):
length, width = Solver(model, T, D_tr, D_rot)
grapher(length, width, model, T, D_tr, D_rot)