本文整理汇总了C++中MESH::has_neighbor方法的典型用法代码示例。如果您正苦于以下问题:C++ MESH::has_neighbor方法的具体用法?C++ MESH::has_neighbor怎么用?C++ MESH::has_neighbor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MESH
的用法示例。
在下文中一共展示了MESH::has_neighbor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hyperbolic_step
/*
* implementation of euler approximation of the shallow water PDE
* @pre: a valid Mesh class instance @mesh
* @post: all triangle in the mesh class have new value() = old value - dt/area() * total flux,
where total flux is calculated by all three edges of the triangle
@return: return total time t+dt
*/
double hyperbolic_step(MESH& mesh, FLUX& f, double t, double dt) {
// Step the finite volume model in time by dt.
// Implement Equation 7 from your pseudocode here.
for (auto it = mesh.tri_begin(); it!=mesh.tri_end() ; ++it)
{
// value function will return the flux
QVar total_flux=QVar(0,0,0);
QVar qm = QVar(0,0,0);
// iterate through 3 edges of a triangle
auto edgetemp = (*it).edge1();
for (int num = 0; num < 3; num++)
{
if (num ==0)
edgetemp= (*it).edge1();
else if (num==1)
edgetemp = (*it).edge2();
else
edgetemp = (*it).edge3();
if ( mesh.has_neighbor(edgetemp.index()) ) // it has a common triangle
{
auto nx = ((*it).norm_vector(edgetemp)).x;
auto ny = ((*it).norm_vector(edgetemp)).y;
// find the neighbour of a common edge
for (auto i = mesh.tri_edge_begin(edgetemp.index()); i != mesh.tri_edge_end(edgetemp.index()); ++i){
if (!(*i==*it))
qm = (*i).value();
}
// calculat the total flux
total_flux += f(nx, ny, dt, (*it).value(), qm);
}
else{
// when it doesnt have a neighbour shared with this edge
auto nx = ((*it).norm_vector(edgetemp)).x;
auto ny = ((*it).norm_vector(edgetemp)).y;
qm = QVar((*it).value().h, 0, 0 ); // approximation
total_flux += f(nx, ny, dt, (*it).value(), qm);
}
}
(*it).value() += total_flux * (- dt / (*it).area());
}
return t + dt;
}