Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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):
indu[p*i+j] = i*(p-1) + j
ru = ceed.ElemRestriction(nelem, p, nu, 1, indu, cmode=libceed.USE_POINTER)
rui = ceed.IdentityElemRestriction(nelem, q, q*nelem, 1)
# Bases
bx = ceed.BasisTensorH1Lagrange(1, 1, 2, q, libceed.GAUSS)
bu = ceed.BasisTensorH1Lagrange(1, 1, p, q, libceed.GAUSS)
# QFunctions
file_dir = os.path.dirname(os.path.abspath(__file__))
qfs = load_qfs_so()
qf_setup = ceed.QFunction(1, qfs.setup_mass,
os.path.join(file_dir, "test-qfunctions.h:setup_mass"))
qf_setup.add_input("weights", 1, libceed.EVAL_WEIGHT)
qf_setup.add_input("dx", 1, libceed.EVAL_GRAD)
qf_setup.add_output("rho", 1, libceed.EVAL_NONE)
qf_mass = ceed.QFunction(1, qfs.apply_mass,
os.path.join(file_dir, "test-qfunctions.h:apply_mass"))
qf_mass.add_input("rho", 1, libceed.EVAL_NONE)
qf_mass.add_input("u", 1, libceed.EVAL_INTERP)
xq = Xq.get_array_read()
for i in range(Qdim):
xx = np.empty(dim, dtype="float64")
for d in range(dim):
xx[d] = xq[d*Qdim + i]
uq[i] = eval(dim, xx)
Xq.restore_array_read()
Uq.set_array(uq, cmode=libceed.USE_POINTER)
# This operation is the identity because the quadrature is collocated
bul.T.apply(1, libceed.EVAL_INTERP, Uq, U)
bxg = ceed.BasisTensorH1Lagrange(dim, dim, 2, Q, libceed.GAUSS)
bug = ceed.BasisTensorH1Lagrange(dim, 1, Q, Q, libceed.GAUSS)
bxg.apply(1, libceed.EVAL_INTERP, X, Xq)
bug.apply(1, libceed.EVAL_INTERP, U, Uq)
xq = Xq.get_array_read()
u = Uq.get_array_read()
for i in range(Qdim):
xx = np.empty(dim, dtype="float64")
for d in range(dim):
xx[d] = xq[d*Qdim + i]
fx = eval(dim, xx)
assert math.fabs(u[i] - fx) < 1E-4
Xq.restore_array_read()
Uq.restore_array_read()
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):
indu[p*i+j] = i*(p-1) + j
ru = ceed.ElemRestriction(nelem, p, nu, 1, indu, cmode=libceed.USE_POINTER)
rui = ceed.IdentityElemRestriction(nelem, q, q*nelem, 1)
# Bases
bx = ceed.BasisTensorH1Lagrange(1, 1, 2, q, libceed.GAUSS)
bu = ceed.BasisTensorH1Lagrange(1, 1, p, q, libceed.GAUSS)
# QFunctions
file_dir = os.path.dirname(os.path.abspath(__file__))
qfs = load_qfs_so()
qf_setup = ceed.QFunction(1, qfs.setup_mass,
os.path.join(file_dir, "test-qfunctions.h:setup_mass"))
qf_setup.add_input("weights", 1, libceed.EVAL_WEIGHT)
qf_setup.add_input("dx", 1, libceed.EVAL_GRAD)
qf_setup.add_output("rho", 1, libceed.EVAL_NONE)
qf_mass = ceed.QFunction(1, qfs.apply_mass,
os.path.join(file_dir, "test-qfunctions.h:apply_mass"))
qf_mass.add_input("rho", 1, libceed.EVAL_NONE)
qf_mass.add_input("u", 1, libceed.EVAL_INTERP)
def test_300(ceed_resource, capsys):
ceed = libceed.Ceed(ceed_resource)
b = ceed.BasisTensorH1Lagrange(1, 1, 4, 4, libceed.GAUSS_LOBATTO)
print(b)
del b
b = ceed.BasisTensorH1Lagrange(1, 1, 4, 4, libceed.GAUSS)
print(b)
del b
stdout, stderr = capsys.readouterr()
with open(os.path.abspath("./output/test_300.out")) as output_file:
true_output = output_file.read()
assert stdout == true_output