import matplotlib.pyplot as plt from abapy.postproc import HistoryOutput time = [[1., 2., 3.], [3., 4., 5.], [5., 6., 7.]] force = [[2., 2., 2.], [3., 3., 3.], [4., 4., 4.]] Force = HistoryOutput(time, force) fig = plt.figure(0, figsize=(8, 4)) plt.clf() ax = fig.add_subplot(121) ax2 = fig.add_subplot(122) x, y = Force[[0, 2]].toArray() x2, y2 = Force[[0, 2]].plotable() ax.plot(x, y) ax2.plot(x2, y2) ax.set_ylim([1, 5]) ax2.set_ylim([1, 5]) plt.savefig('HistoryOutput-plotable.png') ax.set_title('HistorytOutput.toArray') ax2.set_title('HistorytOutput.plotable') plt.show()
from abapy.postproc import HistoryOutput from math import sin, pi N = 100 hist = HistoryOutput() time = [pi / 2 * float(i) / N for i in range(N + 1)] data = [sin(t) for t in time] hist.add_step(time_step=time, data_step=data) time2 = [10., 11.] data2 = [1., 1.] hist.add_step(time_step=time2, data_step=data2) sol = 2. / pi + 1. print('Print computed value:', hist.average()) print('Analytic solution:', sol) print('Relative error: {0:.4}%'.format((hist.average() - sol) / sol * 100.))
from abapy.postproc import HistoryOutput from math import sin, pi N = 100 hist = HistoryOutput() time = [pi / 2 * float(i)/N for i in xrange(N+1)] data = [sin(t) for t in time] hist.add_step(time_step = time, data_step = data) time2 = [10., 11.] data2 = [1., 1.] hist.add_step(time_step = time2, data_step = data2) sol = 2. / pi + 1. print 'Print computed value:', hist.average() print 'Analytic solution:', sol print 'Relative error: {0:.4}%'.format( (hist.average() - sol)/sol * 100.)
from abapy.postproc import HistoryOutput time = [ [0., 1.], [3., 4.] ] data = [ [.5, 1.5], [.5, 1.5] ] hist = HistoryOutput(time = time, data = data) hist[0].integral() hist[1].integral() hist.integral() N = 10 from math import sin, pi time = [pi / 2 * float(i)/N for i in xrange(N+1)] data = [sin(t) for t in time] hist = HistoryOutput() hist.add_step(time_step = time, data_step = data) trap = hist.integral() simp = hist.integral(method = 'simps') trap_error = (trap -1.) simp_error = (simp -1.) print 'Relative errors:\nTrapezoid rule: {0:.2}%\nSimpson rule: {1:.2}%'.format(trap_error*100, simp_error*100)
from abapy.postproc import HistoryOutput time = [[0., 1.], [3., 4.]] data = [[.5, 1.5], [.5, 1.5]] hist = HistoryOutput(time=time, data=data) hist[0].integral() hist[1].integral() hist.integral() N = 10 from math import sin, pi time = [pi / 2 * float(i) / N for i in range(N + 1)] data = [sin(t) for t in time] hist = HistoryOutput() hist.add_step(time_step=time, data_step=data) trap = hist.integral() simp = hist.integral(method='simps') trap_error = (trap - 1.) simp_error = (simp - 1.) print('Relative errors:\nTrapezoid rule: {0:.2}%\nSimpson rule: {1:.2}%'.format( trap_error * 100, simp_error * 100))
from abapy.postproc import HistoryOutput time = [[1., 2., 3.], [3., 4., 5.], [5., 6., 7.]] # Time separated in 3 steps data = [[2., 2., 2.], [3., 3., 3.], [4., 4., 4.]] # Data separated in 3 steps Data = HistoryOutput(time, data) print Data # +, *, **, abs, neg act only on data, not on time print Data + Data + 1. # addition print Data * Data * 2. # multiplication print(Data / Data) / 2. # division print Data**2 print abs(Data) print Data[1] # step 1 print Data[0:2] print Data[0, 2]