Poisson2#

Poisson equation with unit load.

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

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

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

Gallery generated by Sphinx-Gallery