std::vector<GEOLIB::PointWithID*> MshEditor::getSurfaceNodes( const MeshLib::CFEMesh& mesh) { std::cout << "Extracting surface nodes..." << "\n"; // Sort points lexicographically size_t nNodes(mesh.nod_vector.size()); std::vector<GEOLIB::PointWithID*> nodes; std::vector<size_t> perm; for (size_t j(0); j < nNodes; j++) { nodes.push_back( new GEOLIB::PointWithID(mesh.nod_vector[j]->getData(), j)); perm.push_back(j); } Quicksort<GEOLIB::PointWithID*>(nodes, 0, nodes.size(), perm); // Extract surface points double eps(std::numeric_limits<double>::epsilon()); std::vector<GEOLIB::PointWithID*> surface_pnts; for (size_t k(1); k < nNodes; k++) { const GEOLIB::PointWithID& p0(*(nodes[k - 1])); const GEOLIB::PointWithID& p1(*(nodes[k])); if (fabs(p0[0] - p1[0]) > eps || fabs(p0[1] - p1[1]) > eps) surface_pnts.push_back(nodes[k - 1]); } // Add last point surface_pnts.push_back(nodes[nNodes - 1]); return surface_pnts; }
GeoLib::Grid<GeoLib::PointWithID>* GeoMapper::getFlatGrid(MeshLib::Mesh const*const mesh, std::vector<GeoLib::PointWithID*> sfc_pnts) const { size_t nNodes (mesh->getNNodes()); sfc_pnts.resize(nNodes); const std::vector<MeshLib::Node*> nodes (mesh->getNodes()); for (unsigned i(0); i<nNodes; ++i) sfc_pnts[i] = new GeoLib::PointWithID((*nodes[i])[0], (*nodes[i])[1], 0.0, nodes[i]->getID()); return new GeoLib::Grid<GeoLib::PointWithID>(sfc_pnts.begin(), sfc_pnts.end()); }
GeoLib::Grid<GeoLib::PointWithID>* GeoMapper::getFlatGrid(MeshLib::Mesh const*const mesh, std::vector<GeoLib::PointWithID*> sfc_pnts) const { if (mesh->getDimension()<3) //much faster { size_t nNodes (mesh->getNNodes()); sfc_pnts.resize(nNodes); const std::vector<MeshLib::Node*> nodes (mesh->getNodes()); for (unsigned i(0); i<nNodes; ++i) sfc_pnts[i] = new GeoLib::PointWithID(nodes[i]->getCoords(), nodes[i]->getID()); } else { double dir[3] = {1,0,0}; sfc_pnts = MeshLib::MshEditor::getSurfaceNodes(*mesh, dir); } size_t nPoints (sfc_pnts.size()); for (unsigned i=0; i<nPoints; ++i) { GeoLib::PointWithID* pnt (sfc_pnts[i]); (*pnt)[2] = 0; } return new GeoLib::Grid<GeoLib::PointWithID>(sfc_pnts.begin(), sfc_pnts.end()); }
Foam::octree<Type>::octree ( const treeBoundBox& octreeBb, const Type& shapes, const label minNLevels, const scalar maxLeafRatio, const scalar maxShapeRatio ) : topNode_(new treeNode<Type>(octreeBb)), shapes_(shapes), octreeBb_(octreeBb), maxLeafRatio_(maxLeafRatio), maxShapeRatio_(maxShapeRatio), minNLevels_(minNLevels), deepestLevel_(0), nEntries_(0), nNodes_(0), nLeaves_(0), endIter_(*this, -1), endConstIter_(*this, -1) { cpuTime timer; setNodes(nNodes() + 1); const label nShapes = shapes_.size(); labelList indices(nShapes); for (label i = 0; i < nShapes; i++) { indices[i] = i; } // Create initial level (0) of subLeaves if (debug & 1) { Pout<< "octree : --- Start of Level " << deepestLevel_ << " ----" << endl; } topNode_->distribute(0, *this, shapes_, indices); if (debug & 1) { printStats(Pout); Pout<< "octree : --- End of Level " << deepestLevel_ << " ----" << endl; } // Breadth first creation of tree // Stop if: - level above minlevel and // - less than so many cells per endpoint // (so bottom level is fine enough) // - every shape mentioned in only so many // leaves. (if shape bb quite big it will end up // in lots of leaves). // - no change in number of leaves // (happens if leafs fine enough) // This guarantees that tree // - is fine enough (if minLevel > 0) // - has some guaranteed maximum size (maxShapeRatio) label oldNLeaves = -1; // make test below pass first time. deepestLevel_ = 1; while ( (deepestLevel_ <= minNLevels_) || ( (nEntries() > maxLeafRatio * nLeaves()) // shapes per leaf && (nEntries() < maxShapeRatio * nShapes) // entries per shape ) ) { if (deepestLevel_ >= maxNLevels) { if (debug & 1) { Pout<< "octree : exiting since maxNLevels " << maxNLevels << " reached" << endl; } break; } if (oldNLeaves == nLeaves()) { if (debug & 1) { Pout<< "octree : exiting since nLeaves does not change" << endl; } break; } if (debug & 1) { Pout<< "octree : --- Start of Level " << deepestLevel_ << " ----" << endl; } oldNLeaves = nLeaves(); topNode_->redistribute ( 1, *this, shapes_, deepestLevel_ ); if (debug & 1) { printStats(Pout); Pout<< "octree : --- End of Level " << deepestLevel_ << " ----" << endl; } deepestLevel_++; } if (debug & 1) { Pout<< "octree : Constructed octree in = " << timer.cpuTimeIncrement() << " s\n" << endl << endl; } // Set volume type of non-treeleaf nodes. topNode_->setSubNodeType(0, *this, shapes_); if (debug & 1) { Pout<< "octree : Added node information to octree in = " << timer.cpuTimeIncrement() << " s\n" << endl << endl; } }