Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[32a023]: obsolete / test / test_expr.cpp Maximize Restore History

Download this file

test_expr.cpp    77 lines (59 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <dolfin.h>
#include "Laplace.h"
#include "expression.h"
#include "functionspace.h"
class Source : public dolfin::Expression
{
void eval(dolfin::Array<double>& values, const dolfin::Array<double>& x) const
{
double dx = x[0] - 0.5;
double dy = x[1] - 0.5;
values[0] = 10*exp(-(dx*dx + dy*dy) / 0.02);
}
};
class dUdN : public dolfin::Expression
{
void eval(dolfin::Array<double>& values, const dolfin::Array<double>& x) const
{
values[0] = sin(5*x[0]);
}
};
DEFUN_DLD (test_expr, args, , "test_expr: functionspace V, fcn_handle f, mesh_label label")
{
int nargin = args.length ();
octave_value retval=0;
if (nargin < 3 || nargin > 3)
print_usage ();
else
{
if (args(0).type_id () == functionspace::static_type_id ())
{
const functionspace & fspo = static_cast<const functionspace&> (args(0).get_rep ());
octave_fcn_handle * fh = args(1).fcn_handle_value ();
Array<int> side = args(2).array_value ();
if (!error_state)
{
const dolfin::FunctionSpace V = fspo.get_fsp ();
dolfin::Mesh mesh = *(V.mesh());
expression ff (*fh);
//We use dolfin now, fem-fenics not yet available
std::vector<const dolfin::BoundaryCondition*> bcu;
Source f;
dUdN g;
for (octave_idx_type i = 0; i < side.length (); ++i)
bcu.push_back (new dolfin::DirichletBC (V, ff, side(i)));
Laplace::BilinearForm a (V, V);
Laplace::LinearForm L (V);
L.f = f;
L.g = g;
dolfin::Function u(V);
dolfin::solve(a == L, u, bcu);
dolfin::File file("fem-fenics.pvd");
file << u;
dolfin::plot(u);
dolfin::interactive();
}
}
}
return retval;
}