bool test_grad(int fn_idx, Shapeset *shapeset) { _F_ ShapeFunction pss_u(shapeset); pss_u.set_active_shape(fn_idx); printf("."); fflush(stdout); // prevent caching of output (to see that it did not freeze) double3 vol_val = { 0.0, 0.0, 0.0 }; double3 surf_val = { 0.0, 0.0, 0.0 }; hcurl_int_vol(&pss_u, vol_val); hcurl_int_surf(&pss_u, surf_val); if (fabs(vol_val[0] - surf_val[0]) > EPS || fabs(vol_val[1] - surf_val[1]) > EPS || fabs(vol_val[2] - surf_val[2]) > EPS) { printf("\n"); warning("Gradient values for fn #%d do not match", fn_idx); return false; } return true; }
bool test_lin_indep(Shapeset *shapeset) { _F_ printf("I. linear independency\n"); UMFPackMatrix mat; UMFPackVector rhs; UMFPackLinearSolver solver(&mat, &rhs); ShapeFunction pss_u(shapeset), pss_v(shapeset); int n = Hex::NUM_EDGES * shapeset->get_num_edge_fns(H3D_MAX_ELEMENT_ORDER) + Hex::NUM_FACES * shapeset->get_num_face_fns(order2_t(H3D_MAX_ELEMENT_ORDER, H3D_MAX_ELEMENT_ORDER)) + shapeset->get_num_bubble_fns(order3_t(H3D_MAX_ELEMENT_ORDER, H3D_MAX_ELEMENT_ORDER, H3D_MAX_ELEMENT_ORDER)); printf("number of functions = %d\n", n); int *fn_idx = new int[n]; int m = 0; // edge fns for (int i = 0; i < Hex::NUM_EDGES; i++) { int order = H3D_MAX_ELEMENT_ORDER; int *edge_idx = shapeset->get_edge_indices(i, 0, order); for (int j = 0; j < shapeset->get_num_edge_fns(order); j++, m++) fn_idx[m] = edge_idx[j]; } // face fns for (int i = 0; i < Hex::NUM_FACES; i++) { order2_t order(H3D_MAX_ELEMENT_ORDER, H3D_MAX_ELEMENT_ORDER); int *face_idx = shapeset->get_face_indices(i, 0, order); for (int j = 0; j < shapeset->get_num_face_fns(order); j++, m++) fn_idx[m] = face_idx[j]; } // bubble order3_t order(H3D_MAX_ELEMENT_ORDER, H3D_MAX_ELEMENT_ORDER, H3D_MAX_ELEMENT_ORDER); int *bubble_idx = shapeset->get_bubble_indices(order); for (int j = 0; j < shapeset->get_num_bubble_fns(order); j++, m++) fn_idx[m] = bubble_idx[j]; // precalc structure mat.prealloc(n); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) mat.pre_add_ij(i, j); mat.alloc(); rhs.alloc(n); printf("assembling matrix "); for (int i = 0; i < n; i++) { pss_u.set_active_shape(fn_idx[i]); printf("."); fflush(stdout); // prevent caching of output (to see that it did not freeze) for (int j = 0; j < n; j++) { pss_v.set_active_shape(fn_idx[j]); double value = l2_product(&pss_u, &pss_v); mat.add(i, j, value); } } printf("\n"); for (int i = 0; i < n; i++) rhs.add(i, 0.0); printf("solving matrix\n"); // solve the system if (solver.solve()) { double *sln = solver.get_solution(); bool indep = true; for (int i = 1; i < n + 1; i++) { if (sln[i] >= EPS) { indep = false; break; } } if (indep) printf("ok\n"); else printf("Shape functions are not linearly independent\n"); } else { printf("Shape functions are not linearly independent\n"); } delete[] fn_idx; return true; }