本文整理汇总了C++中MESH类的典型用法代码示例。如果您正苦于以下问题:C++ MESH类的具体用法?C++ MESH怎么用?C++ MESH使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MESH类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: probe
std::pair<double,double> probe( const MESH& mesh, const DISP& displacement,
const PRESS& pressure )
{
// pick an element
const std::size_t numElements = std::distance( mesh.elementsBegin(), mesh.elementsEnd() );
const std::size_t elemNum = (numElements +
static_cast<std::size_t>(std::sqrt(numElements)) ) / 2;
// geometry
const typename MESH::Element* geomEp = mesh.elementPtr( elemNum );
const typename base::Vector<MESH::Element::dim>::Type xi =
base::constantVector<MESH::Element::dim>( 0. );
const typename base::Geometry<typename MESH::Element>::result_type x =
base::Geometry<typename MESH::Element>()( geomEp, xi );
// displacement
const typename DISP::Element* dispEp = displacement.elementPtr( elemNum );
const typename base::Vector<DISP::DegreeOfFreedom::size>::Type uh =
base::post::evaluateField( geomEp, dispEp, xi );
// pressure
const typename PRESS::Element* pressEp = pressure.elementPtr( elemNum );
const typename base::Vector<PRESS::DegreeOfFreedom::size>::Type ph =
base::post::evaluateField( geomEp, pressEp, xi );
return std::make_pair( uh[1], ph[0] );
}
示例2: operator
void operator()(MESH& m, double t) {
(void) t;
double distance;
double r;
Point directionVector;
Point pos;
Point c;
Point R;
Point velocity;
Node node1;
Node node2;
for(auto it=m.node_begin(); it != m.node_end(); ++ it)
{
node1 = (*it);
c = node1.position();
r = 0.0;
// iterate through connected edges and set r equal to
// the length of the shortest connected edge
for(auto edge_it = node1.edge_begin(); edge_it != node1.edge_end(); ++edge_it)
{
if (r == 0.0 || (*edge_it).length() < r)
r = (*edge_it).length();
}
// now iterate through all of the other nodes and see if any of
// them are within distance r
for(auto it2=m.node_begin(); it2 != m.node_end(); ++it2)
{
node2 = (*it2);
pos = node2.position();
distance = norm(pos-c);
if (distance < r && node1 != node2)
{
// SET POSITION TO NEAREST POINT ON SURFACE OF SPHERE
// get the direction vector from the center to our node
directionVector = pos-c;
//normalize that vector
directionVector = directionVector/norm(directionVector);
// set pos to the direction vector time the sphere's radius
// which should get us to the point on the sphere closest
// to the node's current position
pos = c+directionVector*(r);
node2.set_position(pos);
// SET THE COMPONENT OF VELOCITY THAT IS NORMAL TO THE
// SPHERE'S SURFACE TO ZERO
R = (pos-c)/norm(pos-c);
velocity = node2.value().velocity;
node2.value().velocity = velocity - inner_prod(velocity,R)*R;
}
}
}
}
示例3: get_center
Point get_center(MESH& m)
{
Point center = Point(0,0,0);
for(auto it=m.node_begin(); it != m.node_end(); ++ it)
center += (*it).position();
center /= m.num_nodes();
return center;
}
示例4: hyperbolic_step
double hyperbolic_step(MESH& m, FLUX& f, double t, double dt, Point ball_loc, int water_tris) {
for (auto tri_it = m.triangle_begin(); (*tri_it).index() != water_tris; ++tri_it) {
QVar sum = QVar(0,0,0);
/* Defines the force of the floating objects by checking its submerged
* cross section of the ball intersects with the centers of adjacent triangles
*/
floatObj obj = floatObj();
if (norm((*tri_it).center()-Point(ball_loc.x, ball_loc.y, 0)) < ball_loc.z)
obj = floatObj(total_mass*grav, M_PI*ball_loc.z*ball_loc.z, density);
Point norm_vec = (*tri_it).normal((*tri_it).node1(), (*tri_it).node2());
// Calcuate flux using adjacent triangle's Q
if ((*tri_it).adj_triangle((*tri_it).node1(), (*tri_it).node2()).is_valid())
sum += f(norm_vec.x, norm_vec.y, dt, (*tri_it).value().q_bar,
(*tri_it).adj_triangle((*tri_it).node1(), (*tri_it).node2()).value().q_bar, obj);
// Boundary conditions
else
sum += f(norm_vec.x, norm_vec.y, dt, (*tri_it).value().q_bar,
QVar((*tri_it).value().q_bar.h, 0, 0), obj);
norm_vec = (*tri_it).normal((*tri_it).node2(), (*tri_it).node3());
// Calcuate flux using adjacent triangle's Q
if ((*tri_it).adj_triangle((*tri_it).node2(), (*tri_it).node3()).is_valid())
sum += f(norm_vec.x, norm_vec.y, dt, (*tri_it).value().q_bar,
(*tri_it).adj_triangle((*tri_it).node2(), (*tri_it).node3()).value().q_bar, obj);
// Boundary conditions
else
sum += f(norm_vec.x, norm_vec.y, dt, (*tri_it).value().q_bar,
QVar((*tri_it).value().q_bar.h, 0, 0), obj);
norm_vec = (*tri_it).normal((*tri_it).node3(), (*tri_it).node1());
// Calcuate flux using adjacent triangle's Q
if ((*tri_it).adj_triangle((*tri_it).node3(), (*tri_it).node1()).is_valid())
sum += f(norm_vec.x, norm_vec.y, dt, (*tri_it).value().q_bar,
(*tri_it).adj_triangle((*tri_it).node3(), (*tri_it).node1()).value().q_bar, obj);
// Boundary conditions
else
sum += f(norm_vec.x, norm_vec.y, dt, (*tri_it).value().q_bar,
QVar((*tri_it).value().q_bar.h, 0, 0), obj);
(*tri_it).value().q_bar2 = ((*tri_it).value().S * dt/(*tri_it).area()) + (*tri_it).value().q_bar -
(sum * dt/(*tri_it).area());
}
/* In order to use original (as opposed to update) q_bar values in the equation above, we have to update
* q_bar values for all triangles after the q_bar values have been calculated.
* Updates the Source term
*/
for (auto tri_it = m.triangle_begin(); (*tri_it).index() != water_tris; ++tri_it){
(*tri_it).value().S = (*tri_it).value().S/(*tri_it).value().q_bar.h*(*tri_it).value().q_bar2.h;
(*tri_it).value().q_bar = (*tri_it).value().q_bar2;
}
return t + dt;
}
示例5: get_volume
double get_volume(MESH& m) {
double volume = 0.0;
for(auto it = m.triangle_begin(); it != m.triangle_end(); ++it){
auto tri = (*it);
Point normal = get_normal_surface(tri);
double area = tri.area();
volume += normal.z * area * (tri.node(0).position().z + tri.node(1).position().z + tri.node(2).position().z) / 3.0;
}
return volume;
}
示例6: hyperbolic_step
double hyperbolic_step(MESH& m, FLUX& f, double t, double dt) {
// HW4B: YOUR CODE HERE
// Step the finite volume model in time by dt.
// Pseudocode:
// Compute all fluxes. (before updating any triangle Q_bars)
// For each triangle, update Q_bar using the fluxes as in Equation 8.
// NOTE: Much like symp_euler_step, this may require TWO for-loops
// Implement Equation 7 from your pseudocode here.
for(auto i = m.edge_begin(); i != m.edge_end(); ++i){
if ((*i).triangle1().index() != (unsigned) -1 && (*i).triangle2().index() != (unsigned) -1 ){
MeshType::Triangle trik = (*i).triangle1();
MeshType::Triangle trim = (*i).triangle2();
unsigned int edge_k = 0;
unsigned int edge_m = 0;
//which edge (*i) is in trik and trim
while(trik.node(edge_k).index()== (*i).node1().index()
|| trik.node(edge_k).index()== (*i).node2().index() )
++edge_k;
while(trim.node(edge_m).index()== (*i).node1().index()
|| trim.node(edge_m).index()== (*i).node2().index() )
++edge_m;
QVar flux = f(trik.normal(edge_k).x, trik.normal(edge_k).y, dt, trik.value().Q, trim.value().Q);
trik.value().F[edge_k] = flux;
trim.value().F[edge_m] = -flux;
}
else{
MeshType::Triangle trik;
if ((*i).triangle1().index() != (unsigned) -1)
trik = (*i).triangle1();
else
trik = (*i).triangle2();
unsigned int edge_k = 0;
while(trik.node(edge_k).index()== (*i).node1().index()
|| trik.node(edge_k).index()== (*i).node2().index() )
++edge_k;
QVar flux = f(trik.normal(edge_k).x, trik.normal(edge_k).y, dt, trik.value().Q, QVar(trik.value().Q.h, 0, 0));
trik.value().F[edge_k] = flux;
}
}
for(auto i = m.triangle_begin(); i != m.triangle_end(); ++i){
QVar sum = QVar(0, 0, 0);
for (int j = 0; j < 3; ++j){
sum += (*i).value().F[j];
}
(*i).value().Q = (*i).value().Q-dt/(*i).area()*sum;
}
return t + dt;
};
示例7: operator
Point operator()(MESH& m, NODE n, double t) {
(void) t;
Point pressure_force = Point(0.0, 0.0, 0.0);
for(auto it=m.adj_triangle_begin(n.uid()); it != m.adj_triangle_end(n.uid()); ++ it) {
auto tri = (*it);
Point normal = get_normal_surface(tri);
double area = tri.area();
pressure_force += normal * area * pressure;
}
return pressure_force;
}
示例8: post_process
void post_process(MESH& m) {
// HW4B: Post-processing step
// Translate the triangle-averaged values to node-averaged values
// Implement Equation 9 from your pseudocode here
for (auto it = m.node_begin(); it != m.node_end(); ++it){
double sumarea=0;
QVar sumQ = QVar(0, 0, 0);
for(auto j = m.triangle_begin(*it); j != m.triangle_end(*it); ++j){
sumarea += (*j).area();
sumQ += (*j).value().Q * (*j).area();
}
(*it).value().Q = sumQ/sumarea;
}
}
示例9: post_process
Point post_process(MESH& m, FORCE force, CONSTRAINT& c, double t, double dt, uint water_nodes) {
static double ball_bottom = std::numeric_limits<double>::max();
double water_dis = std::numeric_limits<double>::max();
double dh = 0;
static double submerged_height = 0;
Point bottom_loc;
Point water_loc;
for (auto n_it = m.node_begin(); n_it != m.node_end(); ++n_it) {
// handles the shallow water
if ((*n_it).index() < water_nodes) {
double sum_area = 0;
QVar value = QVar(0,0,0);
for (auto tri_it = m.adj_triangle_begin((*n_it).uid()); tri_it != m.adj_triangle_end((*n_it).uid()); ++tri_it) {
value += (*tri_it).value().q_bar * (*tri_it).area();
sum_area += (*tri_it).area();
}
(*n_it).value().q = value * 1.0/(sum_area);
}
// handles the ball
else {
(*n_it).set_position((*n_it).position() + (*n_it).value().velocity*dt);
dh = (*n_it).value().q.h - (*n_it).position().z;
(*n_it).value().q.h = (*n_it).position().z;
(*n_it).value().velocity += force(m,(*n_it),t)*dt/(*n_it).value().mass;
if ((*n_it).value().q.h < ball_bottom) {
ball_bottom = (*n_it).position().z;
bottom_loc = (*n_it).position();
}
}
}
// find the water node closest to the bottom of the ball
for (auto n_it = m.node_begin(); (*n_it).index() != water_nodes; ++n_it) {
if (norm(Point((*n_it).position().x,(*n_it).position().y,0)-Point(bottom_loc.x,bottom_loc.y,0)) < water_dis){
water_dis = norm(Point((*n_it).position().x,(*n_it).position().y,0)-Point(bottom_loc.x,bottom_loc.y,0));
water_loc = Point((*n_it).position().x,(*n_it).position().y,(*n_it).value().q.h);
}
}
// apply contraints of neccessary
c(m,ball_bottom);
// determines if the ball fell below shallow water and updates height submerged
if (bottom_loc.z < water_loc.z)
submerged_height += dh;
return Point(bottom_loc.x, bottom_loc.y, submerged_height);
}
示例10: 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;
}
示例11: apply
//! Get required faces of every element and store the unqiue ones
static void apply( const MESH & mesh,
const std::vector<Face> & faces,
FaceMesh & faceMesh )
{
// 1. Allocate space for nodes and face elements
const std::size_t numNodes = std::distance( mesh.nodesBegin(),
mesh.nodesEnd() );
const std::size_t numElements = faces.size();
faceMesh.allocate( numNodes, numElements );
// 2. Copy nodes (not just the pointers!!!)
typename MESH::NodePtrConstIter sourceNode = mesh.nodesBegin();
typename MESH::NodePtrConstIter finalNode = mesh.nodesEnd();
typename FaceMesh::NodePtrIter copyNode = faceMesh.nodesBegin();
for ( ; sourceNode != finalNode; ++sourceNode, ++copyNode ) {
// Copy the global ID
(*copyNode) -> setID( (*sourceNode) -> getID() );
// Copy the coordinates
std::vector<double> x( Node::dim );
(*sourceNode) -> getX( x.begin() );
(*copyNode) -> setX( x.begin() );
}
// 3. Generate new elements from faces
typename FaceMesh::ElementPtrIter elemIter = faceMesh.elementsBegin();
typename FaceMesh::ElementPtrIter elemEnd = faceMesh.elementsEnd();
typename std::vector<Face>::const_iterator faceIter = faces.begin();
for ( ; elemIter != elemEnd; ++elemIter, ++faceIter ) {
// Extract face's node IDs
Face nodeIDs;
for ( unsigned v = 0; v < nodeIDs.size(); v ++ )
nodeIDs[v] = faceIter -> at( v );
// Set face element connectivity
typename FaceMesh::Element::NodePtrIter node =
(*elemIter) -> nodesBegin();
for ( unsigned v = 0; v < Face::size(); v++, ++node ) {
(*node) = mesh.nodePtr( nodeIDs[v] );
}
}
return;
}
示例12: CreateMesh
/*************
* DESCRIPTION: create mesh dialog
* INPUT: ID dialog ID
* OUTPUT: -
*************/
void CDoc::CreateMesh(int ID)
{
UNDO_CREATE *pUndo;
MESH *pMesh;
BOOL bErr;
nDialogID = ID;
CCMeshDlg dialog;
if (dialog.DoModal() == IDOK)
{
pMesh = new MESH;
if (pMesh)
{
pMesh->selected = TRUE;
pMesh->surf = new SURFACE;
if (pMesh->surf)
{
switch (nDialogID)
{
case IDD_CUBE: bErr = pMesh->CreateCube(&dialog.m_vSize); break;
case IDD_TORUS: bErr = pMesh->CreateTorus(dialog.m_Radius, dialog.m_Thickness, dialog.m_nDivs, dialog.m_nSlices); break;
case IDD_SPHERE: bErr = pMesh->CreateSphere(dialog.m_Radius, dialog.m_nDivs, dialog.m_nSlices); break;
case IDD_TUBE: bErr = pMesh->CreateTube(dialog.m_Radius, dialog.m_Height, dialog.m_nDivs, dialog.m_nSlices, dialog.m_bClosedBottom, dialog.m_bClosedTop); break;
case IDD_PLANE: bErr = pMesh->CreatePlane(&dialog.m_vSize, dialog.m_nXDivs, dialog.m_nZDivs); break;
case IDD_CONE: bErr = pMesh->CreateCone(dialog.m_Radius, dialog.m_Height, dialog.m_nDivs, dialog.m_nSlices, dialog.m_bClosedBottom); break;
}
if (!bErr)
delete pMesh;
else
{
DeselectAll();
pMesh->Append();
pMesh->IsFirstSelected();
pUndo = new UNDO_CREATE;
if (pUndo)
{
if (pUndo->AddCreated(pMesh))
pUndo->Add();
else
delete pUndo;
}
sciBrowserBuild();
}
}
else
delete pMesh;
}
}
sciRedraw();
}
示例13: post_process
void post_process(MESH& m) {
// HW4B: Post-processing step
// Translate the triangle-averaged values to node-averaged values
// Implement Equation 9 from your pseudocode here
for (auto nit = m.node_begin(); nit != m.node_end(); ++nit) {
double total_area = 0;
QVar Q_tot(0, 0, 0);
int count = 0;
for (auto tri_it = m.adjacent_triangle_begin(*nit); tri_it != m.adjacent_triangle_end(*nit); ++tri_it) {
Q_tot = Q_tot + (*tri_it).value() * (*tri_it).area();
total_area += (*tri_it).area();
++count;
}
(*nit).value() = Q_tot / total_area;
}
}
示例14: giveRadius
double giveRadius( const MESH& mesh, const FIELD& field )
{
typename MESH::NodePtrConstIter nIter = mesh.nodesBegin();
typename FIELD::DoFPtrConstIter dIter = field.doFsBegin();
return
((*nIter) -> getX())[0] +
((*dIter) -> getValue(0));
}
示例15: post_process
/*
* post process of a mesh instance to update the values of all the nodes values
* @pre: a valid mesh instance
* @post: update the nodes values based on approximation of the average of neighbours values
refer to equation 9 on the notes
*/
void post_process(MESH& m) {
// Translate the triangle-averaged values to node-averaged values
// Implement Equation 8 from your pseudocode here
// iterate through all the nodes
for ( auto it = m.node_begin(); it!= m.node_end(); ++it)
{
QVar sum = QVar(0,0,0);
double sumTriArea = 0;
// for each node, iterate through its adjacent triangles
for (auto adji = m.vertex_begin((*it).index()); adji != m.vertex_end((*it).index()); ++ adji)
{
auto tri = (*adji);
sum += tri.area() * tri.value();
sumTriArea += tri.area();
}
(*it).value() = sum/sumTriArea; // update nodes value
}
}