-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
74 lines (60 loc) · 1.49 KB
/
test.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import hbconfig
import test_circuit
import numpy as np
# create circuit
circuit = test_circuit.circuit()
# set dc bias
circuit.set_bias(0.7)
# solve
circuit.dc_solve()
# get solution
sol = circuit.get_solution()
print(sol)
print((sol[1]-sol[2])/circuit.RS)
print(sol[0])
# start with hb config
hb = hbconfig.hbconfig()
nharm = 50
hb.set_harmonics(nharm)
hb.set_bias_callback(lambda x : circuit.set_bias(x))
hb.set_matrix_rhs_callback(lambda : circuit.load_circuit())
hb.set_solution_callback(lambda x : circuit.set_solution(x))
hb.set_fundamental(1e6)
hb.set_number_rows(sol.shape[0])
hb.set_dc_solution(sol)
hb.create_hb_solution()
avec = np.zeros((nharm+1,), dtype=np.cdouble)
avec[0] = 0.7
avec[1] = 0.5j
hb.set_bias_vector(avec)
# this is at the beginning of each step
#print(cb(0.0))
# print(cb(0.0))
#print(cb(1.0))
if False:
hb.get_fd_RHS()
vec = np.zeros((hb._number_rows*hb._real_frequency_vec_len,))
hb.apply_jacobian(vec)
hb.apply_preconditioner()
for i in range(100):
x, exitCode = hb.linear_solve()
r = hb.set_hb_solution_update(x)
print ("%d %1.15e" % (i, r))
if r < 1e-10:
break
#avec[1] = 0.025
#hb.set_bias_vector(avec)
#for i in range(100):
# x, exitCode = hb.linear_solve()
# hb.set_hb_solution_update(x)
X = hb.get_hb_solution()
#print(X)
Y = X[2,:]
#Y = np.concatenate((Y,np.zeros(10)))
x = hbconfig.real_ifft(Y)
if True:
import matplotlib.pyplot as plt
plt.plot(x)
#plt.stem(np.real(Y))
#plt.stem(np.imag(Y))
plt.show()