Debian Codegraph @

demo/undocumented/block-matrix/cpp/main.cpp

raw
1 // Copyright (C) 2008 Kent-Andre Mardal
2 //
3 // This file is part of DOLFIN.
4 //
5 // DOLFIN is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // DOLFIN is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // Modified by Anders Logg, 2008.
19 // Modified by Garth N. Wells, 2010-2011.
20 //
21 // First added: 2008-12-12
22 // Last changed: 2012-11-12
23 //
24 // This demo illustrates basic usage of block matrices and vectors.
25
26 #include <dolfin.h>
27 #include "StiffnessMatrix.h"
28
29 using namespace dolfin;
30
31 int main()
32 {
33 // Create mesh
34 auto mesh = std::make_shared<UnitSquareMesh>(32, 32);
35
36 // Create a simple stiffness matrix and vector
37 auto V = std::make_shared<StiffnessMatrix::FunctionSpace>(mesh);
38
39 StiffnessMatrix::BilinearForm a(V, V);
40 std::shared_ptr<GenericMatrix> A(new Matrix);
41 assemble(*A, a);
42
43 StiffnessMatrix::LinearForm L(V);
44 std::shared_ptr<GenericVector> x(new Vector);
45 assemble(*x, L);
46
47 // Create a block matrix
48 BlockMatrix AA(2, 2);
49 AA.set_block(0, 0, A);
50 AA.set_block(1, 0, A);
51 AA.set_block(0, 1, A);
52 AA.set_block(1, 1, A);
53
54 // Create block vector
55 BlockVector xx(2);
56 xx.set_block(0, x);
57 xx.set_block(1, x);
58
59 // Create another block vector
60 std::shared_ptr<GenericVector> y(new Vector);
61 A->init_vector(*y, 0);
62 BlockVector yy(2);
63 yy.set_block(0, y);
64 yy.set_block(1, y);
65
66 // Multiply
67 AA.mult(xx, yy);
68 info("||Ax|| = %g", y->norm("l2"));
69 }