Vector Vertex::normalAngleWeighted( void ) const // returns unit vertex normal using tip angle weights { Vector N(0.,0.,0.); HalfEdgeIter heBegin, he; FaceIter face; const Vector& p_i = this->position; Vector vec1, vec2; he = this->he->flip; vec1 = (he->vertex->position - p_i).unit(); face = he->face; he = heBegin = he->next->flip; do { vec2 = (he->vertex->position - p_i).unit(); N += face->normal() * atan2( cross(vec1,vec2).norm(), -dot(vec1,vec2) ); vec1 = vec2; face = he->face; he = he->next->flip; } while( he != heBegin ); return N.unit(); }
double UpscalerBase<Traits>::computeAverageVelocity(const FlowSol& flow_solution, const int flow_dir, const int pdrop_dir) const { double side1_flux = 0.0; double side2_flux = 0.0; double side1_area = 0.0; double side2_area = 0.0; int num_faces = 0; int num_bdyfaces = 0; int num_side1 = 0; int num_side2 = 0; for (CellIter c = ginterf_.cellbegin(); c != ginterf_.cellend(); ++c) { for (FaceIter f = c->facebegin(); f != c->faceend(); ++f) { ++num_faces; if (f->boundary()) { ++num_bdyfaces; int canon_bid = bcond_.getCanonicalBoundaryId(f->boundaryId()); if ((canon_bid - 1)/2 == flow_dir) { double flux = flow_solution.outflux(f); double area = f->area(); double norm_comp = f->normal()[flow_dir]; // std::cout << "bid " << f->boundaryId() << " area " << area << " n " << norm_comp << std::endl; if (canon_bid - 1 == 2*flow_dir) { ++num_side1; if (flow_dir == pdrop_dir && flux > 0.0) { #ifdef VERBOSE std::cerr << "Flow may be in wrong direction at bid: " << f->boundaryId()<<" (canonical: "<<canon_bid << ") Magnitude: " << std::fabs(flux) << std::endl; #endif // OPM_THROW(std::runtime_error, "Detected outflow at entry face: " << face); } side1_flux += flux*norm_comp; side1_area += area; } else { assert(canon_bid - 1 == 2*flow_dir + 1); ++num_side2; if (flow_dir == pdrop_dir && flux < 0.0) { #ifdef VERBOSE std::cerr << "Flow may be in wrong direction at bid: " << f->boundaryId() << " Magnitude: " << std::fabs(flux) << std::endl; #endif // OPM_THROW(std::runtime_error, "Detected inflow at exit face: " << face); } side2_flux += flux*norm_comp; side2_area += area; } } } } } // std::cout << "Faces: " << num_faces << " Boundary faces: " << num_bdyfaces // << " Side 1 faces: " << num_side1 << " Side 2 faces: " << num_side2 << std::endl; // q is the average velocity. return 0.5*(side1_flux/side1_area + side2_flux/side2_area); }