plt.slope_triangle(h, err) plt.ylabel('L2 error of stress') plt.grid(True) class test(unittest.TestCase): def test0(self): err, hmax = main(nr=0, withplots=False) numpy.testing.assert_almost_equal(err, 3.917807, decimal=6) numpy.testing.assert_almost_equal(hmax, 5.0, decimal=6) def test1(self): err, hmax = main(nr=2, withplots=False) numpy.testing.assert_almost_equal(err, 1.476470, decimal=6) numpy.testing.assert_almost_equal(hmax, 2.028562, decimal=6) def test2(self): err, hmax = main(L=3, R=1.5, E=1e6, nu=0.4, T=15, nr=3, withplots=False) numpy.testing.assert_almost_equal(err, 0.254238, decimal=6) numpy.testing.assert_almost_equal(hmax, 0.768562, decimal=6) if __name__ == '__main__': cli.choose(main, convergence)
def convergence(nrefine=5): err, h = numpy.array([main(nr=irefine) for irefine in log.range('refine', nrefine)]).T with plot.PyPlot( 'convergence' ) as plt: plt.loglog(h, err, 'k*--') plt.slope_triangle(h, err) plt.ylabel('L2 error of stress') plt.grid(True) class test(unittest.TestCase): def test0(self): err, hmax = main(nr=0, figures=False) numpy.testing.assert_almost_equal(err, 3.917807, decimal=6) numpy.testing.assert_almost_equal(hmax, 5.0, decimal=6) def test1(self): err, hmax = main(nr=2, figures=False) numpy.testing.assert_almost_equal(err, 1.476470, decimal=6) numpy.testing.assert_almost_equal(hmax, 2.028562, decimal=6) def test2(self): err, hmax = main(L=3, R=1.5, E=1e6, nu=0.4, T=15, nr=3, figures=False) numpy.testing.assert_almost_equal(err, 0.254238, decimal=6) numpy.testing.assert_almost_equal(hmax, 0.768562, decimal=6) if __name__ == '__main__': cli.choose(main, convergence)
nelems=10, timescale=.1, degree=2, endtime=.01, withplots=False) assert debug.checkdata( retvals, ''' eNpVkcsNxDAIBdtJJFsyYH4Fuf8W1kA47Gkk5DzeEBjPHsDveB4goDN5ILEFydyDsBjOvK+EPYhbLMgg ElSQnDtTzoFZz6QBvjCIyEVTDtJySyLTH795v+vvOqdze0/v7R7dq3t27/Zor/a8znh3nSkDBZKgKvnE oU4AUSVOgF8kFdUxo5mlSLmKN62sdjslt2GdxnfSq6q7UuVBqtmynBtg5XipkbqWQuWBaf2KpViUUoRQ jd5bk9nvKvP29Lu3Db7j/QGOWGzS''') retvals = main(ndims=2, nelems=4, timescale=.1, degree=1, endtime=.01, withplots=False) assert debug.checkdata( retvals, ''' eNplUllywyAMvU4yAzNoRT5Q7n+FGuRHU/VLWMhvE9Re2sje7fUSV/302YhnfLqfqhq86nS5sk/06dbY 57Wqsvqq6GMOfcwBDzzARR///c4n3sH3cX9rY5P4rjpYvr8xV/vArfrAU/mqnspX9fzjq3oKX9VT8677 qHnXffzPu+yj5F33cb8BEh6r1Y3d/hyYxgbr0+ZG6xKXrI4MTjozXTa7XD5yNIZvIouxboSI94UJz30h 6gnO+lx48oMF4IcNLOoxt1niDPupNOzWK0tvcoakOlrLuPthc8/PDKu7yDZIM1K+RqQY+ID84wc+wAFs cIHjdsW7P3Q/gFP1eXChe64bjfxxzkzOOYM5SSEhJHaSgo8jH36OD7AccLAdFibxJ/58EedAYhvs3d4/ YD7oyg==''') if __name__ == '__main__': cli.choose(main, unittest)
assert debug.checkdata( retvals, ''' eNoz1NEw0TE01dTRMLY0tEjVNdYxNTAwANGaAEntBW4=''') retvals = main(nr=2, withplots=False) assert debug.checkdata( retvals, ''' eNoz1NEw0TE01dTRMDQxN0vVNdYxMjCyBNGaAEniBXM=''') retvals = main(L=3, R=1.5, E=1e6, nu=0.4, T=15, nr=3, withplots=False) assert debug.checkdata( retvals, ''' eNoz1NEw0TE01dTRMDI1MUrVNdExN7MwA9GaAEohBX4=''') def exact_solution(geometry, T, R, E, nu): mu = .5 * E / (1 + nu) k = (3 - nu) / (1 + nu) #Plane stress parameter x, y = geometry / R #Dimensionless coordinates r2 = x**2 + y**2 return T / (4 * mu) * geometry * ( [(k + 1) / 2, (k - 3) / 2] + [1 + k, 1 - k] / r2 + (1 - 1 / r2) * [x**2 - 3 * y**2, 3 * x**2 - y**2] / r2**2) if __name__ == '__main__': cli.choose(main, convergence, unittest)