Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
nelem = 12
dim = 2
p = 6
q = 4
nx, ny = 3, 2
ndofs = (nx*2+1)*(ny*2+1)
nqpts = nelem*q
# Vectors
x = ceed.Vector(dim*ndofs)
x_array = np.zeros(dim*ndofs)
for i in range(ndofs):
x_array[i] = (1. / (nx*2)) * (i % (nx*2+1))
x_array[i+ndofs] = (1. / (ny*2)) * (i / (nx*2+1))
x.set_array(x_array, cmode=libceed.USE_POINTER)
qdata = ceed.Vector(nqpts)
u = ceed.Vector(ndofs)
v = ceed.Vector(ndofs)
# Restrictions
indx = np.zeros(nelem*p, dtype="int32")
for i in range(nelem//2):
col = i % nx;
row = i // nx;
offset = col*2 + row*(nx*2+1)*2
indx[i*2*p+ 0] = 2 + offset
indx[i*2*p+ 1] = 9 + offset
indx[i*2*p+ 2] = 16 + offset
indx[i*2*p+ 3] = 1 + offset
def test_208(ceed_resource, capsys):
ceed = libceed.Ceed(ceed_resource)
ne = 8
blksize = 5
x = ceed.Vector(ne+1)
a = np.arange(10, 10 + ne+1, dtype="float64")
x.set_array(a, cmode=libceed.USE_POINTER)
ind = np.zeros(2*ne, dtype="int32")
for i in range(ne):
ind[2*i+0] = i
ind[2*i+1] = i+1
r = ceed.BlockedElemRestriction(ne, 2, blksize, ne+1, 1, ind,
cmode=libceed.USE_POINTER)
y = ceed.Vector(blksize*2)
y.set_value(0)
r.apply_block(1, x, y)
print(y)
x.set_value(0)
r.T.apply_block(1, y, x)
print(x)
stdout, stderr = capsys.readouterr()
with open(os.path.abspath("./output/test_208.out")) as output_file:
true_output = output_file.read()
q = 8
w_array = np.zeros(q, dtype="float64")
u_array = np.zeros(q, dtype="float64")
v_true = np.zeros(q, dtype="float64")
for i in range(q):
x = 2.*i/(q-1) - 1
w_array[i] = 1 - x*x
u_array[i] = 2 + 3*x + 5*x*x
v_true[i] = w_array[i] * u_array[i]
dx = ceed.Vector(q)
dx.set_value(1)
w = ceed.Vector(q)
w.set_array(w_array, cmode=libceed.USE_POINTER)
u = ceed.Vector(q)
u.set_array(u_array, cmode=libceed.USE_POINTER)
v = ceed.Vector(q)
v.set_value(0)
qdata = ceed.Vector(q)
qdata.set_value(0)
inputs = [ dx, w ]
outputs = [ qdata ]
qf_setup.apply(q, inputs, outputs)
inputs = [ qdata, u ]
outputs = [ v ]
qf_mass.apply(q, inputs, outputs)
v_array = v.get_array_read()
xr = np.array([0., 0.5, 1., 0., 0.5, 0., 0., 0., 0., 0.5, 0.5, 1.], dtype="float64")
in_array = np.empty(P, dtype="float64")
qref = np.empty(dim*Q, dtype="float64")
qweight = np.empty(Q, dtype="float64")
interp, grad = bm.buildmats(qref, qweight)
b = ceed.BasisH1(libceed.TRIANGLE, 1, P, Q, interp, grad, qref, qweight)
# Interpolate function to quadrature points
for i in range(P):
in_array[i] = feval(xr[0*P+i], xr[1*P+i])
in_vec = ceed.Vector(P)
in_vec.set_array(in_array, cmode=libceed.USE_POINTER)
out_vec = ceed.Vector(Q)
out_vec.set_value(0)
weights_vec = ceed.Vector(Q)
weights_vec.set_value(0)
b.apply(1, libceed.EVAL_INTERP, in_vec, out_vec)
b.apply(1, libceed.EVAL_WEIGHT, libceed.VECTOR_NONE, weights_vec)
# Check values at quadrature points
out_array = out_vec.get_array_read()
weights_array = weights_vec.get_array_read()
sum = 0
for i in range(Q):
sum += out_array[i]*weights_array[i]
if math.fabs(sum - 17./24.) > 1E-10:
print("%f != %f"%(sum, 17./24.))
def test_104(ceed_resource):
ceed = libceed.Ceed(ceed_resource)
n = 10
x = ceed.Vector(n)
a = np.zeros(n, dtype="float64")
x.set_array(a, cmode=libceed.USE_POINTER)
b = x.get_array()
b[3] = -3.14;
x.restore_array()
assert a[3] == -3.14
def test_500(ceed_resource):
ceed = libceed.Ceed(ceed_resource)
nelem = 15
p = 5
q = 8
nx = nelem + 1
nu = nelem*(p-1) + 1
# Vectors
x = ceed.Vector(nx)
x_array = np.zeros(nx)
for i in range(nx):
x_array[i] = i / (nx - 1.0)
x.set_array(x_array, cmode=libceed.USE_POINTER)
qdata = ceed.Vector(nelem*q)
u = ceed.Vector(nu)
v = ceed.Vector(nu)
# Restrictions
indx = np.zeros(nx*2, dtype="int32")
for i in range(nx):
indx[2*i+0] = i
indx[2*i+1] = i+1
rx = ceed.ElemRestriction(nelem, 2, nx, 1, indx, cmode=libceed.USE_POINTER)
rxi = ceed.IdentityElemRestriction(nelem, 2, nelem*2, 1)
indu = np.zeros(nelem*p, dtype="int32")
for i in range(nelem):
for j in range(p):
def test_100(ceed_resource):
ceed = libceed.Ceed(ceed_resource)
n = 10
x = ceed.Vector(n)
a = np.arange(10, 10 + n, dtype="float64")
x.set_array(a, cmode=libceed.USE_POINTER)
b = x.get_array_read()
for i in range(n):
assert b[i] == 10 + i
x.restore_array_read()
xr = np.array([0., 0.5, 1., 0., 0.5, 0., 0., 0., 0., 0.5, 0.5, 1.], dtype="float64")
in_array = np.empty(P, dtype="float64")
qref = np.empty(dim*Q, dtype="float64")
qweight = np.empty(Q, dtype="float64")
interp, grad = bm.buildmats(qref, qweight)
b = ceed.BasisH1(libceed.TRIANGLE, 1, P, Q, interp, grad, qref, qweight)
# Interpolate function to quadrature points
for i in range(P):
in_array[i] = feval(xr[0*P+i], xr[1*P+i])
in_vec = ceed.Vector(P)
in_vec.set_array(in_array, cmode=libceed.USE_POINTER)
out_vec = ceed.Vector(Q)
out_vec.set_value(0)
weights_vec = ceed.Vector(Q)
weights_vec.set_value(0)
b.apply(1, libceed.EVAL_INTERP, in_vec, out_vec)
b.apply(1, libceed.EVAL_WEIGHT, libceed.VECTOR_NONE, weights_vec)
# Check values at quadrature points
out_array = out_vec.get_array_read()
weights_array = weights_vec.get_array_read()
sum = 0
for i in range(Q):
sum += out_array[i]*weights_array[i]
assert math.fabs(sum - 17./24.) < 1E-10
xq = np.array([0.2, 0.6, 1./3., 0.2, 0.2, 0.2, 1./3., 0.6], dtype="float64")
xr = np.array([0., 0.5, 1., 0., 0.5, 0., 0., 0., 0., 0.5, 0.5, 1.], dtype="float64")
in_array = np.empty(P, dtype="float64")
qref = np.empty(dim*Q, dtype="float64")
qweight = np.empty(Q, dtype="float64")
interp, grad = bm.buildmats(qref, qweight)
b = ceed.BasisH1(libceed.TRIANGLE, 1, P, Q, interp, grad, qref, qweight)
# Interpolate function to quadrature points
for i in range(P):
in_array[i] = feval(xr[0*P+i], xr[1*P+i])
in_vec = ceed.Vector(P)
in_vec.set_array(in_array, cmode=libceed.USE_POINTER)
out_vec = ceed.Vector(Q)
out_vec.set_value(0)
b.apply(1, libceed.EVAL_INTERP, in_vec, out_vec)
# Check values at quadrature points
out_array = out_vec.get_array_read()
for i in range(Q):
value = feval(xq[0*Q+i], xq[1*Q+i])
if math.fabs(out_array[i] - value) > 1E-10:
# LCOV_EXCL_START
printf("[%d] %f != %f"%(i, out[i], value))
# LCOV_EXCL_STOP
out_vec.restore_array_read()