def test_pdes_3d_1(): print('============ test_pdes_3d_1 =============') # ... abstract model V = H1Space('V', ldim=3) v = TestFunction(V, name='v') u = TestFunction(V, name='u') a = BilinearForm((v, u), dot(grad(v), grad(u))) # ... # ... discretization # Input data: degree, number of elements p1 = 1 p2 = 1 p3 = 1 ne1 = 4 ne2 = 4 ne3 = 4 # Create uniform grid grid_1 = linspace(0., 1., num=ne1 + 1) grid_2 = linspace(0., 1., num=ne2 + 1) grid_3 = linspace(0., 1., num=ne3 + 1) # Create 1D finite element spaces and precompute quadrature data V1 = SplineSpace(p1, grid=grid_1) V1.init_fem() V2 = SplineSpace(p2, grid=grid_2) V2.init_fem() V3 = SplineSpace(p3, grid=grid_3) V3.init_fem() # Create 2D tensor product finite element space V = TensorFemSpace(V1, V2, V3) # ... # ... discretize_symbol(a, [V, V]) # print(mass.symbol.__doc__) # ... # ... n1 = 21 n2 = 21 n3 = 21 t1 = linspace(-pi, pi, n1) t2 = linspace(-pi, pi, n2) t3 = linspace(-pi, pi, n3) x1 = linspace(0., 1., n1) x2 = linspace(0., 1., n2) x3 = linspace(0., 1., n3) xs = [x1, x2, x3] ts = [t1, t2, t3] e = a.symbol(*xs, *ts) print('> ', e.min(), e.max())
def test_pdes_2d_2(): print('============ test_pdes_2d_2 =============') # ... abstract model V = H1Space('V', ldim=2) v = TestFunction(V, name='v') u = TestFunction(V, name='u') c = Constant('c', real=True, label='mass stabilization') a = BilinearForm((v, u), dot(grad(v), grad(u)) + c * v * u) # ... # ... discretization # Input data: degree, number of elements p1 = 1 p2 = 1 ne1 = 4 ne2 = 4 # Create uniform grid grid_1 = linspace(0., 1., num=ne1 + 1) grid_2 = linspace(0., 1., num=ne2 + 1) # Create 1D finite element spaces and precompute quadrature data V1 = SplineSpace(p1, grid=grid_1) V1.init_fem() V2 = SplineSpace(p2, grid=grid_2) V2.init_fem() # Create 2D tensor product finite element space V = TensorFemSpace(V1, V2) # ... # ... discretize_symbol(a, [V, V]) # print(mass.symbol.__doc__) # ... # ... n1 = 21 n2 = 21 t1 = linspace(-pi, pi, n1) t2 = linspace(-pi, pi, n2) x1 = linspace(0., 1., n1) x2 = linspace(0., 1., n2) xs = [x1, x2] ts = [t1, t2] e = a.symbol(*xs, *ts, 0.25) print('> c = 0.25 :: ', e.min(), e.max()) e = a.symbol(*xs, *ts, 0.6) print('> c = 0.6 :: ', e.min(), e.max())
def test_gelatize_2d_4(): print('============ test_gelatize_2d_4 =============') V = H1Space('V', ldim=2) v = TestFunction(V, name='v') u = TestFunction(V, name='u') expr = BilinearForm((v, u), dot(grad(v), grad(u))) print('> input >>> {0}'.format(expr)) print('> gelatized >>> {0}'.format(gelatize(expr)))
def test_symbol_3d_2(): print('============ test_symbol_3d_2 =============') # ... abstract model V = H1Space('V', ldim=3) v = TestFunction(V, name='v') u = TestFunction(V, name='u') mass = BilinearForm((v, u), u * v) laplace = BilinearForm((v, u), dot(grad(v), grad(u))) # ... # ... degrees = [1, 1, 1] symbol = compile_symbol('mass_symbol', mass, degrees) # ... # ... n1 = 21 n2 = 21 n3 = 21 t1 = linspace(-pi, pi, n1) t2 = linspace(-pi, pi, n2) t3 = linspace(-pi, pi, n3) x1 = linspace(0., 1., n1) x2 = linspace(0., 1., n2) x3 = linspace(0., 1., n3) xs = [x1, x2, x3] ts = [t1, t2, t3] e = zeros((n1, n2, n3)) # ... # ... n_elements = [4, 4, 4] symbol(*xs, *ts, e, *n_elements) print('> ', e.min(), e.max()) # ... # ... n_elements = [4, 8, 8] symbol(*xs, *ts, e, *n_elements) print('> ', e.min(), e.max())
def test_pdes_1d_1(): print('============ test_pdes_1d_1 =============') # ... abstract model V = H1Space('V', ldim=1) v = TestFunction(V, name='v') u = TestFunction(V, name='u') a = BilinearForm((v,u), dot(grad(v), grad(u))) # ... # ... discretization # Input data: degree, number of elements p1 = 1 ne1 = 4 # Create uniform grid grid_1 = linspace( 0., 1., num=ne1+1 ) # Create 1D finite element spaces and precompute quadrature data V = SplineSpace( p1, grid=grid_1 ); V.init_fem() # ... # ... discretize_symbol( a, [V,V] ) # print(mass.symbol.__doc__) # ... # ... n1 = 21 t1 = linspace(-pi, pi, n1) x1 = linspace(0.,1., n1) xs = [x1] ts = [t1] e = a.symbol(*xs, *ts) print('> ', e.min(), e.max())
def test_gelatize_1d_1(): print('============ test_gelatize_1d_1 =============') V = H1Space('V', ldim=1) v = TestFunction(V, name='v') u = TestFunction(V, name='u') nx = symbols('nx', integer=True) px = symbols('px', integer=True) tx = symbols('tx') c1 = Constant('c1') c2 = Constant('c2') c3 = Constant('c3') c4 = Constant('c4') # ... expected = Mass(px, tx) / nx assert (gelatize(BilinearForm((v, u), u * v)) == expected) # ... # ... expected = nx * Stiffness(px, tx) assert (gelatize(BilinearForm((v, u), dot(grad(v), grad(u)))) == expected) # ... # ... expected = I * Advection(px, tx) assert (gelatize(BilinearForm((v, u), dx(u) * v)) == expected) # ... # ... expected = c1 * Mass(px, tx) / nx + c2 * I * Advection( px, tx) - c3 * I * Advection(px, tx) + c4 * nx * Stiffness(px, tx) assert (gelatize( BilinearForm((v, u), c1 * v * u + c2 * dx(u) * v + c3 * dx(v) * u + c4 * dx(v) * dx(u))) == expected)
def test_symbol_2d_1(): print('============ test_symbol_2d_1 =============') # ... abstract model V = H1Space('V', ldim=2) v = TestFunction(V, name='v') u = TestFunction(V, name='u') mass = BilinearForm((v, u), u * v) laplace = BilinearForm((v, u), dot(grad(v), grad(u))) # ... # ... degrees = [1, 1] n_elements = [4, 4] symbol = compile_symbol('mass_symbol', mass, degrees, n_elements=n_elements) # ... # ... n1 = 101 n2 = 101 t1 = linspace(-pi, pi, n1) t2 = linspace(-pi, pi, n2) x1 = linspace(0., 1., n1) x2 = linspace(0., 1., n2) xs = [x1, x2] ts = [t1, t2] e = zeros((n1, n2)) symbol(*xs, *ts, e) print('> ', e.min(), e.max())
def test_gelatize_3d_1(): print('============ test_gelatize_3d_1 =============') V = H1Space('V', ldim=3) v = TestFunction(V, name='v') u = TestFunction(V, name='u') nx, ny, nz = symbols('nx ny nz', integer=True) px, py, pz = symbols('px py pz', integer=True) tx, ty, tz = symbols('tx ty tz') c = Constant('c') bx = Constant('bx') by = Constant('by') bz = Constant('bz') b = Tuple(bx, by, bz) # ... expected = Mass(px, tx) * Mass(py, ty) * Mass(pz, tz) / (nx * ny * nz) assert (gelatize(BilinearForm((v, u), u * v)) == expected) # ... # ... expected = nx * Mass(py, ty) * Mass(pz, tz) * Stiffness(px, tx) / (ny * nz) assert (gelatize(BilinearForm((v, u), dx(u) * dx(v))) == expected) # ... # ... expected = I * Advection(py, ty) * Mass(px, tx) * Mass(pz, tz) / (nx * nz) assert (gelatize(BilinearForm((v, u), dy(u) * v)) == expected) # ... # ... expected = I * Advection(px, tx) * Mass(py, ty) * Mass(pz, tz) / (ny * nz) assert (gelatize(BilinearForm((v, u), dx(u) * v)) == expected) # ... # ... expected = (nx * Mass(py, ty) * Mass(pz, tz) * Stiffness(px, tx) / (ny * nz) + ny * Mass(px, tx) * Mass(pz, tz) * Stiffness(py, ty) / (nx * nz) + nz * Mass(px, tx) * Mass(py, ty) * Stiffness(pz, tz) / (nx * ny)) assert (gelatize(BilinearForm((v, u), dot(grad(v), grad(u)))) == expected) # ... # ... expected = ( nx * Mass(py, ty) * Mass(pz, tz) * Stiffness(px, tx) / (ny * nz) + I * Advection(px, tx) * Mass(py, ty) * Mass(pz, tz) / (ny * nz) + ny * Mass(px, tx) * Mass(pz, tz) * Stiffness(py, ty) / (nx * nz) + I * Advection(py, ty) * Mass(px, tx) * Mass(pz, tz) / (nx * nz) + nz * Mass(px, tx) * Mass(py, ty) * Stiffness(pz, tz) / (nx * ny)) assert (gelatize( BilinearForm( (v, u), dot(grad(v), grad(u)) + dx(u) * v + dy(u) * v)) == expected) # ... # ... expected = (-bx * I * Advection(px, tx) * Mass(py, ty) * Mass(pz, tz) / (ny * nz) - by * I * Advection(py, ty) * Mass(px, tx) * Mass(pz, tz) / (nx * nz) - bz * I * Advection(pz, tz) * Mass(px, tx) * Mass(py, ty) / (nx * ny)) assert (gelatize(BilinearForm((v, u), dot(b, grad(v)) * u)) == expected) # ... # ... expected = (bx**2 * nx * Mass(py, ty) * Mass(pz, tz) * Stiffness(px, tx) / (ny * nz) + 2 * bx * by * Advection(px, tx) * Advection(py, ty) * Mass(pz, tz) / nz + 2 * bx * bz * Advection(px, tx) * Advection(pz, tz) * Mass(py, ty) / ny + by**2 * ny * Mass(px, tx) * Mass(pz, tz) * Stiffness(py, ty) / (nx * nz) + 2 * by * bz * Advection(py, ty) * Advection(pz, tz) * Mass(px, tx) / nx + bz**2 * nz * Mass(px, tx) * Mass(py, ty) * Stiffness(pz, tz) / (nx * ny)) assert (gelatize(BilinearForm( (v, u), dot(b, grad(v)) * dot(b, grad(u)))) == expected) # ... degrees = None # degrees = [2, 1, 1] # evaluate = True evaluate = False
def test_gelatize_2d_1(): print('============ test_gelatize_2d_1 =============') V = H1Space('V', ldim=2) v = TestFunction(V, name='v') u = TestFunction(V, name='u') nx, ny = symbols('nx ny', integer=True) px, py = symbols('px py', integer=True) tx, ty = symbols('tx ty') c = Constant('c') bx = Constant('bx') by = Constant('by') b = Tuple(bx, by) # ... expected = Mass(px, tx) * Mass(py, ty) / (nx * ny) assert (gelatize(BilinearForm((v, u), u * v)) == expected) # ... # ... expected = Mass(py, ty) * nx * Stiffness(px, tx) / ny assert (gelatize(BilinearForm((v, u), dx(u) * dx(v))) == expected) # ... # ... expected = I * Advection(py, ty) * Mass(px, tx) / nx assert (gelatize(BilinearForm((v, u), dy(u) * v)) == expected) # ... # ... expected = I * Advection(px, tx) * Mass(py, ty) / ny assert (gelatize(BilinearForm((v, u), dx(u) * v)) == expected) # ... # ... expected = Mass(px, tx) * ny * Stiffness(py, ty) / nx + Mass( py, ty) * nx * Stiffness(px, tx) / ny assert (gelatize(BilinearForm((v, u), dot(grad(v), grad(u)))) == expected) # ... # ... expected = (nx * Mass(py, ty) * Stiffness(px, tx) / ny + I * Advection(px, tx) * Mass(py, ty) / ny + ny * Mass(px, tx) * Stiffness(py, ty) / nx + I * Advection(py, ty) * Mass(px, tx) / nx) assert (gelatize( BilinearForm( (v, u), dot(grad(v), grad(u)) + dx(u) * v + dy(u) * v)) == expected) # ... # ... expected = -bx * I * Advection(px, tx) * Mass( py, ty) / ny - by * I * Advection(py, ty) * Mass(px, tx) / nx assert (gelatize(BilinearForm((v, u), dot(b, grad(v)) * u)) == expected) # ... # ... expected = bx**2 * nx * Mass(py, ty) * Stiffness( px, tx) / ny + 2 * bx * by * Advection(px, tx) * Advection( py, ty) + by**2 * ny * Mass(px, tx) * Stiffness(py, ty) / nx assert (gelatize(BilinearForm( (v, u), dot(b, grad(v)) * dot(b, grad(u)))) == expected) # ... degrees = None # degrees = [2, 1] # evaluate = True evaluate = False