This commit is contained in:
2021-09-15 10:45:08 +02:00
parent 8817ed4b4c
commit 639d1cdd74
8 changed files with 278 additions and 287 deletions

View File

@ -146,6 +146,17 @@ def plot_parameters(dat, input_file, deparameterize=False, ref=None):
for i in range(len(ids)):
cur_key = ids[i]
rec_value = np.round(2**theta[-1, idx]*current_val[i],2)
curve = 2**theta[:, idx]*current_val[i]
std_down = 2**(-np.sqrt(P[:, idx, idx]))*curve
std_up = 2**np.sqrt(P[:, idx, idx])*curve
dash_curve = true_values[ids[i]] + t*0
if ids_type[i] == 'dirichlet':
fig3, axes3 = plt.subplots(1,1,figsize=(12,5))
axes3.plot(t, curve , '-', color=col_,label= legends_ + '= ' + str(rec_value) + '/' + str(true_values[cur_key]) + '$', linewidth = 4)
@ -159,17 +170,9 @@ def plot_parameters(dat, input_file, deparameterize=False, ref=None):
axes3.set_box_aspect(1/4)
plt.xticks(fontsize=28)
plt.yticks(fontsize=28)
plt.savefig('U.png')
plt.close(fig3)
plt.savefig('results/' + name_file + '/U.png')
else:
cur_key = ids[i]
rec_value = np.round(2**theta[-1, idx]*current_val[i],2)
curve = 2**theta[:, idx]*current_val[i]
std_down = 2**(-np.sqrt(P[:, idx, idx]))*curve
std_up = 2**np.sqrt(P[:, idx, idx])*curve
dash_curve = true_values[ids[i]] + t*0
axes1.plot(t, curve , '-', color=col_,label= legends_ + '= ' + str(rec_value) + '/' + str(true_values[cur_key]) + '$', linewidth = 3)
axes1.fill_between(t, std_down, std_up, alpha=0.3, color=col_)
axes1.plot(t, dash_curve , color=col_,ls='--',linewidth = 3)
@ -202,7 +205,7 @@ def plot_parameters(dat, input_file, deparameterize=False, ref=None):
axes1.set_ylabel(r'$R_d$',fontsize=36)
axes1.legend(fontsize=36,loc='upper right')
axes1.set_xlim([-0.01,0.81])
axes1.set_ylim([1700,45000])
axes1.set_ylim([1700,55000])
axes1.set_box_aspect(1/2)
plt.xticks(fontsize=28)
plt.yticks(fontsize=28)
@ -220,7 +223,7 @@ def plot_parameters(dat, input_file, deparameterize=False, ref=None):
axes2.set_xlabel(r'$t (s)$',fontsize=36)
fig2.savefig('C.png')
fig1.savefig('Rd.png')
fig1.savefig('results/' + name_file + '/Rd.png')
if not is_ipython():
plt.show()

View File

@ -33,5 +33,7 @@ ax1.legend(fontsize=20, loc= 'upper right')
ax1.tick_params(axis='both', which='major', labelsize=22)
ax1.set_yticks([])
ax1.set_xlabel('$u$',fontsize=font_size)
ax1.set_ylabel('$J(u)$',fontsize=font_size)
plt.show()
fig1.savefig('functionals.png', dpi=500, bbox_inches='tight')

View File

@ -10,9 +10,6 @@ from matplotlib import rc
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
rc('text', usetex=True)
fig1, ax1 = plt.subplots(1,1,figsize=(8, 5))
lwidth = 2
font_size = 28
################ Flow Parameters
@ -23,148 +20,150 @@ mu = 0.5
fac = 1
nr = 50
VENC = 0.6
VENC2 = 0.4
gamma = 267.513e6 # rad/Tesla/sec Gyromagnetic ratio for H nuclei
Bo = 1.5 # Tesla Magnetic Field Strenght
TE = 5e-3 # Echo-time
M = np.ones(nr) # Magnetization
phi0 = gamma*Bo*TE # Reference phase
phi02 = phi0%3.14
M1 = np.pi/(gamma*VENC)
ff = np.pi/(1000*gamma*M1)
uv = np.arange(-4*VENC,4*VENC,ff)
r = np.linspace(-Rd, Rd, nr)
dr = r[2]-r[1]
vmax = 1
v = vmax/Rt**2*( Rt**2 - r**2 )*(np.abs(r)<Rt); # Poiseuille Formula
ai = v/vmax
theta = np.linspace(-4,5,2000)
vtest = np.linspace(-5,5,2000)
JF = 0*theta
jv = 0*theta
JV = 0*theta
JV2 = 0*theta
Mjv = np.zeros([len(theta),len(ai)])
Mjv2 = np.zeros([len(theta),len(ai)])
jv0 = 0*theta
JV0 = 0*theta
Mjv0 = np.zeros([len(theta),len(ai)])
#################################### MAGNETIZACION FROM V
phiv = phi02 + v*np.pi/VENC
phiv2 = phi02 + v*np.pi/VENC2
modv = np.ones(phiv.shape)
M1 = modv*np.cos(phi02) + 1j*modv*np.sin(phi02)
M2 = modv*np.cos(phiv) + 1j*modv*np.sin(phiv)
M2_2 = modv*np.cos(phiv2) + 1j*modv*np.sin(phiv2)
################################### FFT to COMPLEX M
S1 = np.fft.fft(M1)
S2 = np.fft.fft(M2)
################################### SubSampling
a1 = 0
a2 = 1
##### FILLED WITH ZEROS
US1 = S1
US2 = 0*S2
US2[a1::a2] = S2[a1::a2]
S2_2 = np.fft.fft(M2_2)
MR1 = np.fft.ifft(S1)
MR2 = np.fft.ifft(S2)
MR2_2 = np.fft.ifft(S2_2)
MR1 = np.fft.ifft(US1)
MR2 = np.fft.ifft(US2)
vrec1 = (np.angle(MR2)-phi02)*VENC/(np.pi)
vrec2 = (np.angle(MR2_2)-phi02)*VENC2/(np.pi)
for k in range(len(ai)):
jv0 = 1-np.cos(np.pi*(vrec1[k]-vtest)/VENC)
Mjv0[:,k] = jv0[:]
JV0 = JV0 + jv0
for k in range(len(ai)):
jv = 1-np.cos(np.pi*(vrec1[k]-theta*ai[k])/VENC)
Mjv[:,k] = jv[:]
JV = JV + jv
NJV1 = JV*100/np.max(JV)
# v func
jv0 = 1-np.cos(np.pi*(vrec1[k]-vtest)/VENC)
Mjv0[:,k] = jv0[:]
JV0 += jv0
# theta func
jv = 1-np.cos(np.pi*(vrec1[k]-theta*ai[k])/VENC)
Mjv[:,k] = jv[:]
JV += jv
jv2 = 1-np.cos(np.pi*(vrec2[k]-theta*ai[k])/VENC2)
Mjv2[:,k] = jv2[:]
JV2 += jv2
NJV1 = JV#*100/np.max(JV)
NJV2 = JV2#*110/np.max(JV)
MV = Mjv0
V =NJV1
V2 =NJV2
left, bottom, width, height = [0.2, 0.2, 0.1, 0.1]
fig = plt.figure(figsize=(12, 6), dpi=100)
ax1 = plt.subplot(1,2,1)
ch1 = 20
ch2 = 23
color1 = 'xkcd:coral'
color2 = 'xkcd:azure'
color3 = 'darkviolet'
lwidth = 2
# Miniplot
left, bottom, width, height = [0.18, 0.17, 0.1, 0.1]
ax0 = fig.add_axes([left, bottom, width, height])
ax0.plot(r,v,'b-')
ax0.plot([r[ch1]],[v[ch1]],color='xkcd:coral',marker='o')
ax0.plot([r[ch2]],[v[ch2]],color='xkcd:azure',marker='o')
ax0.plot([r[ch1]],[v[ch1]],color=color1,marker='o')
ax0.plot([r[ch2]],[v[ch2]],color=color2,marker='o')
ax0.set_xlim((-1.5,1.5))
ax0.set_xticks([])
ax0.set_ylabel(r'$u$',fontsize=20)
#for k in range(22,39):
# if k!=ch1 and k!=ch2 and np.sum(MV[:,k])!=0:
# ax1.plot(vtest, MV[:,k],color='xkcd:beige',alpha=0.8)
ax1.plot(vtest, MV[:,ch1],color='xkcd:coral',label='$v_1$')
ax1.plot(vtest, MV[:,ch2],color='xkcd:azure',label='$v_2$')
# Figure 1
#ax1.plot(vtest, MV[:,ch1],color='xkcd:coral',label='$v_1$')
#ax1.plot(vtest, MV[:,ch2],color='xkcd:azure',label='$v_2$')
ax1.plot(vtest, MV[:,ch1],color=color1,linewidth=lwidth)
ax1.plot(vtest, MV[:,ch2],color=color2,linewidth=lwidth)
m1x = vtest[np.where( np.abs(MV[:,ch1] - np.min(MV[:,ch1]))<0.001 )]
m1y = np.min(MV[:,ch1])
m2x = vtest[np.where( np.abs(MV[:,ch2] - np.min(MV[:,ch2]))<0.001 )]
#m2x = vtest[np.where(MV[:,ch2]==np.min(MV[:,ch2]))]
m2y = np.min(MV[:,ch2])
ax1.plot([m1x],[m1y],color='xkcd:coral',marker='o')
ax1.plot([m2x],[m2y],color='xkcd:azure',marker='o')
ax1.axvline(x=v[ch1], color='xkcd:coral', linestyle='--',label='$v_{1,true}$')
ax1.axvline(x=v[ch2], color='xkcd:azure', linestyle='--',label='$v_{2,true}$')
ax1.set_xlabel(r'$u$',fontsize=20)
ax1.set_ylabel(r'$J_i(u)$',fontsize=20)
#ax1.plot([m1x],[m1y],color='xkcd:coral',marker='o')
#ax1.plot([m2x],[m2y],color='xkcd:azure',marker='o')
ax1.axvline(x=v[ch1], color=color1, linestyle='--',label='$v_{1,true}$')
ax1.axvline(x=v[ch2], color=color2, linestyle='--',label='$v_{2,true}$')
ax1.set_ylabel('$individual \ functional$',fontsize=20)
#ax1.legend(loc='upper right', bbox_to_anchor=(0.5, 1.05),ncol=2, fancybox=True, shadow=True,fontsize=15)
ax1.set_yticks([])
ax1.set_xticks([])
ax1.tick_params(axis='both', which='major', labelsize=22)
#ax1.set_xticks([])
#ax1.legend(fontsize=20, loc= 'upper right')
ax1.set_xlim((-3.5,3.5))
ax1.set_ylim((-1.0,2.4))
ax2 = plt.subplot(1,2,2)
ax2.plot(theta,V,'b-')
ax2.axvline(x=1, color='k', linestyle='--')
ax2.set_xlabel(r'$\theta$',fontsize=20)
ax2.set_ylabel(r'$J_T(\theta)$',fontsize=20)
plt.yticks([])
ax2.set_xticks([])
plt.title(r'$\theta_{true}=1$' + '\n' +'$venc < v_{max}$',fontsize=15)
plt.xlim((-2,3))
plt.show()
#ax1.plot(u, J1, color = 'orangered', label = '$venc = 0.9 u_{true}$', linestyle='-',linewidth=lwidth)
#ax1.plot(u, J2, color = 'dodgerblue', label = '$venc = 0.6 u_{true}$', linestyle='-',linewidth=lwidth)
#ax1.axvline(x=1,color = 'black',linewidth = lwidth , label = '$u_{true}$')
ax1.legend(fontsize=20, loc= 'upper right')
ax1.set_ylim((-1.1,2.9))
ax1.set_xlabel('$u$',fontsize=font_size)
ax1.tick_params(axis='both', which='major', labelsize=22)
ax1.set_yticks([])
ax1.set_xlabel('$u$',fontsize=font_size)
ax1.text(-1,2.4,'$u_{true}$',fontsize=22, color = color1)
ax1.text(1.1,2.4,'$u_{true}$',fontsize=22, color = color2)
# Figure 2
ax2 = plt.subplot(1,2,2)
ax2.plot(theta,V,color=color3,linestyle = '-',linewidth=lwidth, label = '$venc=0.6u_{true}$')
ax2.plot(theta,V2,color='darkorange',linestyle = '-',linewidth=lwidth, label = '$venc=0.4u_{true}$')
ax2.axvline(x=1, color='black', linestyle='--')
ax2.set_xlabel(r'$\theta$',fontsize=font_size)
ax2.set_ylabel(r'$total \ functional$',fontsize=20)
plt.yticks([])
ax2.legend(fontsize=17, loc= 'upper left',frameon=False)
ax2.set_ylim((-3,20))
ax2.text(1.2,17,r'$ \theta _{true}$',fontsize=22, color = 'black')
ax2.tick_params(axis='both', which='major', labelsize=22)
#ax2.set_xticks([])
#plt.title(r'$\theta_{true}=1$' + '\n' +'$venc < v_{max}$',fontsize=15)
plt.xlim((-3.5,3.5))
plt.show()
#fig1.savefig('functionals.png', dpi=500, bbox_inches='tight')
fig.savefig('functionals2.png', dpi=500, bbox_inches='tight')