Exemplo n.º 1
0
 forceinline
 TaskTree<TaskView,Node>::TaskTree(Region& r, 
                                   const TaskViewArray<TaskView>& t)
   : tasks(t), 
     node(r.alloc<Node>(n_nodes())),
     _leaf(r.alloc<int>(tasks.size())) {
   // Compute a sorting map to order by non decreasing est
   int* map = r.alloc<int>(tasks.size());
   sort<TaskView,STO_EST,true>(map, tasks);
   // Compute inverse of sorting map
   for (int i=tasks.size(); i--; )
     _leaf[map[i]] = i;
   r.free<int>(map,tasks.size());
   // Compute index of first leaf in tree: the next larger power of two
   int fst = 1;
   while (fst < tasks.size())
     fst <<= 1;
   fst--;
   // Remap task indices to leaf indices
   for (int i=tasks.size(); i--; )
     if (_leaf[i] + fst >= n_nodes())
       _leaf[i] += fst - tasks.size();
     else
       _leaf[i] += fst;
 }
Exemplo n.º 2
0
void KCsplit::sampleCtr(			// sample from splitting node
    KMpoint		c,			// the sampled point (returned)
    KMorthRect		&bnd_box)		// bounding box for current node
{
    int r = kmRanInt(n_nodes());		// random integer [0..n_nodes-1]
    if (r == 0)  				// sample from this node
    {
        KMorthRect expBox(kcDim);
        bnd_box.expand(kcDim, 3, expBox);	// compute 3x expanded box
        expBox.sample(kcDim, c);		// sample c from box
    }
    else if (r <= child[KM_LO]->n_nodes())  	// sample from left
    {
        KMcoord save = bnd_box.hi[cut_dim];	// save old upper bound
        bnd_box.hi[cut_dim] = cut_val;		// modify for left subtree
        child[KM_LO]->sampleCtr(c, bnd_box);
        bnd_box.hi[cut_dim] = save;		// restore upper bound
    }
    else  					// sample from right subtree
    {
        KMcoord save = bnd_box.lo[cut_dim];	// save old lower bound
        bnd_box.lo[cut_dim] = cut_val;		// modify for right subtree
        child[KM_HI]->sampleCtr(c,  bnd_box);
        bnd_box.lo[cut_dim] = save;		// restore lower bound
    }
}
Exemplo n.º 3
0
 forceinline
 TaskTree<TaskView,Node>::TaskTree(Region& r, 
                                   const TaskTree<TaskView,Node2>& t)
   : tasks(t.tasks), 
     node(r.alloc<Node>(n_nodes())),
     _leaf(r.alloc<int>(tasks.size())) {
   for (int i=tasks.size(); i--; )
     _leaf[i] = t._leaf[i];
 }
Exemplo n.º 4
0
void GMSHInterface::readGMSHMesh(std::string const& fname, MeshLib::CFEMesh* mesh)
{
	std::string line;
	std::ifstream in(fname.c_str(), std::ios::in);
	getline(in, line); // Node keyword

	if (line.find("$MeshFormat") != std::string::npos) {
		getline(in, line); // version-number file-type data-size
		getline(in, line); //$EndMeshFormat
		getline(in, line); //$Nodes Keywords

		size_t n_nodes(0);
		size_t n_elements(0);
		while (line.find("$EndElements") == std::string::npos) {
			// Node data
			long id;
			double x, y, z;
			in >> n_nodes >> std::ws;
			for (size_t i = 0; i < n_nodes; i++) {
				in >> id >> x >> y >> z >> std::ws;
				mesh->nod_vector.push_back(new MeshLib::CNode(id, x, y, z));
			}
			getline(in, line); // End Node keyword $EndNodes

			// Element data
			getline(in, line); // Element keyword $Elements
			in >> n_elements >> std::ws; // number-of-elements
			for (size_t i = 0; i < n_elements; i++) {
				MeshLib::CElem* elem(new MeshLib::CElem(i));
				elem->Read(in, 7);
				if (elem->GetElementType() != MshElemType::INVALID) mesh->ele_vector.push_back(elem);
			}
			getline(in, line); // END keyword

			// correct indices TF
			const size_t n_elements(mesh->ele_vector.size());
			for (size_t k(0); k < n_elements; k++)
				mesh->ele_vector[k]->SetIndex(k);

			// ordering nodes and closing gaps TK
			std::vector<size_t> gmsh_id;
			size_t counter(0);
			for (size_t i = 0; i < mesh->nod_vector.size(); i++) {
				const size_t diff = mesh->nod_vector[i]->GetIndex() - counter;
				if (diff == 0) {
					gmsh_id.push_back(i);
					counter++;
				} else {
					for (size_t j = 0; j < diff; j++) {
						gmsh_id.push_back(i);
						counter++;
					}
					i--;
				}
			}

			for (size_t i = 0; i < mesh->ele_vector.size(); i++)
				for (long j = 0; j < mesh->ele_vector[i]->GetVertexNumber(); j++)
					mesh->ele_vector[i]->getNodeIndices()[j]
									= gmsh_id[mesh->ele_vector[i]->GetNodeIndex(j) + 1];

			for (size_t i = 0; i < mesh->nod_vector.size(); i++)
				mesh->nod_vector[i]->SetIndex(i);
			// END OF: ordering nodes and closing gaps TK
		} /*End while*/
	}
Exemplo n.º 5
0
 double& at(unsigned int nnode_id, unsigned int neigh_id) {
     assert(nnode_id > 0);
     assert(nnode_id -1 < n_nodes());
     assert(neigh_id < m_neigh_dim);
     return m_data[index(nnode_id, neigh_id)];
 }
Exemplo n.º 6
0
void testMeshGridAlgorithm(MeshLib::Mesh const*const mesh,
                           std::vector<GeoLib::Point*>& pnts_for_search,
                           std::vector<size_t> &idx_found_nodes, bool contiguous)
{
    // constructing Grid
    INFO ("[MeshGridAlgorithm] constructing mesh grid object ...");

    if (contiguous) {
        std::vector<MeshLib::Node> mesh_nodes;
        size_t n_nodes(mesh->getNodes().size());
        mesh_nodes.reserve(n_nodes);
        for (size_t k(0); k<n_nodes; k++) {
            mesh_nodes.push_back(MeshLib::Node(*(mesh->getNodes()[k])));
        }
#ifndef WIN32
        BaseLib::MemWatch mem_watch;
        unsigned long mem_without_mesh (mem_watch.getVirtMemUsage());
#endif
        clock_t start_grid_construction = clock();
        GeoLib::Grid<MeshLib::Node> mesh_grid(mesh_nodes.begin(), mesh_nodes.end(), 511);
        clock_t end_grid_construction = clock();
#ifndef WIN32
        unsigned long mem_with_mesh (mem_watch.getVirtMemUsage());
#endif
        INFO("\tdone, construction time: %f seconds", (end_grid_construction-start_grid_construction)/(double)(CLOCKS_PER_SEC));
#ifndef WIN32
        INFO ("[MeshGridAlgorithm] mem for mesh grid: %i MB", (mem_with_mesh - mem_without_mesh)/(1024*1024));
#endif
        const size_t n_pnts_for_search(pnts_for_search.size());
        INFO ("[MeshGridAlgorithm] searching %d points ...", pnts_for_search.size());
        clock_t start = clock();
        for (size_t k(0); k<n_pnts_for_search; k++) {
            MeshLib::Node const* node(mesh_grid.getNearestPoint(pnts_for_search[k]->getCoords()));
            idx_found_nodes.push_back(node->getID());
        }
        clock_t stop = clock();
        INFO("\tdone, search time: %f seconds", (stop-start)/(double)(CLOCKS_PER_SEC));
    } else {
#ifndef WIN32
        BaseLib::MemWatch mem_watch;
        unsigned long mem_without_mesh (mem_watch.getVirtMemUsage());
#endif
        clock_t start_grid_construction = clock();
        GeoLib::Grid<MeshLib::Node> mesh_grid(mesh->getNodes().begin(), mesh->getNodes().end(), 511);
        clock_t end_grid_construction = clock();
#ifndef WIN32
        unsigned long mem_with_mesh (mem_watch.getVirtMemUsage());
#endif
        INFO("\tdone, construction time: %f seconds", (end_grid_construction-start_grid_construction)/(double)(CLOCKS_PER_SEC));
#ifndef WIN32
        INFO ("[MeshGridAlgorithm] mem for mesh grid: %i MB", (mem_with_mesh - mem_without_mesh)/(1024*1024));
#endif
        const size_t n_pnts_for_search(pnts_for_search.size());
        INFO ("[MeshGridAlgorithm] searching %d points ...", pnts_for_search.size());
        clock_t start = clock();
        for (size_t k(0); k<n_pnts_for_search; k++) {
            MeshLib::Node const* node(mesh_grid.getNearestPoint(pnts_for_search[k]->getCoords()));
            idx_found_nodes.push_back(node->getID());
        }
        clock_t stop = clock();
        INFO("\tdone, search time: %f seconds", (stop-start)/(double)(CLOCKS_PER_SEC));
    }
}
Exemplo n.º 7
0
MeshNodesAlongPolyline::MeshNodesAlongPolyline(
		GEOLIB::Polyline const* const ply, MeshLib::CFEMesh const* mesh,
		double search_radius) :
	_ply(ply), _mesh(mesh), _linear_nodes (0)
{
	std::vector<CNode*> const& mesh_nodes (mesh->getNodeVector());

	size_t n_linear_order_nodes (mesh->GetNodesNumber (false));
	size_t n_nodes (mesh->GetNodesNumber (true));

	std::vector<size_t> msh_node_higher_order_ids;
	std::vector<double> dist_of_proj_higher_order_node_from_ply_start;

	//We need exactly defined polyline for DDC. If there is not any node located within the
	// threhold the ployline, we do not forced to fill the _msh_node_ids.
	//Therefore, the repeating loop is skipped.
	// repeat until at least one relevant node was found
	// WW while (_msh_node_ids.empty())
	{
		// loop over all line segments of the polyline
		for (size_t k = 0; k < ply->getNumberOfPoints() - 1; k++)
		{
			double act_length_of_ply(ply->getLength(k));
			double seg_length (sqrt(MathLib::sqrDist(_ply->getPoint(k), _ply->getPoint(k + 1))));
			double lower_lambda (- search_radius / seg_length);
			double upper_lambda (1 + search_radius / seg_length);

			// loop over all nodes
			for (size_t j = 0; j < n_nodes; j++)
			{
				double dist, lambda;

				// is the orthogonal projection of the j-th node to the
				// line g(lambda) = _ply->getPoint(k) + lambda * (_ply->getPoint(k+1) - _ply->getPoint(k))
				// at the k-th line segment of the polyline, i.e. 0 <= lambda <= 1?
				if (MathLib::calcProjPntToLineAndDists(mesh_nodes[j]->getData(),
								(_ply->getPoint(k))->getData(), (_ply->getPoint(k + 1))->getData(),
								lambda, dist) <= search_radius) {
					if (lower_lambda <= lambda && lambda <= upper_lambda) {
						if (mesh_nodes[j]->GetIndex() < n_linear_order_nodes) {
							// check if node id is already in the vector
							if (std::find(_msh_node_ids.begin(), _msh_node_ids.end(),
											mesh_nodes[j]->GetIndex()) == _msh_node_ids.end()) {
								_msh_node_ids.push_back(mesh_nodes[j] ->GetIndex());
								_dist_of_proj_node_from_ply_start. push_back(act_length_of_ply + dist);
								_linear_nodes++;
							}
						} else {
							// check if node id is already in the vector
							if (std::find(msh_node_higher_order_ids.begin(),
											msh_node_higher_order_ids.end(), mesh_nodes[j]->GetIndex())
											== msh_node_higher_order_ids.end()) {
								msh_node_higher_order_ids.push_back(mesh_nodes[j]->GetIndex());
								dist_of_proj_higher_order_node_from_ply_start .push_back(act_length_of_ply
												+ dist);
							}
						}
					} // end if lambda
				}
			} // end node loop
		} // end line segment loop

		//We need exactly defined polyline for DDC. 
		//Therefore, the following two line should be dropped.
		//if (_msh_node_ids.empty())
		//	search_radius *= 2.0;
	}

	// sort the (linear) nodes along the polyline according to their distances
	Quicksort<double> (_dist_of_proj_node_from_ply_start, 0,
					_dist_of_proj_node_from_ply_start.size(), _msh_node_ids);

#ifndef NDEBUG
//	std::cout << "[DEBUG-INFO] " << "\n";
//
//	// fetch polyline name
//	std::string ply_name;
//	if (! _mesh->getGEOObjects()->getPolylineVecObj(*(_mesh->getProjectName()))->getNameOfElement(ply, ply_name)) {
//		ply_name = "unknown-ply";
//	}
//
//	std::cout << "distances of linear nodes along polyline " << ply_name <<
//	" (epsilon radius = " << search_radius << "): " << "\n";
//	for (size_t k(0); k < _dist_of_proj_node_from_ply_start.size(); k++)
//		std::cout << "\t" << _msh_node_ids[k] << " " <<
//		_dist_of_proj_node_from_ply_start[k] << "\n";
//	std::cout << "number of linear nodes along polyline " << ply_name << ": " <<
//	_dist_of_proj_node_from_ply_start.size()
//	          << ", number of higher order nodes: " << msh_node_higher_order_ids.size() <<
//	"\n";
#endif
	// assign/append higher order nodes at the end of vector _msh_node_ids
	for (size_t k(0); k < msh_node_higher_order_ids.size(); k++)
		_msh_node_ids.push_back (msh_node_higher_order_ids[k]);
	// append distances for higher order nodes at the end of vector _dist_of_proj_node_from_ply_start
	for (size_t k(0); k < dist_of_proj_higher_order_node_from_ply_start.size(); k++)
		_dist_of_proj_node_from_ply_start.push_back(dist_of_proj_higher_order_node_from_ply_start[k]);
}