[d03d99]: inst / example / Poisson / Poisson.m  Maximize  Restore  History

Download this file

29 lines (20 with data), 649 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
pkg load fem-fenics msh
import_ufl_Problem ('Poisson')
# Create mesh and define function space
x = y = linspace (0, 1, 33);
mesh = Mesh(msh2m_structured_mesh (x, y, 1, 1:4));
V = FunctionSpace('Poisson', mesh);
# Define boundary condition
bc = DirichletBC(V, @(x, y) 0.0, [2;4]);
f = Expression ('f', @(x,y) 10*exp(-((x - 0.5)^2 + (y - 0.5)^2) / 0.02));
g = Expression ('g', @(x,y) sin (5.0 * x));
a = BilinearForm ('Poisson', V);
L = LinearForm ('Poisson', V, f, g);
# Compute solution
[A, b] = assemble_system (a, L, bc);
sol = A \ b;
u = Function ('u', V, sol);
# Save solution in VTK format
save (u, 'poisson')
# Plot solution
plot (u);