[32a023]: obsolete / test / test_coeff.m  Maximize  Restore  History

Download this file

50 lines (39 with data), 1.9 kB

 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# We follow the dolfin example for the Poisson problem
# -div ( grad (u) ) = f on omega
# u = h on gamma_d;
# du/dn = g on gamma_n;
# See (http://fenicsproject.org/documentation/dolfin/1.2.0/cpp/demo/pde/poisson/cpp/documentation.html#index-0)
# we check if:
# 1) the classes created within fem-fenics
# like "mesh" and "functionspace" hold correctly the dolfin data
# 2) the class "expression", which we derived from dolfin::Expression
# correctly sets up the value for the bc using a function_handle
# 3) the class "boundarycondition", which handle a vecotr of pointer
# to dolfin::DirichletBC correctly stores the value for the bc
pkg load msh
addpath ("../src/")
# create a unit square mesh using msh: labels for the boundary sides are 1,2,3,4
# we can use only 2D mesh for the moment
# if you want to try with a 3D mesh, you need to use tetrahedron instead of
# triangle inside Laplace.ufl and recompile fem_fs.cpp
msho = msh2m_structured_mesh (0:0.05:1, 0:0.05:1, 1, 1:4);
mshd = fem_init_mesh (msho);
V = fem_fs (mshd);
f = @(x,y) 0;
# fem_bc takes as input the functionspace V, a function handler f,
# and the sides where we want to apply the condition
# The value on each point of the boundary is computed using
# the eval method available inside expression.h
# if a side is not specified, Neumann conditions are applied
# with g specified below
bc = fem_bc (V, f, [2, 4]);
# fem_coeff takes as input a string and a function handler
# and is used below to set the value of the coefficient of the rhs
ff = @(x,y) 10*exp(-((x - 0.5).^2 + (y - 0.5).^2) / 0.02);
f = fem_coeff ('f', ff);
gg = @(x,y) sin (5.0 * x);
g = fem_coeff ('g', gg);
# test_coeff takes as input the functionspace V, and the
# boundarycondition bc and solve the Poisson problem with
# the velues specified inside f and g;
test_coeff (V, bc, f, g);

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks