/// @file /// Test assembly of mass and Poisson operator QFunction /// \test Test assembly of mass and Poisson operator QFunction #include #include #include #include "t532-operator.h" int main(int argc, char **argv) { Ceed ceed; CeedElemRestriction elem_restr_x, elem_restr_u, elem_restr_qd_mass_i, elem_restr_qd_diff_i, elem_restr_lin_i; CeedBasis basis_x, basis_u; CeedQFunction qf_setup_mass, qf_setup_diff, qf_apply, qf_apply_lin; CeedOperator op_setup_mass, op_setup_diff, op_apply, op_apply_lin; CeedVector q_data_mass, q_data_diff, X, A, u, v; CeedInt num_elem = 6, P = 3, Q = 4, dim = 2; CeedInt nx = 3, ny = 2; CeedInt num_dofs = (nx*2+1)*(ny*2+1), num_qpts = num_elem*Q*Q; CeedInt ind_x[num_elem*P*P]; CeedScalar x[dim*num_dofs]; CeedInit(argv[1], &ceed); // DoF Coordinates for (CeedInt i=0; i 100.*CEED_EPSILON) // LCOV_EXCL_START printf("Error: True operator computed area = %f != 1.0\n", area); // LCOV_EXCL_STOP // Assemble QFunction CeedOperatorSetQFunctionAssemblyReuse(op_apply, true); CeedOperatorLinearAssembleQFunction(op_apply, &A, &elem_restr_lin_i, CEED_REQUEST_IMMEDIATE); // Second call will be no-op since SetQFunctionUpdated was not called CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(op_apply, false); CeedOperatorLinearAssembleQFunction(op_apply, &A, &elem_restr_lin_i, CEED_REQUEST_IMMEDIATE); // QFunction - apply assembled CeedQFunctionCreateInterior(ceed, 1, apply_lin, apply_lin_loc, &qf_apply_lin); CeedQFunctionAddInput(qf_apply_lin, "du", dim, CEED_EVAL_GRAD); CeedQFunctionAddInput(qf_apply_lin, "qdata", (dim+1)*(dim+1), CEED_EVAL_NONE); CeedQFunctionAddInput(qf_apply_lin, "u", 1, CEED_EVAL_INTERP); CeedQFunctionAddOutput(qf_apply_lin, "v", 1, CEED_EVAL_INTERP); CeedQFunctionAddOutput(qf_apply_lin, "dv", dim, CEED_EVAL_GRAD); // Operator - apply assembled CeedOperatorCreate(ceed, qf_apply_lin, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_apply_lin); CeedOperatorSetField(op_apply_lin, "du", elem_restr_u, basis_u, CEED_VECTOR_ACTIVE); CeedOperatorSetField(op_apply_lin, "qdata", elem_restr_lin_i, CEED_BASIS_COLLOCATED, A); CeedOperatorSetField(op_apply_lin, "u", elem_restr_u, basis_u, CEED_VECTOR_ACTIVE); CeedOperatorSetField(op_apply_lin, "v", elem_restr_u, basis_u, CEED_VECTOR_ACTIVE); CeedOperatorSetField(op_apply_lin, "dv", elem_restr_u, basis_u, CEED_VECTOR_ACTIVE); // Apply assembled QFunction operator CeedVectorSetValue(v, 0.0); CeedOperatorApply(op_apply_lin, u, v, CEED_REQUEST_IMMEDIATE); // Check output area = 0.0; CeedVectorGetArrayRead(v, CEED_MEM_HOST, &vv); for (CeedInt i=0; i 100.*CEED_EPSILON) // LCOV_EXCL_START printf("Error: Assembled operator computed area = %f != 1.0\n", area); // LCOV_EXCL_STOP // Cleanup CeedQFunctionDestroy(&qf_setup_mass); CeedQFunctionDestroy(&qf_setup_diff); CeedQFunctionDestroy(&qf_apply); CeedQFunctionDestroy(&qf_apply_lin); CeedOperatorDestroy(&op_setup_mass); CeedOperatorDestroy(&op_setup_diff); CeedOperatorDestroy(&op_apply); CeedOperatorDestroy(&op_apply_lin); CeedElemRestrictionDestroy(&elem_restr_u); CeedElemRestrictionDestroy(&elem_restr_x); CeedElemRestrictionDestroy(&elem_restr_qd_mass_i); CeedElemRestrictionDestroy(&elem_restr_qd_diff_i); CeedElemRestrictionDestroy(&elem_restr_lin_i); CeedBasisDestroy(&basis_u); CeedBasisDestroy(&basis_x); CeedVectorDestroy(&X); CeedVectorDestroy(&A); CeedVectorDestroy(&q_data_mass); CeedVectorDestroy(&q_data_diff); CeedVectorDestroy(&u); CeedVectorDestroy(&v); CeedDestroy(&ceed); return 0; }