Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
out_vec.restore_array_read()
weights_vec.restore_array_read()
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.))
out_vec.restore_array_read()
weights_vec.restore_array_read()
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)
qf_mass.add_output("v", 1, libceed.EVAL_INTERP)
# Operators
op_setup = ceed.Operator(qf_setup)
op_setup.set_field("weights", rxi, bx, libceed.VECTOR_NONE)
op_setup.set_field("dx", rx, bx, libceed.VECTOR_ACTIVE)
op_setup.set_field("rho", rui, libceed.BASIS_COLLOCATED,
libceed.VECTOR_ACTIVE)
op_mass = ceed.Operator(qf_mass)
op_mass.set_field("rho", rui, libceed.BASIS_COLLOCATED, qdata)
op_mass.set_field("u", ru, bu, libceed.VECTOR_ACTIVE)
op_mass.set_field("v", ru, bu, libceed.VECTOR_ACTIVE)
# Setup
op_setup.apply(x, qdata)
# Apply mass matrix
u.set_value(0)
op_mass.apply(u, v)
# QFunctions
qf_setup_hex = ceed.QFunction(1, qfs.setup_mass_2d,
os.path.join(file_dir, "test-qfunctions.h:setup_mass_2d"))
qf_setup_hex.add_input("weights", 1, libceed.EVAL_WEIGHT)
qf_setup_hex.add_input("dx", dim*dim, libceed.EVAL_GRAD)
qf_setup_hex.add_output("rho", 1, libceed.EVAL_NONE)
qf_mass_hex = ceed.QFunction(1, qfs.apply_mass,
os.path.join(file_dir, "test-qfunctions.h:apply_mass"))
qf_mass_hex.add_input("rho", 1, libceed.EVAL_NONE)
qf_mass_hex.add_input("u", 1, libceed.EVAL_INTERP)
qf_mass_hex.add_output("v", 1, libceed.EVAL_INTERP)
# Operators
op_setup_hex = ceed.Operator(qf_setup_tet)
op_setup_hex.set_field("weights", rxi_hex, bx_hex, libceed.VECTOR_NONE)
op_setup_hex.set_field("dx", rx_hex, bx_hex, libceed.VECTOR_ACTIVE)
op_setup_hex.set_field("rho", rui_hex, libceed.BASIS_COLLOCATED,
qdata_hex)
op_mass_hex = ceed.Operator(qf_mass_hex)
op_mass_hex.set_field("rho", rui_hex, libceed.BASIS_COLLOCATED, qdata_hex)
op_mass_hex.set_field("u", ru_hex, bu_hex, libceed.VECTOR_ACTIVE)
op_mass_hex.set_field("v", ru_hex, bu_hex, libceed.VECTOR_ACTIVE)
## ------------------------- Composite Operators -------------------------
# Setup
op_setup = ceed.CompositeOperator()
op_setup.add_sub(op_setup_tet)
op_setup.add_sub(op_setup_hex)