// Output a list of primitives as a VTK file. // - primitiveType is: // 0: List of points // 1: List of edges // 2: List of faces // 3: List of cells void conservativeMeshToMesh::writeVTK ( const word& name, const labelList& cList, const label primitiveType, const bool useOldConnectivity, const UList<scalar>& field ) const { if (useOldConnectivity) { // Use points from polyMesh meshOps::writeVTK ( tgtMesh(), name, cList, primitiveType, srcMesh().points(), srcMesh().edges(), srcMesh().faces(), srcMesh().cells(), srcMesh().faceOwner(), field ); } else { meshOps::writeVTK ( tgtMesh(), name, cList, primitiveType, tgtMesh().points(), tgtMesh().edges(), tgtMesh().faces(), tgtMesh().cells(), tgtMesh().faceOwner(), field ); } }
void remapMesh(const MeshSrc& meshSrc, const MeshDest& meshDest, const MeshRemapSettings<Index>& s, MeshRemapResult<typename boost::make_unsigned<Index>::type, typename mesh_adaptor<MeshSrc>::scalar>& result) { typedef mesh_adaptor<MeshSrc> SrcAdaptor; typedef mesh_adaptor<MeshDest> DestAdaptor; typedef typename SrcAdaptor::scalar T; typedef typename SrcAdaptor::const_poly_ref const_src_poly_ref; typedef typename SrcAdaptor::poly_type src_poly_type; typedef typename DestAdaptor::poly_type dest_poly_type; typedef points_adaptor<src_poly_type> SrcPointsAdaptor; typedef points_adaptor<dest_poly_type> DestPointsAdaptor; typedef typename boost::make_unsigned<Index>::type UIndex; typedef MeshRemapResult<UIndex,T> result_type; typedef typename result_type::contrib_type result_contrib_type; typedef typename result_type::contribs_type result_contribs_type; typedef typename result_type::vertex_contribs result_vertex_contribs; typedef typename result_type::remap_map result_remap_map; typedef typename result_type::contribs_vector result_contribs_vector; typedef boost::unordered_map<unsigned int, unsigned int> u_u_map; BOOST_MPL_ASSERT((boost::is_same<T,typename DestAdaptor::scalar>)); if(!s.m_genPointRemapping && !s.m_genPolyRemapping && !s.m_genVertexRemapping) return; SrcAdaptor srcMesh(meshSrc); DestAdaptor destMesh(meshDest); // create identity point remapping if all points map directly std::vector<Index> point_mapping_; const std::vector<Index>* point_mapping = s.m_pointMapping; if(s.m_identity_point_mapping) { unsigned int npoints = destMesh.numPoints(); point_mapping_.resize(npoints); for(unsigned int i=0; i<npoints; ++i) point_mapping_[i] = i; point_mapping = &point_mapping_; } if(s.m_genPointRemapping && point_mapping) { // direct point remapping (straightforward, just copy >=0 entries into the map) unsigned int npoints = point_mapping->size(); for(unsigned int i=0; i<npoints; ++i) { Index ptnum = (*point_mapping)[i]; if(ptnum >= 0) { typename result_remap_map::value_type v( s.m_firstPoint+i, static_cast<UIndex>(ptnum)); result.m_pointMapping.insert(v); } } } if(s.m_genPolyRemapping || s.m_genVertexRemapping) { // we don't support missing poly remapping yet! if(!s.m_polyMapping || s.m_polyMapping->size() != destMesh.numPolys()) { throw std::runtime_error("Missing/partial poly mapping not yet supported"); } const std::vector<Index>& polyremap = *(s.m_polyMapping); unsigned int npolys = destMesh.numPolys(); std::vector<T> coeffs; u_u_map pt_vert_lookup; // remap polys for(unsigned int i=0; i<npolys; ++i) { Index polynum = polyremap[i]; if(polynum > 0) { typename result_remap_map::value_type v( s.m_firstPoly+i, static_cast<UIndex>(polynum-1)); if(s.m_genPolyRemapping) result.m_polyMapping.insert(v); if(s.m_genVertexRemapping) result.m_vertexMapping.insert(v); } else if(polynum < 0) { UIndex upolynum = static_cast<UIndex>(-1-polynum); if(s.m_genPolyRemapping) { typename result_remap_map::value_type v(s.m_firstPoly+i, upolynum); result.m_polyMapping.insert(v); } // this is a poly fragment if(s.m_genVertexRemapping || s.m_genPointRemapping) { const_src_poly_ref srcPoly = srcMesh.getPoly(upolynum); DestPointsAdaptor destPoly(destMesh.getPoly(i)); unsigned int ndestverts = destPoly.size(); result_vertex_contribs* vcontribs = NULL; if(s.m_genVertexRemapping) { vcontribs = &(result.m_vertexIMapping[s.m_firstPoly+i]); vcontribs->first = upolynum; vcontribs->second.resize(ndestverts); // build (src pt -> destpoly vert index) lookup pt_vert_lookup.clear(); SrcPointsAdaptor a_srcPoly(srcPoly); unsigned int nsrcverts = a_srcPoly.size(); for(unsigned int j=0; j<nsrcverts; ++j) pt_vert_lookup.insert(u_u_map::value_type(a_srcPoly.index(j), j)); } // iterate over dest poly verts for(unsigned int j=0; j<ndestverts; ++j) { coeffs.clear(); // does the vert map to a src point? unsigned int dest_ptnum = destPoly.index(j); int src_ptnum = (point_mapping && (dest_ptnum < point_mapping->size()))? (*point_mapping)[dest_ptnum] : -1; if(s.m_genVertexRemapping) { result_contribs_type& contribs = vcontribs->second[j]; if(src_ptnum >= 0) { u_u_map::const_iterator it = pt_vert_lookup.find(src_ptnum); if(it != pt_vert_lookup.end()) { // mapped dest vert to src, via common point contribs.resize(1); contribs[0] = result_contrib_type(it->second, 1); } } if(contribs.empty()) { // no common point found, do barycentric interpolation getGeneralBarycentricCoord(srcPoly, destPoly[j], coeffs); unsigned int ncoeffs = coeffs.size(); contribs.resize(ncoeffs); for(unsigned int k=0; k<ncoeffs; ++k) contribs[k] = result_contrib_type(k, coeffs[k]); } } dest_ptnum += s.m_firstPoint; if(s.m_genPointRemapping && (src_ptnum < 0) && (result.m_pointIMapping.find(dest_ptnum) == result.m_pointIMapping.end())) { // we can reuse the vertex barycentric coord if that happened if(coeffs.empty()) getGeneralBarycentricCoord(srcPoly, destPoly[j], coeffs); unsigned int ncoeffs = coeffs.size(); result_contribs_type& contribs = result.m_pointIMapping[dest_ptnum]; contribs.resize(ncoeffs); SrcPointsAdaptor a_srcPoly(srcPoly); for(unsigned int k=0; k<ncoeffs; ++k) contribs[k] = result_contrib_type(a_srcPoly.index(k), coeffs[k]); } } } } } } }