void GMem::consolidate_many_points( double tolerance ) { const double tolsqr = tolerance * tolerance; // build OctTree DLIList<GPoint*> point_list(pointListCount); GPoint* p_itor = pointList; GPoint* p_end = p_itor + pointListCount; while( p_itor < p_end ) point_list.append( p_itor++ ); OctTree<GPoint, GPointOctTreeEval> tree( point_list, tolerance ); point_list.clean_out(); // Consolidate the point list. index_map is used // to maintain a map between the old index of a point // (the index into index_map) and the new index of a // point (the value in index_map). int* index_map = new int[pointListCount]; GPoint* new_array = new GPoint[pointListCount]; int read, write = 0; for ( read = 0; read < pointListCount; read++) { GPoint* pt = pointList + read; CubitVector v(pt->x, pt->y, pt->z); index_map[read] = write; point_list.clean_out(); tree.nodes_near( v, point_list ); while ( point_list.size() ) { GPoint* p = point_list.pop(); int index = p - pointList; assert( (index >= 0) && (index < pointListCount) ); CubitVector v2(p->x, p->y, p->z); if ( (index < read) && ((v - v2).length_squared() < tolsqr) ) { index_map[read] = index_map[index]; break; } } if ( index_map[read] == write ) { new_array[write++] = pointList[read]; } } pointListCount = write; delete [] pointList; pointList = new_array; // Update the facet list using values from index_map. int *itor = facetList; const int* end = facetList + fListCount; while( itor < end ) for( int count = *(itor++); count--; itor++ ) *itor = index_map[*itor]; delete [] index_map; pointsConsolidated = CUBIT_TRUE; }
void MeshFunction::hessian (const Point& p, const Real, std::vector<Tensor>& output, const std::set<subdomain_id_type>* subdomain_ids) { libmesh_assert (this->initialized()); const Elem* element = this->find_element(p,subdomain_ids); if (!element) { output.resize(0); } else { // resize the output vector to the number of output values // that the user told us output.resize (this->_system_vars.size()); { const unsigned int dim = element->dim(); /* * Get local coordinates to feed these into compute_data(). * Note that the fe_type can safely be used from the 0-variable, * since the inverse mapping is the same for all FEFamilies */ const Point mapped_point (FEInterface::inverse_map (dim, this->_dof_map.variable_type(0), element, p)); std::vector<Point> point_list (1, mapped_point); // loop over all vars for (unsigned int index=0; index < this->_system_vars.size(); index++) { /* * the data for this variable */ const unsigned int var = _system_vars[index]; const FEType& fe_type = this->_dof_map.variable_type(var); UniquePtr<FEBase> point_fe (FEBase::build(dim, fe_type)); const std::vector<std::vector<RealTensor> >& d2phi = point_fe->get_d2phi(); point_fe->reinit(element, &point_list); // where the solution values for the var-th variable are stored std::vector<dof_id_type> dof_indices; this->_dof_map.dof_indices (element, dof_indices, var); // interpolate the solution Tensor hess; for (unsigned int i=0; i<dof_indices.size(); i++) hess.add_scaled(d2phi[i][0], this->_vector(dof_indices[i])); output[index] = hess; } } } // all done return; }
void MeshFunction::hessian (const Point& p, const Real, std::vector<Tensor>& output) { libmesh_assert (this->initialized()); /* Ensure that in the case of a master mesh function, the out-of-mesh mode is enabled either for both or for none. This is important because the out-of-mesh mode is also communicated to the point locator. Since this is time consuming, enable it only in debug mode. */ #ifdef DEBUG if (this->_master != NULL) { const MeshFunction* master = libmesh_cast_ptr<const MeshFunction*>(this->_master); if(_out_of_mesh_mode!=master->_out_of_mesh_mode) libmesh_error_msg("ERROR: If you use out-of-mesh-mode in connection with master mesh " \ << "functions, you must enable out-of-mesh mode for both the master and the slave mesh function."); } #endif // locate the point in the other mesh const Elem* element = this->_point_locator->operator()(p); // If we have an element, but it's not a local element, then we // either need to have a serialized vector or we need to find a // local element sharing the same point. if (element && (element->processor_id() != this->processor_id()) && _vector.type() != SERIAL) { // look for a local element containing the point std::set<const Elem*> point_neighbors; element->find_point_neighbors(p, point_neighbors); element = NULL; std::set<const Elem*>::const_iterator it = point_neighbors.begin(); const std::set<const Elem*>::const_iterator end = point_neighbors.end(); for (; it != end; ++it) { const Elem* elem = *it; if (elem->processor_id() == this->processor_id()) { element = elem; break; } } } if (!element) { output.resize(0); } else { // resize the output vector to the number of output values // that the user told us output.resize (this->_system_vars.size()); { const unsigned int dim = this->_eqn_systems.get_mesh().mesh_dimension(); /* * Get local coordinates to feed these into compute_data(). * Note that the fe_type can safely be used from the 0-variable, * since the inverse mapping is the same for all FEFamilies */ const Point mapped_point (FEInterface::inverse_map (dim, this->_dof_map.variable_type(0), element, p)); std::vector<Point> point_list (1, mapped_point); // loop over all vars for (unsigned int index=0; index < this->_system_vars.size(); index++) { /* * the data for this variable */ const unsigned int var = _system_vars[index]; const FEType& fe_type = this->_dof_map.variable_type(var); AutoPtr<FEBase> point_fe (FEBase::build(dim, fe_type)); const std::vector<std::vector<RealTensor> >& d2phi = point_fe->get_d2phi(); point_fe->reinit(element, &point_list); // where the solution values for the var-th variable are stored std::vector<dof_id_type> dof_indices; this->_dof_map.dof_indices (element, dof_indices, var); // interpolate the solution Tensor hess; for (unsigned int i=0; i<dof_indices.size(); i++) hess.add_scaled(d2phi[i][0], this->_vector(dof_indices[i])); output[index] = hess; } } } // all done return; }
void SpatiaLiteDB::queryGeometry( std::string table, std::string geometry_col, double left, double bottom, double right, double top, std::string label_col) { _pointlist.clear(); _linestringlist.clear(); _polygonlist.clear(); bool getLabel = label_col.size() != 0; // Search for geometry and name // The query will be either // // SELECT Geometry FROM table WHERE MbrWithin(Column, BuildMbr(left, bottom, right, top)); // or // SELECT Geometry,Label FROM table WHERE MbrWithin(Column, BuildMbr(left, bottom, right, top)); // // where Geometry is the geometry column name and Label is the column containing a name or label. std::string label; if (getLabel) { label = "," + label_col; } std::stringstream s; s << "SELECT " << geometry_col << label << " FROM " << table << " WHERE MbrIntersects(" << geometry_col << ", BuildMbr(" << left << "," << bottom << "," << right << "," << top << "));"; // prepare the query prepare(s.str()); // fetch the next result row while (step()) { // get the geometry gaiaGeomCollPtr geom = Geom(0); // get the label, if we asked for it std::string label; if (getLabel) { label = Text(1); } // the following will create lists for points, lines and polygons found in // a single geometry. In practice it seems that only one of those types // exists for a given geometry, but it's not clear if this is a requirement // or just occurs in the sample databases we have been working with. PointList points = point_list(geom, label); for (PointList::iterator i = points.begin(); i != points.end(); i++) { _pointlist.push_back(*i); } LinestringList lines = linestring_list(geom, label); for (LinestringList::iterator i = lines.begin(); i != lines.end(); i++) { _linestringlist.push_back(*i); } PolygonList polys = polygon_list(geom, label); for (PolygonList::iterator i = polys.begin(); i != polys.end(); i++) { _polygonlist.push_back(*i); } } // finish with this query finalize(); }