Skip to content

Commit

Permalink
add test for the addfunction takin float as parameter #2139
Browse files Browse the repository at this point in the history
/cc @prudhomm
[ci skip]
  • Loading branch information
thomas-saigre committed Jul 21, 2023
1 parent a07023c commit 4315d04
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
7 changes: 6 additions & 1 deletion python/pyfeelpp/tests/test_alg.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,16 @@ def test_alg_vector(init_feelpp):
print("Test maxpy")

alpha = np.array([1,2,3])
u.setConstant(0)

u.setConstant(0)
u.add(alpha, us) # u += sum_i alpha[i] * us[i]
assert( u.sum() == 14 * u.size() )

u.setConstant(0)
for i in range(3):
u.add(alpha[i], us[i])
assert( u.sum() == 14 * u.size() )


def test_backend_vector():
feelpp.Environment.changeRepository(
Expand Down
21 changes: 18 additions & 3 deletions python/pyfeelpp/tests/test_discr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import feelpp
import sys
import numpy as np
import pytest
from feelpp.timing import tic,toc

Expand Down Expand Up @@ -120,7 +121,7 @@ def run_element(m, geo):
assert abs(l2_w) < 1e-12

def run_element_alg(m, geo):
mesh_name, dim, e_meas, e_s_1, e_s_2, e_s_bdy=geo
mesh_name, dim, e_meas, e_s_1, e_s_2, e_s_bdy = geo

m2d = feelpp.load(m, mesh_name, 0.1)

Expand Down Expand Up @@ -149,14 +150,28 @@ def run_element_alg(m, geo):
for ui in us:
ui.setConstant(1.0)

if feelpp.Environment.isMasterRank():
print("Test mDot")
r = u.mDot(us)
assert r.shape == (3,)
for i in range(3):
assert( r[i] == us[i].sum() )

if feelpp.Environment.isMasterRank():
print("Test maxpy")
alpha = np.array([1,2,3])
u.setConstant(0.0)
u.add(alpha, us)
assert( u.sum() == 6 * u.size() )

u.setConstant(0.0)
for i in range(3):
u.add(alpha[i], us[i])
assert( u.sum() == 6 * u.size() )


geo_cases=[(2, feelpp.create_rectangle),
(3, feelpp.create_box)]
(3, feelpp.create_box)]

@pytest.mark.parametrize("dim,geo", geo_cases)
def test_discr(dim,geo,init_feelpp):
Expand All @@ -183,5 +198,5 @@ def test_element(dim,geo,init_feelpp):
@pytest.mark.parametrize("dim,geo", geo_cases)
def test_element_alg(dim, geo, init_feelpp):
feelpp.Environment.changeRepository(
directory="pyfeelpp-tests/discr/test_{}d_element".format(dim))
directory = "pyfeelpp-tests/discr/test_{}d_element".format(dim))
run_element_alg( feelpp.mesh(dim=dim, realdim=dim), geo(filename="boxelement" if dim==3 else "rectelement") )

0 comments on commit 4315d04

Please sign in to comment.