double compute_deformed_length(node_set& nodes, EquationSystems* equation_systems) { System& X_system = equation_systems->get_system<System>(IBFEMethod::COORDS_SYSTEM_NAME); const unsigned int X_sys_num = X_system.number(); NumericVector<double>* X_vec = X_system.solution.get(); AutoPtr<NumericVector<Number> > X_serial_vec = NumericVector<Number>::build(X_vec->comm()); X_serial_vec->init(X_vec->size(), true, SERIAL); X_vec->localize(*X_serial_vec); // Get the current positions of the points. std::vector<IBTK::Point> points; points.reserve(nodes.size()); IBTK::Point p; for (typename node_set::iterator it = nodes.begin(); it != nodes.end(); ++it) { Node* node = *it; for (unsigned int d = 0; d < NDIM; ++d) { p(d) = (*X_serial_vec)(node->dof_number(X_sys_num, d, 0)); } points.push_back(p); } // Compute the length of the center line. IBTK::Point p0, p1; double l = 0.0; std::vector<IBTK::Point>::iterator it = points.begin(); p0 = *it; ++it; for (; it != points.end(); ++it) { p1 = *it; double l_segment_sq = 0.0; for (int d = 0; d < NDIM; ++d) { l_segment_sq += pow(p0(d) - p1(d), 2.0); } l += sqrt(l_segment_sq); p0 = p1; } return l; }
double compute_displaced_area(node_set& nodes, EquationSystems* equation_systems) { System& X_system = equation_systems->get_system<System>(IBFEMethod::COORDS_SYSTEM_NAME); const unsigned int X_sys_num = X_system.number(); NumericVector<double>* X_vec = X_system.solution.get(); AutoPtr<NumericVector<Number> > X_serial_vec = NumericVector<Number>::build(X_vec->comm()); X_serial_vec->init(X_vec->size(), true, SERIAL); X_vec->localize(*X_serial_vec); // Get the current positions of the points. std::vector<IBTK::Point> points; points.reserve(nodes.size()); IBTK::Point p; for (typename node_set::iterator it = nodes.begin(); it != nodes.end(); ++it) { Node* node = *it; for (unsigned int d = 0; d < NDIM; ++d) { p(d) = (*X_serial_vec)(node->dof_number(X_sys_num, d, 0)); } points.push_back(p); } // Compute the area of the polygon. IBTK::Point p0, p1; double A2 = 0.0; p0 = *points.rbegin(); for (std::vector<IBTK::Point>::iterator it = points.begin(); it != points.end(); ++it) { p1 = *it; A2 += p0(0) * p1(1) - p0(1) * p1(0); p0 = p1; } return 0.5 * abs(A2); }