From 6834e8163ad97d998eb857aa8e9787b4393aa28f Mon Sep 17 00:00:00 2001 From: Laura Pfeiffer <laura.pfeiffer@kit.edu> Date: Sun, 11 Aug 2024 07:54:56 +0200 Subject: [PATCH] added evaluation adaptive --- tools/evaluation/thesisCoupled.py | 119 ++++++------------------ tools/evaluation/utility/computing.py | 12 +++ tools/evaluation/utility/latexTables.py | 57 ++++++++---- tools/evaluation/utility/plotting.py | 36 +++++++ 4 files changed, 117 insertions(+), 107 deletions(-) diff --git a/tools/evaluation/thesisCoupled.py b/tools/evaluation/thesisCoupled.py index b232973ee..969e58016 100644 --- a/tools/evaluation/thesisCoupled.py +++ b/tools/evaluation/thesisCoupled.py @@ -15,7 +15,11 @@ threshold=-50.0 fMech0008='../../../data/Kopplung/TimeStepTest/Mech0008/' fMech0016='../../../data/Kopplung/TimeStepTest/Mech0016/' -fMechAdaptive='../../../data/Kopplung/TimeStepTest/adaptive/' +fMech0032='../../../data/Kopplung/TimeStepTest/Mech0032/' +fMechAdaptive16='../../../data/Kopplung/TimeStepTest/adaptive16/' +fMechAdaptive32='../../../data/Kopplung/TimeStepTest/adaptive32/' +fMechAdaptive='../../../data/Kopplung/TimeStepTest/adaptiveTest/' + def DifferencePerPointTabs(case): lL=[1,2,3,4] @@ -209,7 +213,7 @@ def plotSchwinger(): plot.Unterschwinger(fL,nL,threshold,p,j,savePath) plot.Oberschwinger(fL,nL,threshold,p,j,savePath) -def PlottingForAdaptive(): +def PlottingForAdaptive(path,name): lL=[2] tL=[0,1,2] sdt=0.0004 @@ -217,80 +221,9 @@ def PlottingForAdaptive(): listEvaluationPoints=[2,3,4,5,6,7,8,9] l=2 - read.writeVolumeDataInFile(fMechAdaptive,lL,[0],1) - read.writeGammaDataInFile(fMechAdaptive,lL,[0],1,len(listEvaluationPoints),True) - lvRvLabel=["LV volume", "RV volume"] - vol, dataTime, dataStep = read.VolumeDataFromLog(fMechAdaptive, read.createFilename(l,0,1)) - for i in range(len(vol)): - plt.plot(dataTime, vol[i], label ='j=0'+ lvRvLabel[i]+', $\ell='+str(l)+'$',linewidth=2.5) - - stepSize=[] - for i in range(len(dataTime)-1): - stepSize.append(100000*(dataTime[i+1]-dataTime[i])) - - - plt.plot(dataTime[:-1],stepSize,label='Time j=0',linewidth=2.5) - #vol, dataTime, dataStep = read.VolumeDataFromLog(fMechAdaptive, read.createFilename(l,2,1)) - #for i in range(len(vol)): - #plt.plot(dataTime, vol[i], label ='j=2'+ lvRvLabel[i]+', $\ell='+str(l)+'$',linewidth=2.5) - #stepSize=[] - #for i in range(len(dataTime)-1): - # stepSize.append(100000*(dataTime[i+1]-dataTime[i])) - #plt.plot(dataTime[:-1],stepSize,label='Time j=2',linewidth=2.5) - - vol, dataTime, dataStep = read.VolumeDataFromLog(fMech0016, read.createFilename(l,0,1)) - #for i in range(len(vol)): - #plt.plot(dataTime, vol[i], label = 'MechDT=0.0016 j=0 '+lvRvLabel[i]+', $\ell='+str(l)+'$',linewidth=2.5) - - - vol_full, dataTime_full, dataStep = read.VolumeDataFromLog(fSISVI, read.createFilename(l,0,1)) - for i in range(len(vol)): - plt.plot(dataTime_full, vol_full[i], label = 'Full j=0 '+lvRvLabel[i]+', $\ell='+str(l)+'$',linewidth=2.5,linestyle='dotted') - - (time,V)= read.getDataFromTXT(fMechAdaptive,read.createFilename(l,0,1)+'Gamma',10) - steigung=[] - for i in range(len(V)-1): - #print(V[i]-V[i+1],abs(V[i]-V[i+1])) - steigung.append(10*abs(V[i]-V[i+1])/abs(time[i]-time[i+1])) - - plt.plot(time[1:],steigung, label = 'steigung in j='+str(0),linewidth=2.5) - for i in range(len(V)): - V[i]*=100 - plt.plot(time,V, label = 'gamma in j='+str(0),linewidth=2.5) - - #(time,V)= read.getDataFromTXT(fMechAdaptive,read.createFilename(l,2,1)+'Gamma',10) - #steigung=[] - #for i in range(len(V)-1): - #print(V[i]-V[i+1],abs(V[i]-V[i+1])) - #steigung.append(10*abs(V[i]-V[i+1])/abs(time[i]-time[i+1])) - - #plt.plot(time[1:],steigung, label = 'steigung in j='+str(2),linewidth=2.5) - #for i in range(len(V)): - #V[i]*=100 - #plt.plot(time,V, label = 'gamma in j='+str(2),linewidth=2.5) - - (time,V)= read.getDataFromTXT(fSISVI,read.createFilename(l,0,1)+'Gamma',10) - steigung=[] - for i in range(len(V)-1): - #print(V[i]-V[i+1],abs(V[i]-V[i+1])) - steigung.append(10*abs(V[i]-V[i+1])/abs(time[i]-time[i+1])) - - plt.plot(time[1:],steigung, label = 'SISVI steigung in j='+str(0),linewidth=2.5) - for i in range(len(V)): - V[i]*=100 - plt.plot(time,V, label = 'SISVI gamma in j='+str(0),linewidth=2.5) - - diff =[] - n=int((len(vol_full[0])-1)/(len(vol[0])-1)) - #print(len(vol_full[0]),len(vol[0]),n) - for i in range(len(dataTime)): - diff.append(vol_full[0][i*n]-vol[0][i]) - - #plt.plot(dataTime,diff,label='diff Full-Mech0016',linewidth=2.5) - plt.legend(bbox_to_anchor=(1.05,1.00), loc="upper left") - plt.xlabel('Zeit (s)') - plt.ylabel('Volumen (ml)') - plt.show() + savePath='../../../thesis-lindner/thesis/images/coupled/' + plot=Plot(lL,tL,sdt,endTime,1,listEvaluationPoints) + plot.plotAdaptive(l,path,name,savePath) def MechTimeStepTestTable(): lL=[2] @@ -298,21 +231,28 @@ def MechTimeStepTestTable(): sdt=0.0004 endTime=0.6 listEvaluationPoints=[2,3,4,5,6,7,8,9] - nL=['${\\vartriangle}t^{\\mathrm{m}}={\\vartriangle}t^{\\mathrm{e}}$ ','${\\vartriangle}t^{\\mathrm{m}}=0.0008$\, s','${\\vartriangle}t^{\\mathrm{m}}=0.0016$\, s'] - fL=[fSISVI,fMech0008,fMech0016] - - #read.writeVolumeDataInFile(fMech0016,lL,tL,1) - #read.writeDataInFile(fMech0008,lL,tL,1) - #read.writeDataInFile(fMech0016,lL,tL,1) - #read.writeCaDataInFile(fMech0008,lL,tL,1,len(listEvaluationPoints),True) - #read.writeCaDataInFile(fMech0016,lL,tL,1,len(listEvaluationPoints),True) - #read.writeGammaDataInFile(fMech0008,lL,tL,1,len(listEvaluationPoints),True) - #read.writeGammaDataInFile(fMech0016,lL,tL,1,len(listEvaluationPoints),True) - + nL=['${\\vartriangle}t^{\\mathrm{m}}={\\vartriangle}t^{\\mathrm{e}}$ ','${\\vartriangle}t^{\\mathrm{m}}=0.8$','${\\vartriangle}t^{\\mathrm{m}}=1.6$', '$\\dtMechAd=1.6$',' $\\dtMechAd=3.2$',] + fL=[fSISVI,fMech0008,fMech0016,fMechAdaptive16,fMechAdaptive32] + numberofAdaptive=2 + + #read.writeVolumeDataInFile(fMechAdaptive16,lL,[2],1) + #read.writeVolumeDataInFile(fMechAdaptive32,lL,[2],1) + + #read.writeDataInFile(fMechAdaptive16,lL,[2],1) + #read.writeDataInFile(fMechAdaptive32,lL,[2],1) + + #read.writeCaDataInFile(fMech0032,lL,[2],1,len(listEvaluationPoints),True) + #read.writeCaDataInFile(fMechAdaptive16,lL,[2],1,len(listEvaluationPoints),True) + #read.writeCaDataInFile(fMechAdaptive32,lL,[2],1,len(listEvaluationPoints),True) + + #read.writeGammaDataInFile(fMechAdaptive16,lL,[2],1,len(listEvaluationPoints),True) + #read.writeGammaDataInFile(fMechAdaptive32,lL,[2],1,len(listEvaluationPoints),True) + + l=2 savePath='../../../thesis-lindner/thesis/tables/erstmal/coupled/' tabWriter = TableWriter(lL,tL,sdt,endTime,1,[fSIOC],listEvaluationPoints) for p in listEvaluationPoints: - tabWriter.writeMechTimeStepTestTable(l,p,fL,nL,threshold,savePath) + tabWriter.writeMechTimeStepTestTable(l,p,fL,nL,threshold,savePath,numberofAdaptive) plot=Plot(lL,tL,sdt,endTime,1,listEvaluationPoints) #plot.volumesDifferentAlgs(nL,fL,l.j,) @@ -578,7 +518,8 @@ if __name__=="__main__": #MechTimeStep listEvaluationPoints ################################## #MechTimeStepTestTable() - PlottingForAdaptive() + PlottingForAdaptive(fMechAdaptive16,'${\\vartriangle}t^{\\mathrm{m,beg}}=1.6\,$ms') + #PlottingForAdaptive(fMechAdaptive32,'A 32') ###################################### diff --git a/tools/evaluation/utility/computing.py b/tools/evaluation/utility/computing.py index 19be0c7a8..24eafbba3 100644 --- a/tools/evaluation/utility/computing.py +++ b/tools/evaluation/utility/computing.py @@ -110,6 +110,18 @@ def L2DiffEx(path,l,j,m,V,p,start_dt,T): norm =L2(Diff,start_dt,T) return(norm) +def L2DiffWithVaryingTimeStepSize(V,W,t_v,t_w): + Diff=[] + for i in range(len(t_w)): + interpolatedV=np.interp(t_w[i], t_v, V) + Diff.append(interpolatedV-W[i]) + + + dt=t_w[1] + norm =L2(Diff,dt,1.0,0,False) + return(norm) + + def L2DiffInterval(V,W,dt,j_v,j_w,p=0): Diff=[] diff=abs(j_v-j_w) diff --git a/tools/evaluation/utility/latexTables.py b/tools/evaluation/utility/latexTables.py index 4fdde8f2c..cb822b2dc 100644 --- a/tools/evaluation/utility/latexTables.py +++ b/tools/evaluation/utility/latexTables.py @@ -2244,10 +2244,16 @@ class Table: block +=self.EndTabular() return block - def MechTimeStepTest(self,l,p,fL,nL,th): + def MechTimeStepTest(self,l,p,fL,nL,th, numberofAdaptive): L=4 block = '' block+='\\toprule\n' + block+='\\multicolumn{2}{c}{}'+ '&\\multicolumn{'+str(len(fL)-numberofAdaptive)+'}{c}{festes ${\\vartriangle}t^{\\mathrm{m}}$} '+'&\\multicolumn{'+str(numberofAdaptive)+'}{c}{adaptives Verfahren }' + block+='\\\\\n' + #block+='\cmidrule(r){1-2}\n' + block+='\cmidrule(lr){3-'+str(len(fL)-numberofAdaptive+2)+'}\n' + block+='\cmidrule(l){'+str(len(fL)-numberofAdaptive+3)+'-'+str(len(fL)+2)+'}\n' + block+='\\multicolumn{2}{c}{$\\ell='+str(l)+'$}' for name in nL: block+='& '+name @@ -2284,6 +2290,7 @@ class Table: j_refVol=3 LV_ref=comp.getFullExtrapolate(L,j_refVol,self.m,1,self.sdt,self.T,self.exP,'Volumes') RV_ref=comp.getFullExtrapolate(L,j_refVol,self.m,2,self.sdt,self.T,self.exP,'Volumes') + t_ref=np.linspace(0.0, self.T, num=len(LV_ref)) normLV_ref=comp.L2(LV_ref,self.sdt,self.T,j_refVol-1,False) normRV_ref=comp.L2(RV_ref,self.sdt,self.T,j_refVol-1,False) @@ -2371,26 +2378,40 @@ class Table: for alg in fL: (t,LV)=read.getDataFromTXT(alg,read.createFilename(l,j,self.m)+'Volumes',1) - - sdtnew=(int(1000.0*1000.0*self.T)//((len(LV)-1)))/(1000*1000) - refJ=int(math.log(sdtnew/(self.sdt*2**(-(j_refVol-1))) ,2)) - - value=comp.L2DiffInterval(LV,LV_ref,sdtnew,0,refJ) - value=value/normLV_ref - block += " & $"+ str("%8.4f"%(value))+"$" + if len(LV)!=0: + value=0.0 + if 'Mech' in alg: + sdtnew=(int(1000.0*1000.0*self.T)//((len(LV)-1)))/(1000*1000) + refJ=int(math.log(sdtnew/(self.sdt*2**(-(j_refVol-1))) ,2)) + value=comp.L2DiffInterval(LV,LV_ref,self.sdt,0,refJ) + else: + value=comp.L2DiffWithVaryingTimeStepSize(LV,LV_ref,t,t_ref) + + value=value/normLV_ref + block += " & $"+ str("%8.4f"%(value))+"$" + else: + block+=" & - " + block+='\\\\[2pt]\n' #RV: block+='& $\\errorRV^{'+str(j)+','+str(l)+'}$' for alg in fL: (t,RV)=read.getDataFromTXT(alg,read.createFilename(l,j,self.m)+'Volumes',2) - - sdtnew=(int(1000.0*1000.0*self.T)//((len(RV)-1)))/(1000*1000) - refJ=int(math.log(sdtnew/(self.sdt*2**(-(j_refVol-1))) ,2)) - - value=comp.L2DiffInterval(RV,RV_ref,self.sdt,0,refJ) - value=value/normRV_ref - block += " & $"+ str("%8.4f"%(value))+"$" + if len(RV)!=0: + value=0.0 + if 'Mech' in alg: + sdtnew=(int(1000.0*1000.0*self.T)//((len(RV)-1)))/(1000*1000) + refJ=int(math.log(sdtnew/(self.sdt*2**(-(j_refVol-1))) ,2)) + value=comp.L2DiffInterval(RV,RV_ref,self.sdt,0,refJ) + + else: + value=comp.L2DiffWithVaryingTimeStepSize(RV,RV_ref,t,t_ref) + + value=value/normRV_ref + block += " & $"+ str("%8.4f"%(value))+"$" + else: + block+=" & - " block+='\\\\[2pt]\n' @@ -3538,14 +3559,14 @@ class TableWriter: output_file.write(self.tab.writeEndTable()) - def writeMechTimeStepTestTable(self,l,p,fL,nL,threshold,savePath): + def writeMechTimeStepTestTable(self,l,p,fL,nL,threshold,savePath,numberofAdaptive): - cap='Untersuchung verschiedener Varianten zur Anpassung der Zeitschrittweite ${\\vartriangle}t^{\\mathrm{m}}$ für die Mechanik für das \\emm~berechnet mit dem \\SISVI~in '+self.tab.getPointNamebyNumber(p,False)+'. Es wurden $512$ parallele Prozesse auf dem HoreKa verwendet und die Rechenzeit ist in Stunden:Minuten:Sekunden angegeben' + cap='Untersuchung verschiedener Varianten zur Anpassung der Zeitschrittweite ${\\vartriangle}t^{\\mathrm{m}}$ für die Mechanik für das \\emm~berechnet mit dem \\SISVI~in '+self.tab.getPointNamebyNumber(p,False)+'. Es wurden $512$ parallele Prozesse auf dem HoreKa verwendet. Die Rechenzeit ist in Stunden:Minuten:Sekunden und die Zeitschrittweiten sind in Millisekunden angegeben' label ='tab:MechTimeStepTestP'+str(p) filename=savePath +'MechTimeStepTestP'+str(p) with open(filename+'.tex', 'w') as output_file: output_file.write(self.tab.writeBeginApproxAndDurationTabList(p,cap,label,fL,False)) - output_file.write(self.tab.MechTimeStepTest(l,p,fL,nL,threshold)) + output_file.write(self.tab.MechTimeStepTest(l,p,fL,nL,threshold,numberofAdaptive)) output_file.write(self.tab.writeEndTable()) def writeDifferenceTablePerPoint(self,l,j,fL,nL,savePath,case,threshold=-50.0,experiment=''): diff --git a/tools/evaluation/utility/plotting.py b/tools/evaluation/utility/plotting.py index 89f4c3123..18de04556 100644 --- a/tools/evaluation/utility/plotting.py +++ b/tools/evaluation/utility/plotting.py @@ -1380,7 +1380,43 @@ class Plot: time=np.linspace(0,T,n) plt.plot(time,V) plt.show() + + def plotAdaptive(self,l,path,name,sP): + resize=2 + lvRvLabel=['LV','RV']#["$\\LV$", "\\RV$"] + fig, ax1 = plt.subplots() + ax1.set_xlabel('Zeit (s)') + #ax1.set_ylabel('Volumen (ml)~~~~') + ax1.set_ylabel('$\\norm{\\gf}_\\infty$') + ax2 = ax1.twinx() + ax2.set_ylabel('${\\vartriangle}t^{\\mathrm{m}}$ (ms)') #10^6\\cdot + for j in self.tL: + vol, dataTime, dataStep = read.VolumeDataFromLog(path, read.createFilename(l,j,1)) + (time,V)= read.getDataFromTXT(path,read.createFilename(l,j,1)+'Gamma',10) + (time,V)=self.resizeData(time,V,resize*2**(j),len(time)) + ax1.plot(time,V,label='$\\norm{\\gf}_\\infty$ für'+' $j='+str(j)+'$ ',linewidth=2.5,color=self.colorList[j],linestyle=self.linestyleList[2]) + times=[dataTime,dataTime] + #for i in range(len(vol)): + #(times[i],vol[i])=self.resizeData(times[i],vol[i],resize*2**(j),len(times[i])) + #ax1.plot(times[i], vol[i], label =lvRvLabel[i]+' $j='+str(j)+'$ ',linewidth=2.5,color=self.colorList[j],linestyle=self.linestyleList[i+1]) + stepSize=[] + for i in range(len(dataTime)-1): + stepSize.append(1000.0*(dataTime[i+1]-dataTime[i])) #100000* + #(dataTime,stepSize)=self.resizeData(dataTime,stepSize,resize*2**(j),len(dataTime)) + ax2.plot(dataTime[:-2],stepSize[:-1],label='${\\vartriangle}t^{\\mathrm{m}}$ für $j='+str(j)+'$',linewidth=3.5,color=self.colorList[j])#, marker=self.markerList[j],linestyle='dotted',markersize=self.markerSizeList[j]) + + ax1.legend(bbox_to_anchor=(-0.2,1.00), loc="upper right") + ax2.legend(title=' ${\\vartriangle}t^{\\mathrm{m}}$',bbox_to_anchor=(1.2,1.00), loc="upper left") + ax1.set_ylim([-0.4,0.3]) + ax2.set_ylim([0.0,3.0]) + #ax2.tick_params(axis ='y', labelcolor = color) + plt.title(name) + #plt.show() + #plotname='TimeStepsizeWithVolumes' + plotname='TimeStepsizeWithMaxnormGamma' + self.saveTikz(sP, plotname) + plt.close() def resizeData(t,V,number,length): time=[] -- GitLab