// Custom function to calculate drag coefficient. double integrate_over_wall(MeshFunction* meshfn, int marker) { Quad2D* quad = &g_quad_2d_std; meshfn->set_quad_2d(quad); double integral = 0.0; Element* e; Mesh* mesh = meshfn->get_mesh(); for_all_active_elements(e, mesh) { for(int edge = 0; edge < e->nvert; edge++) { if ((e->en[edge]->bnd) && (e->en[edge]->marker == marker)) { update_limit_table(e->get_mode()); RefMap* ru = meshfn->get_refmap(); meshfn->set_active_element(e); int eo = quad->get_edge_points(edge); meshfn->set_quad_order(eo, H2D_FN_VAL); scalar *uval = meshfn->get_fn_values(); double3* pt = quad->get_points(eo); double3* tan = ru->get_tangent(edge); for (int i = 0; i < quad->get_num_points(eo); i++) integral += pt[i][2] * uval[i] * tan[i][2]; } } } return integral * 0.5; }
//------------------------------------------------------------------------------ // Compute marked boundary length // double CalculateBoundaryLength(Mesh* mesh, int bdryMarker) { // Variables declaration. Element* e; double length = 0; RefMap rm; rm.set_quad_2d(&g_quad_2d_std); Quad2D * quad = rm.get_quad_2d(); int points_location; double3* points; int np; double3* tangents; // Loop through all boundary faces of all active elements. for_all_active_elements(e, mesh) { for(int edge = 0; edge < e->nvert; ++edge) { if ((e->en[edge]->bnd) && (e->en[edge]->marker == bdryMarker)) { rm.set_active_element(e); points_location = quad->get_edge_points(edge); points = quad->get_points(points_location); np = quad->get_num_points(points_location); tangents = rm.get_tangent(edge, points_location); for(int i = 0; i < np; i++) { // Weights sum up to two on every edge, therefore the division by two must be present. length += 0.5 * points[i][2] * tangents[i][2]; } } } } return length; } // end of CalculateBoundaryLength()