forked from sfepy/sfepy
/
test_assembling.py
107 lines (79 loc) · 3.86 KB
/
test_assembling.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import numpy as nm
import scipy.sparse as sps
from sfepy.base.testing import TestCommon
class Test(TestCommon):
@staticmethod
def from_conf(conf, options):
conn = nm.array([[0, 1, 2],
[2, 3, 4]], dtype=nm.int32)
num = conn.max() + 1
iels = nm.array([0, 1], dtype=nm.int32)
vec_in_els = nm.array([[1, 1, 1], [2, 2, 2]], dtype=nm.float64)
vec_in_els.shape = (2, 1, 1, 3)
mtx_in_els = nm.array([nm.ones((3, 3)), 2 * nm.ones((3, 3))],
dtype=nm.float64)
mtx_in_els.shape = (2, 1, 3, 3)
return Test(conn=conn, num=num, iels=iels,
vec_in_els=vec_in_els, mtx_in_els=mtx_in_els,
conf=conf, options=options)
def test_assemble_vector(self):
from sfepy.discrete.common.extmods.assemble import assemble_vector
vec = nm.zeros(self.num, dtype=nm.float64)
assemble_vector(vec, self.vec_in_els, self.iels, 1, self.conn)
aux = nm.array([1, 1, 3, 2, 2], dtype=nm.float64)
self.report('assembled: %s' % vec)
self.report('expected: %s' % aux)
ok = self.compare_vectors(vec, aux,
label1='assembled',
label2='expected')
return ok
def test_assemble_vector_complex(self):
from sfepy.discrete.common.extmods.assemble import assemble_vector_complex
vec = nm.zeros(self.num, dtype=nm.complex128)
vec_in_els = self.vec_in_els.astype(nm.complex128) * (2 - 3j)
assemble_vector_complex(vec, vec_in_els, self.iels, 1, self.conn)
aux = nm.array([2-3j, 2-3j, 6-9j, 4-6j, 4-6j],
dtype=nm.complex128)
self.report('assembled: %s' % vec)
self.report('expected: %s' % aux)
ok = self.compare_vectors(vec, aux,
label1='assembled',
label2='expected')
return ok
def test_assemble_matrix(self):
from sfepy.discrete.common.extmods.assemble import assemble_matrix
mtx = sps.csr_matrix(nm.ones((self.num, self.num),
dtype=nm.float64))
mtx.data[:] = 0.0
assemble_matrix(mtx.data, mtx.indptr, mtx.indices, self.mtx_in_els,
self.iels, 1, self.conn, self.conn)
aux = nm.array([[1, 1, 1, 0, 0],
[1, 1, 1, 0, 0],
[1, 1, 3, 2, 2],
[0, 0, 2, 2, 2],
[0, 0, 2, 2, 2]], dtype=nm.float64)
self.report('assembled:\n%s' % mtx.toarray())
self.report('expected:\n%s' % aux)
ok = self.compare_vectors(mtx, aux,
label1='assembled',
label2='expected')
return ok
def test_assemble_matrix_complex(self):
from sfepy.discrete.common.extmods.assemble import assemble_matrix_complex
mtx = sps.csr_matrix(nm.ones((self.num, self.num),
dtype=nm.complex128))
mtx.data[:] = 0.0
mtx_in_els = self.mtx_in_els.astype(nm.complex128) * (2 - 3j)
assemble_matrix_complex(mtx.data, mtx.indptr, mtx.indices, mtx_in_els,
self.iels, 1, self.conn, self.conn)
aux = nm.array([[2-3j, 2-3j, 2-3j, 0+0j, 0+0j],
[2-3j, 2-3j, 2-3j, 0+0j, 0+0j],
[2-3j, 2-3j, 6-9j, 4-6j, 4-6j],
[0+0j, 0+0j, 4-6j, 4-6j, 4-6j],
[0+0j, 0+0j, 4-6j, 4-6j, 4-6j]], dtype=nm.complex128)
self.report('assembled:\n%s' % mtx.toarray())
self.report('expected:\n%s' % aux)
ok = self.compare_vectors(mtx, aux,
label1='assembled',
label2='expected')
return ok