HRESULT APPLICATION::Render() { // Clear the viewport m_pDevice->Clear( 0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0L ); // Begin the scene if(SUCCEEDED(m_pDevice->BeginScene())) { if(m_wireframe)m_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); else m_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); //Render either of the meshes if(m_activeMesh == 0) m_mesh1.Render(); else m_mesh2.Render(); RECT r[] = {{10, 10, 0, 0}, {10, 30, 0, 0}}; m_pFont->DrawText(NULL, "Space: Next Object", -1, &r[0], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); m_pFont->DrawText(NULL, "W: Toggle Wireframe", -1, &r[1], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); // End the scene. m_pDevice->EndScene(); m_pDevice->Present(0, 0, 0, 0); } return S_OK; }
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] ); }
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; } } } }
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; }
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; }
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; }
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; };
void operator()(MESH& m, double t) { (void) t; for(auto it=m.node_begin(); it != m.node_end(); ++ it) { if ((*it).position().z < plane_) { Point current_position = (*it).position(); Point current_veloc = (*it).value().velocity; (*it).set_position(Point(current_position.x,current_position.y,plane_)); (*it).value().velocity = Point(current_veloc.x,current_veloc.y,-current_veloc.z); } } }
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; }
Point operator() (MESH& m, NODE n, double t){ Point node_velocity = n.value().velocity; Point node_normal(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); // approximate node normal vector by the sum of normal vectors of its neighboring faces node_normal += get_normal_surface(tri); } // calculte wind force Point force = wind_const * dot(wind_velocity_ - node_velocity, node_normal) * node_normal; (void) t; return force; }
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; } }
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); }
/* * 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; }
HRESULT APPLICATION::Cleanup() { try { m_build1.Release(); m_build2.Release(); m_pDevice->Release(); debug.Print("Application terminated"); } catch(...){} return S_OK; }
//! 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; }
/************* * 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(); }
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; } }
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)); }
/* * 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 } }
double errorComputation( const QUADRATURE& quadrature, const MESH& mesh, const FIELD& field, const typename base::post::ErrorNorm< typename MESH::Element, typename FIELD::Element, ORDER>::Reference& refSol ) { typedef ErrorNorm<typename MESH::Element,typename FIELD::Element, ORDER> Error; Error error( refSol ); // compute for every element the error typename MESH::ElementPtrConstIter elemIter = mesh.elementsBegin(); typename MESH::ElementPtrConstIter elemLast = mesh.elementsEnd(); double errorSquared = 0.; for ( ; elemIter != elemLast; ++elemIter ) { // work around to get the ID of the field elements const std::size_t fieldElemID = detail_::getID( *elemIter ); // get corresponding field element typename FIELD::Element* fieldElem = field.elementPtr( fieldElemID ); // Construct a field element pointer tuple base::asmb::FieldElementPointerTuple< typename MESH::Element*, typename FIELD::Element*> fept( *elemIter, fieldElem ); // apply quadrature quadrature.apply( error, fept, errorSquared ); } // return the square root of the sum of the squares return std::sqrt( errorSquared ); }
HRESULT APPLICATION::Render() { // Clear the viewport m_pDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0); //Set camera D3DXMATRIX view, proj, world, identity; D3DXMatrixLookAtLH(&view, &D3DXVECTOR3(15.0f, 30.0f, -40.0f), &D3DXVECTOR3(0.0f, 11.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI * 0.3f, 1.33333f, 0.01f, 1000.0f); D3DXMatrixIdentity(&identity); m_pDevice->SetTransform(D3DTS_WORLD, &identity); m_pDevice->SetTransform(D3DTS_VIEW, &view); m_pDevice->SetTransform(D3DTS_PROJECTION, &proj); // Begin the scene if(SUCCEEDED(m_pDevice->BeginScene())) { if(m_buildPrc < 1.0f) { m_build1.Render(m_buildPrc); //Progressbar m_pDevice->Clear(1, &SetRect(10, 560, 790, 590), D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff000000, 1.0f, 0); m_pDevice->Clear(1, &SetRect(12, 562, 788, 588), D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0); m_pDevice->Clear(1, &SetRect(12, 562, (int)(12 + 774 * m_buildPrc), 588), D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff00ff00, 1.0f, 0); } else m_build2.Render(); // End the scene. m_pDevice->EndScene(); m_pDevice->Present(0, 0, 0, 0); } return S_OK; }
HRESULT APPLICATION::Cleanup() { try { m_pFont->Release(); if(m_pFarmerMesh != NULL) m_pFarmerMesh->Release(); m_pDevice->Release(); debug.Print("Application terminated"); } catch(...){} return S_OK; }
void moveSurface( const MESH& mesh, const FIELD& velocity, typename base::cut::SurfaceMeshBinder<MESH>::SurfaceMesh &surfaceMesh, const double dt, const double factor, const typename MESH::Node::VecDim ¢roid ) { typedef typename base::cut::SurfaceMeshBinder<MESH>::SurfaceMesh SurfaceMesh; typedef typename base::Vector<MESH::Node::dim>::Type VecDim; // go through all elements of the surface mesh typename SurfaceMesh::ElementPtrIter eIter = surfaceMesh.elementsBegin(); typename SurfaceMesh::ElementPtrIter eEnd = surfaceMesh.elementsEnd(); for ( ; eIter != eEnd; ++eIter ) { const std::size_t elemID = (*eIter) -> getDomainID(); const typename MESH::Element* geomElem = mesh.elementPtr( elemID ); const typename FIELD::Element* velocElem = velocity.elementPtr( elemID ); typename SurfaceMesh::Element::ParamIter pIter = (*eIter) -> parametricBegin(); typename SurfaceMesh::Element::ParamIter pEnd = (*eIter) -> parametricEnd(); typename SurfaceMesh::Element::NodePtrIter nIter = (*eIter) -> nodesBegin(); for ( ; pIter != pEnd; ++pIter, ++nIter ) { // evaluate time step times velocity at parameter coordinate const VecDim du = dt * base::post::evaluateFieldHistory<0>( geomElem, velocElem, *pIter ); // get old location VecDim x; (*nIter) -> getX( &(x[0]) ); // add value to nodal coordinate //const VecDim xNew = x + du; const VecDim xNew = centroid + factor * (x-centroid) + du; (*nIter) -> setX( &(xNew[0]) ); } } return; }
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 /* 1. Initialize a vector temp_Q of size @a m.num_triangles() for storing all temp Q_bar values * 2. Use a TriangleIterator to iterate through all the triangles, for each tri_it: * a. Compute the sum of fluxes sum_fluxes * b. temp_Q[(*it).index()] = sum_fluxes * 3. Use indices of triangles to do another for loop, for each triangle(i): * a. triangle_i.value().Q_bar = temp_Q[i] */ std::vector<QVar> temp_fluxes(m.num_triangles(), QVar()); for (auto tri_it = m.triangle_begin(); tri_it != m.triangle_end(); ++tri_it) { auto qk = (*tri_it).value(); QVar F_k(0, 0, 0); for (size_type i = 0; i < 3; ++i) { auto edge = (*tri_it).edge(i); QVar qm(0, 0, 0); if (m.adj_triangle1_index(edge) == -1 || m.adj_triangle2_index(edge) == -1) { //set_boundary_conditions qm = QVar(qk.h, 0, 0); } else { size_type adj_tri_idx = m.adj_triangle1_index(edge) == (*tri_it).index() ? m.adj_triangle2_index(edge) : m.adj_triangle1_index(edge); auto adj_triangle = m.triangle(adj_tri_idx); qm = adj_triangle.value(); } auto norm_ke = m.out_norm((*tri_it), edge); F_k = F_k + f(norm_ke.x, norm_ke.y, dt, qk, qm); } // print_triangle(m, (*tri_it), f, t, dt); temp_fluxes[(*tri_it).index()] = qk - F_k * (dt / (*tri_it).area()); } for (auto tri_it = m.triangle_begin(); tri_it != m.triangle_end(); ++tri_it) { (*tri_it).value() = temp_fluxes[(*tri_it).index()]; } return t + dt; }
void operator()(MESH& m, double z_bottom) { if (z_bottom < plane_) for(auto it=m.node_begin(); it != m.node_end(); ++it) (*it).value().velocity = Point(0,0,0); }
void DynamicSubdivisionCCBase<MESH>::copyFromBin( BinaryDataHandler &pMem, const BitVector &whichField) { Inherited::copyFromBin(pMem, whichField); if(FieldBits::NoField != (MinProjSizeFieldMask & whichField)) { _sfMinProjSize.copyFromBin(pMem); } if(FieldBits::NoField != (MaxProjSizeFieldMask & whichField)) { _sfMaxProjSize.copyFromBin(pMem); } if(FieldBits::NoField != (VertexClassifierFieldMask & whichField)) { _sfVertexClassifier.copyFromBin(pMem); } if(FieldBits::NoField != (NormalConeApertureFieldMask & whichField)) { _sfNormalConeAperture.copyFromBin(pMem); } if(FieldBits::NoField != (MinDepthFieldMask & whichField)) { _sfMinDepth.copyFromBin(pMem); } if(FieldBits::NoField != (MaxDepthFieldMask & whichField)) { _sfMaxDepth.copyFromBin(pMem); } if(FieldBits::NoField != (BackfaceCullingFieldMask & whichField)) { _sfBackfaceCulling.copyFromBin(pMem); } if(FieldBits::NoField != (MeshFieldMask & whichField)) { // new OpenMesh object MESH* newmesh = new MESH; ::OpenMesh::EPropHandleT<Int32> isCrease; newmesh->add_property(isCrease,"isCrease"); //_sfMesh.copyFromBin(pMem,getMesh()); SINFO << "read Mesh" << std::endl; OSGMeshIO<MESH> myMeshIO(*newmesh); myMeshIO.readOpenMesh(pMem); setMesh(newmesh); } #if 0 if(FieldBits::NoField != (TesselatorFieldMask & whichField)) { _sfTesselator.copyFromBin(pMem); } #endif if(FieldBits::NoField != (AutoUpdateFieldMask & whichField)) { _sfAutoUpdate.copyFromBin(pMem); } }
HRESULT APPLICATION::Init(HINSTANCE hInstance, int width, int height, bool windowed) { debug.Print("Application initiated"); //Create Window Class WNDCLASS wc; memset(&wc, 0, sizeof(WNDCLASS)); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC)::DefWindowProc; wc.hInstance = hInstance; wc.lpszClassName = "D3DWND"; //Register Class and Create new Window RegisterClass(&wc); m_mainWindow = CreateWindow("D3DWND", "Example 4.9: Loading & Rendering X-files", WS_EX_TOPMOST, 0, 0, width, height, 0, 0, hInstance, 0); SetCursor(NULL); ShowWindow(m_mainWindow, SW_SHOW); UpdateWindow(m_mainWindow); //Create IDirect3D9 Interface IDirect3D9* d3d9 = Direct3DCreate9(D3D_SDK_VERSION); if(d3d9 == NULL) { debug.Print("Direct3DCreate9() - FAILED"); return E_FAIL; } //Check that the Device supports what we need from it D3DCAPS9 caps; d3d9->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps); //Hardware Vertex Processing or not? int vp = 0; if(caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) vp = D3DCREATE_HARDWARE_VERTEXPROCESSING; else vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING; //Check vertex & pixelshader versions if(caps.VertexShaderVersion < D3DVS_VERSION(2, 0) || caps.PixelShaderVersion < D3DPS_VERSION(2, 0)) { debug.Print("Warning - Your graphic card does not support vertex and pixelshaders version 2.0"); } //Set D3DPRESENT_PARAMETERS D3DPRESENT_PARAMETERS d3dpp; d3dpp.BackBufferWidth = width; d3dpp.BackBufferHeight = height; d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8; d3dpp.BackBufferCount = 1; d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; d3dpp.MultiSampleQuality = 0; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = m_mainWindow; d3dpp.Windowed = windowed; d3dpp.EnableAutoDepthStencil = true; d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; d3dpp.Flags = 0; d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; //Create the IDirect3DDevice9 if(FAILED(d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_mainWindow, vp, &d3dpp, &m_pDevice))) { debug.Print("Failed to create IDirect3DDevice9"); return E_FAIL; } //Release IDirect3D9 interface d3d9->Release(); D3DXCreateFont(m_pDevice, 18, 0, 0, 1, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial", &m_pFont); //Create m_light ::ZeroMemory(&m_light, sizeof(m_light)); m_light.Type = D3DLIGHT_DIRECTIONAL; m_light.Ambient = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f); m_light.Diffuse = D3DXCOLOR(0.9f, 0.9f, 0.9f, 1.0f); m_light.Specular = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f); m_light.Direction = D3DXVECTOR3(0.7f, -0.3f, 0.0f); m_pDevice->SetLight(0, &m_light); m_pDevice->LightEnable(0, true); //Sampler states m_pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); m_pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); m_pDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT); //Load meshes if(FAILED(m_mesh1.Load("meshes/tree.x", m_pDevice)) || FAILED(m_mesh2.Load("meshes/stone.x", m_pDevice))) { debug.Print("Failed to load meshes"); Quit(); } return S_OK; }