def test_input(self): filename = "input.txt" f = open(filename, "r") inParams = InputParameters.get_input(f) f.close() assert inParams == (500.0, 3.0, 3.0, 45, 45), "Something wrong in the InputParameters.py"
def test_user_input(self): filename = "input.txt" f = open(filename, "r") inParams = InputParameters.get_input(f) f.close() validinput = InputConstraints.input_constraints(inParams, calledfunc) self.assertTrue(validinput, "Input parameters are not valid.")
def test_invalid_angle(self): filename = "testcase_invalidangle.txt" f = open(filename, "r") for x in range(6): f.readline() inParams = InputParameters.get_input(f) validinput = InputConstraints.input_constraints( inParams, calledfunc) self.assertFalse(validinput, "Angle is out of bound. It should be false.") f.close()
def test_output(self): (F_1, X_1, X_2, theta_1, theta_2) = (500, 3, 3, 45, 45) (F_Ax, F_Ay, F_By) = InputParameters.derived_values(F_1, X_1, X_2) F_AC = Calculations.func_F_AC(F_Ay, theta_1) F_AD = Calculations.func_F_AD(F_AC, theta_1) F_BC = Calculations.func_F_BC(F_By, theta_2) F_BD = Calculations.func_F_BD(F_BC, theta_2) F_CD = Calculations.func_F_CD(F_1) assert relerr(F_AC, -353.553) < 0.01 assert relerr(F_AD, 250) < 0.01 assert relerr(F_BC, -353.553) < 0.01 assert relerr(F_BD, 250) < 0.01 assert relerr(F_CD, 500) < 0.01
## \file Control.py # \author Thulasi Jegatheesan # \brief Controls the flow of the program import sys import InputParameters import OutputFormat filename = sys.argv[1] A_C, C_W, h_C, T_init, t_final, L, T_C, t_step, rho_W, D, A_tol, R_tol, T_W, E_W = InputParameters.get_input( filename) InputParameters.input_constraints(A_C, C_W, h_C, T_init, t_final, L, T_C, t_step, rho_W, D, T_W, E_W) OutputFormat.write_output(T_W, E_W)
## \file Control.py # \author Samuel J. Crawford, Brooks MacLachlan, and W. Spencer Smith # \brief Controls the flow of the program import sys import Calculations import InputParameters import OutputFormat filename = sys.argv[1] g_vect = 9.8 epsilon = 2.0e-2 inParams = InputParameters.InputParameters(filename) t_flight = Calculations.func_t_flight(inParams, g_vect) p_land = Calculations.func_p_land(inParams, g_vect) d_offset = Calculations.func_d_offset(inParams, p_land) s = Calculations.func_s(inParams, epsilon, d_offset) OutputFormat.write_output(s, d_offset)
import Calculations import InputConstraints import InputParameters import OutputFormat # start timer start = time.time() # start coverage cov = coverage.Coverage() cov.start() filename = sys.argv[1] f = open(filename, "r") # read input (F_1, X_1, X_2, theta_1, theta_2) = InputParameters.get_input(f) f.close() inParams = (F_1, X_1, X_2, theta_1, theta_2) calledfunc = "Control" # do the calculationsif inputs are valid if (InputConstraints.input_constraints(inParams, calledfunc)): (F_Ax, F_Ay, F_By) = InputParameters.derived_values(F_1, X_1, X_2) F_AC = Calculations.func_F_AC(F_Ay, theta_1) F_AD = Calculations.func_F_AD(F_AC, theta_1) F_BC = Calculations.func_F_BC(F_By, theta_2) F_BD = Calculations.func_F_BD(F_BC, theta_2) F_CD = Calculations.func_F_CD(F_1) OutputFormat.write_output(F_AC, F_AD, F_BC, F_BD, F_CD) cov.stop()
# B = Rfunc_series(parameters = A.parameters, g = A.g, gtot = A.gtot, T = A.T, # maxParameter = A.maxParameter, prefac = A.prefac, # V = A.V, scaledVolt = A.scaledVolt, # distance = A.input_parameters["x"][0], Vq = A.Vq) # B.setParameter(nterms = 200, maxA = 8, maxK = 10) # B.genAnswer() # plt.figure() # plt.plot(B.rrfunction) # plt.show() #=============================================================================== # #=============================================================================== Vpoints = mp.linspace(0, mpf('2.')/mpf(10**4), 201) dist1 = np.array([mpf('1.7') / mpf(10**(6)), mpf('1.7')/ mpf(10**(6))]) dist2 = np.array([mpf('1.5') / mpf(10**(6)), mpf('1.7') / mpf(10**(6))]) genData = { "v":[mpf(i) * mpf(10**j) for (i,j) in [(3,4),(3,4)]], "c":[1,1], "g":[1/mpf(8), 1/mpf(8)], "x":[dist1, -dist2]} A = BP.base_parameters(genData, V = Vpoints, Q = 1/mpf(4), T = 0) B = Rfunc_series(parameters = A.parameters, g = A.g, gtot = A.gtot, T = A.T, maxParameter = A.maxParameter, prefac = A.prefac, V = A.V, scaledVolt = A.scaledVolt, distance = A.input_parameters["x"][0], Vq = A.Vq) B.genAnswer() plt.figure() plt.plot(B.rrfunction) plt.show()
X = np.float64(freal(A.V)) Y = np.float64(freal(A.distance)) Z = np.float64(A.rrfunction) #return X, Y, Z X, Y = np.meshgrid(X,Y) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot_wireframe(X, Y, np.transpose(Z)) ax.set_xlabel('Voltage') ax.set_ylabel('Distance') ax.set_zlabel('R function') plt.show() if __name__ == '__main__': VOLTRANGE = fmfy(np.linspace(0,50,2)) * BP.GLOBAL_VOLT basedist = mpf(1.0)/mpf(10**6) distance = np.linspace(.5, 1.0, 3) * basedist distance2 = np.ones_like(distance) * basedist example1 = { "v":[mpf(i) * mpf(10**j) for (i,j) in [(2,3),(2,3)]], "c":[1,1], "g":[1/mpf(8),1/mpf(8)], "x":[distance, -distance]} A = BP.base_parameters(example1, V =VOLTRANGE) B = Rfunc_constructor(A, 'fortran') B.setParameter(nterms = 800, maxA = 8, maxK = 10) B.genAnswer() single, interference = Current(B) # plt.figure() # plt.plot(B.rrfunction) # plt.show()
if method == 'series': constr = Rseries elif method == 'cnct': constr = Rcnct return constr(parameters=A.parameters, g=A.g, gtot=A.gtot, T=A.T, maxParameter=A.maxParameter, prefac=A.prefac, V=A.V, scaledVolt=A.scaledVolt, distance=A.input_parameters["x"][0]) a = BP.base_parameters(example1, V=VOLTRANGE) A = Rfunc_constructor(a, method='cnct') b = BP.base_parameters(example2, V=GLOBAL_VOLT) B = Rfunc_constructor(b, method='cnct') A.genAnswer() #cProfile.runctx('A.genAnswer()', globals(), locals() ) B.genAnswer() def plot_surface(A): if not hasattr(A, 'rrfunction'): A.genAnswer() X = np.float64(freal(A.V)) Y = np.float64(freal(A.distance)) Z = np.float64(A.rrfunction)
"x":[distance2, -distance2, distance2, -distance2]} def Rfunc_constructor(A, method = 'series'): if method == 'series': constr = Rseries elif method =='cnct': constr = Rcnct return constr(parameters = A.parameters, g = A.g, gtot = A.gtot, T = A.T, maxParameter = A.maxParameter, prefac = A.prefac, V = A.V, scaledVolt = A.scaledVolt, distance = A.input_parameters["x"][0]) a = BP.base_parameters(example1, V = VOLTRANGE ) A = Rfunc_constructor(a, method = 'cnct') b = BP.base_parameters(example2, V= GLOBAL_VOLT) B = Rfunc_constructor(b, method = 'cnct') A.genAnswer() #cProfile.runctx('A.genAnswer()', globals(), locals() ) B.genAnswer() def plot_surface(A): if not hasattr(A, 'rrfunction'): A.genAnswer() X = np.float64(freal(A.V)) Y = np.float64(freal(A.distance)) Z = np.float64(A.rrfunction) #return X, Y, Z X, Y = np.meshgrid(X,Y)
## \file Control.py # \author Thulasi Jegatheesan # \brief Controls the flow of the program import sys import Calculations import InputParameters import OutputFormat filename = sys.argv[1] A_C, C_W, h_C, T_init, t_final, L, T_C, t_step, rho_W, D, A_tol, R_tol, E_W = InputParameters.get_input( filename) V_tank = InputParameters.derived_values(D, L) InputParameters.input_constraints(A_C, C_W, h_C, T_init, t_final, L, T_C, t_step, rho_W, D, E_W) V_W = Calculations.func_V_W(V_tank) m_W = Calculations.func_m_W(rho_W, V_W) tau_W = Calculations.func_tau_W(C_W, h_C, A_C, m_W) T_W = Calculations.func_T_W(T_C, t_final, T_init, A_tol, R_tol, t_step, tau_W) OutputFormat.write_output(E_W, T_W)
#return X, Y, Z X, Y = np.meshgrid(X, Y) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot_wireframe(X, Y, np.transpose(Z)) ax.set_xlabel('Voltage') ax.set_ylabel('Distance') ax.set_zlabel('R function') plt.show() if __name__ == '__main__': VOLTRANGE = fmfy(np.linspace(0, 50, 2)) * BP.GLOBAL_VOLT basedist = mpf(1.0) / mpf(10**6) distance = np.linspace(.5, 1.0, 3) * basedist distance2 = np.ones_like(distance) * basedist example1 = { "v": [mpf(i) * mpf(10**j) for (i, j) in [(2, 3), (2, 3)]], "c": [1, 1], "g": [1 / mpf(8), 1 / mpf(8)], "x": [distance, -distance] } A = BP.base_parameters(example1, V=VOLTRANGE) B = Rfunc_constructor(A, 'fortran') B.setParameter(nterms=800, maxA=8, maxK=10) B.genAnswer() single, interference = Current(B) # plt.figure() # plt.plot(B.rrfunction) # plt.show()
## \file Control.py # \author Naveen Ganesh Muralidharan # \brief Controls the flow of the program import sys import Calculations import InputParameters import OutputFormat filename = sys.argv[1] r_t, K_d, K_p, t_step, t_sim = InputParameters.get_input(filename) InputParameters.input_constraints(r_t, K_d, K_p, t_step, t_sim) y_t = Calculations.func_y_t(K_d, K_p, r_t, t_sim, t_step) OutputFormat.write_output(y_t)
# "x":[distance2, -distance]} # A = BP.base_parameters(example1, V =VOLTRANGE, Q= 1/mpf(4), T = 5/ mpf(10**3)) # B = Rfunc_fortran(parameters = A.parameters, g = A.g, gtot = A.gtot, T = A.T, # maxParameter = A.maxParameter, prefac = A.prefac, # V = A.V, scaledVolt = A.scaledVolt, # distance = A.input_parameters["x"][0], Vq = A.Vq) # B.setParameter(nterms = 1500, maxA = 15, maxK = 15) # B.genAnswer() # plt.figure() # plt.plot(B.rrfunction) # plt.show() basedist = mpf(1.5)/mpf(10**6) distance = np.linspace(.8, 1.2, 3) * basedist distance2 = np.ones_like(distance) * basedist example1 = { "v":[mpf(i) * mpf(10**j) for (i,j) in [(3,4),(3,4),(5,3),(5,3)]], "c":[1,1,1,1], "g":[1/mpf(8),1/mpf(8),1/mpf(8),1/mpf(8)], "x":[distance2, -distance, distance2, -distance]} A = BP.base_parameters(example1, V =VOLTRANGE, Q= 1/mpf(4), T = mpf(20)/10**3 ) B = Rfunc_fortran(parameters = A.parameters, g = A.g, gtot = A.gtot, T = A.T, maxParameter = A.maxParameter, prefac = A.prefac, V = A.V, scaledVolt = A.scaledVolt, distance = A.input_parameters["x"][0], Vq = A.Vq) B.setParameter(nterms = 200000, maxA = 15, maxK = 15) B.genAnswer() plt.figure() plt.plot(B.rrfunction) plt.show()
import sys import Calculations import DerivedValues import InputConstraints import InputFormat import InputParameters import OutputFormat filename = sys.argv[1] outfile = open("log.txt", "a") print("var 'filename' assigned ", end="", file=outfile) print(filename, end="", file=outfile) print(" in module Control", file=outfile) outfile.close() inParams = InputParameters.InputParameters() InputFormat.get_input(filename, inParams) DerivedValues.derived_values(inParams, inParams.F_vect_1, inParams.x_1, inParams.x_2) InputConstraints.input_constraints(inParams, pi) F_vect_AC = Calculations.func_F_vect_AC(inParams) outfile = open("log.txt", "a") print("var 'F_vect_AC' assigned ", end="", file=outfile) print(F_vect_AC, end="", file=outfile) print(" in module Control", file=outfile) outfile.close() F_vect_BC = Calculations.func_F_vect_BC(inParams) outfile = open("log.txt", "a") print("var 'F_vect_BC' assigned ", end="", file=outfile) print(F_vect_BC, end="", file=outfile) print(" in module Control", file=outfile) outfile.close()
if __name__ == '__main__': import InputParameters as BP VOLTRANGE = fmfy(np.linspace(0.01, 50, 5)) * BP.GLOBAL_VOLT basedist = mpf(1.0) / mpf(10**6) distance = np.linspace(.5, 1.0, 3) * basedist distance2 = np.ones_like(distance) * basedist example1 = { "v": [mpf(i) * mpf(10**j) for (i, j) in [(2, 3), (2, 3), (8, 3), (8, 3)]], "c": [1, 1, 1, 1], "g": [1 / mpf(8), 1 / mpf(8), 1 / mpf(8), 1 / mpf(8)], "x": [distance2, -distance, distance2, -distance] } A = BP.base_parameters(example1, V=VOLTRANGE, Q=1 / mpf(4), T=mpf(5) / mpf(10**3)) B = Rfunc_CNCT(parameters=A.parameters, g=A.g, gtot=A.gtot, T=A.T, maxParameter=A.maxParameter, prefac=A.prefac, V=A.V, scaledVolt=A.scaledVolt, distance=A.input_parameters["x"][0], Vq=A.Vq) B.setParameter(nterms=400, maxA=8, maxK=10) B.genAnswer() plt.figure() plt.plot(B.rrfunction)