Debian Codegraph @

python/test/unit/la/test_scalar.py

raw
1 """Unit tests for the Scalar interface"""
2
3 # Copyright (C) 2011 Garth N. Wells
4 #
5 # This file is part of DOLFIN.
6 #
7 # DOLFIN is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Lesser General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # DOLFIN is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
19
20 from dolfin import *
21
22
23 def test_scalar_parallel_sum():
24 a = Scalar()
25 b = 1.0
26 a.add_local_value(b)
27 a.apply("add")
28 assert round(a.get_scalar_value() - b*MPI.size(a.mpi_comm()), 7) == 0
29
30
31 def test_scalar_assembly():
32 mesh = UnitSquareMesh(3, 3)
33
34 S = Scalar()
35 assemble(Constant(1.0)*dx(mesh), tensor=S)
36 assemble(Constant(1.0)*dx(mesh), tensor=S)
37 assert round(S.get_scalar_value() - 1.0, 7) == 0
38
39 S = Scalar()
40 assemble(Constant(1.0)*dx(mesh), tensor=S)
41 assemble(Constant(1.0)*dx(mesh), tensor=S, add_values=True)
42 assert round(S.get_scalar_value() - 2.0, 7) == 0
43
44 S = Scalar()
45 assemble(Constant(1.0)*dx(mesh), tensor=S, add_values=True)
46 assemble(Constant(1.0)*dx(mesh), tensor=S, add_values=True)
47 assert round(S.get_scalar_value() - 2.0, 7) == 0