import sys, os sys.path.insert(0, os.path.join(os.pardir, 'src')) from u_xx_f_sympy import model2, x import sympy as sym import numpy as np from fe1D import finite_element1D, mesh_uniform, u_glob import matplotlib.pyplot as plt C = 5 D = 2 L = 4 m_values = [0, 1, 2, 3, 4] d_values = [1, 2, 3, 4] for m in m_values: u = model2(x**m, L, C, D) print('\nm=%d, u: %s' % (m, u)) u_exact = sym.lambdify([x], u) for d in d_values: vertices, cells, dof_map = mesh_uniform( N_e=2, d=d, Omega=[0,L], symbolic=False) vertices[1] = 3 # displace vertex essbc = {} essbc[dof_map[-1][-1]] = D c, A, b, timing = finite_element1D( vertices, cells, dof_map, essbc, ilhs=lambda e, phi, r, s, X, x, h: phi[1][r](X, h)*phi[1][s](X, h),
integrand = (i+1)*(j+1)*(1-x)**(i+j) A_ij = sym.integrate(integrand, (x, 0, 1)) A_ij = sym.simplify(A_ij) print A_ij psi_i = (1-x)**(i+1) integrand = 2*psi_i - D*(i+1)*(1-x)**i b_i = sym.integrate(integrand, (x, 0, 1)) - C*psi_i.subs(x, 0) b_i = sym.factor(sym.simplify(b_i)) print b_i print sym.expand(2 - (2+i)*(D+C)) # Solving model2 problem with f(x) and fe1D.py from u_xx_f_sympy import model2, x, C, D, L m = 2 u = model2(x**m, L, C, D) print u #u_exact = lambda x: D + C*(x-L) + (1./6)*(L**3 - x**3) u_exact = sym.lambdify([x, C, D, L], u) import numpy as np from fe1D import finite_element1D_naive, mesh_uniform # Override C, D and L with numeric values C = 5 D = 2 L = 4 d = 1 vertices, cells, dof_map = mesh_uniform( N_e=2, d=d, Omega=[0,L], symbolic=False)