Poisson2#

Poisson equation with unit load.

Reference: https://scikit-fem.readthedocs.io/en/latest/gettingstarted.html

$u$
14 from EasyFEA import Display, ElemType, Models, Simulations, np
15 from EasyFEA.fem import Field, BiLinearForm, LinearForm
16 from EasyFEA.Geoms import Domain
17
18 if __name__ == "__main__":
19     Display.Clear()
20
21     # ----------------------------------------------
22     # Mesh
23     # ----------------------------------------------
24
25     contour = Domain((0, 0), (1, 1), 1 / 8)
26
27     mesh = contour.Mesh_2D([], ElemType.TRI15, isOrganised=True)
28
29     nodes = mesh.Nodes_Tags(["L0", "L1", "L2", "L3"])
30
31     # ----------------------------------------------
32     # Formulations
33     # ----------------------------------------------
34
35     field = Field(mesh.groupElem, 1)
36
37     @BiLinearForm
38     def bilinear_form(u: Field, v: Field):
39         return u.grad.dot(v.grad)
40
41     @LinearForm
42     def linear_form(v: Field):
43         x, y, _ = v.Get_coords()
44         f = np.sin(np.pi * x) * np.sin(np.pi * y)
45         return f * v
46
47     weakForms = Models.WeakForms(field, computeK=bilinear_form, computeF=linear_form)
48
49     # ----------------------------------------------
50     # Simulation
51     # ----------------------------------------------
52
53     simu = Simulations.WeakFormSimu(mesh, weakForms)
54
55     simu.add_dirichlet(nodes, [0], ["u"])
56
57     simu.Solve()
58
59     # ----------------------------------------------
60     # Results
61     # ----------------------------------------------
62
63     Display.Plot_Result(simu, "u", plotMesh=True)
64
65     # compute error
66     x, y, z = mesh.coord.T
67     u_an = 1 / 2 / np.pi**2 * np.sin(np.pi * x) * np.sin(np.pi * y)
68     error = np.linalg.norm(u_an - simu.u) / np.linalg.norm(u_an)
69
70     Display.plt.show()

Total running time of the script: (0 minutes 0.353 seconds)

Gallery generated by Sphinx-Gallery