// create buffer to hold copy of eeprom points in RAM // returns nullptr if not enough memory can be allocated void* AC_PolyFence_loader::create_point_array(uint8_t element_size) { uint32_t array_size = max_points() * element_size; if (hal.util->available_memory() < 100U + array_size) { // too risky to enable as we could run out of stack return nullptr; } return calloc(1, array_size); }
// save a fence point to eeprom, returns true on successful save bool AC_PolyFence_loader::save_point_to_eeprom(uint16_t i, const Vector2l& point) { // sanity check index if (i >= max_points()) { return false; } // write point to eeprom fence_storage.write_uint32(i * sizeof(Vector2l), point.x); fence_storage.write_uint32(i * sizeof(Vector2l)+sizeof(uint32_t), point.y); return true; }
// load boundary point from eeprom, returns true on successful load bool AC_PolyFence_loader::load_point_from_eeprom(uint16_t i, Vector2l& point) { // sanity check index if (i >= max_points()) { return false; } // read fence point point.x = fence_storage.read_uint32(i * sizeof(Vector2l)); point.y = fence_storage.read_uint32(i * sizeof(Vector2l) + sizeof(uint32_t)); return true; }
void GrainTracker::buildBoundingSpheres() { // Don't track grains if the current simulation step is before the specified tracking step if (_t_step < _tracking_step) return; MeshBase & mesh = _mesh.getMesh(); unsigned long total_node_count = 0; for (unsigned int map_num = 0; map_num < _maps_size; ++map_num) { /** * Create a pair of vectors of real values that is 3 (for the x,y,z components) times * the length of the current _bubble_sets length. Each processor will update the * vector for the nodes that it owns (parallel_mesh case). Then a parallel exchange * will all for the global min/maxs of each bubble. */ std::vector<Real> min_points(_bubble_sets[map_num].size()*3, std::numeric_limits<Real>::max()); std::vector<Real> max_points(_bubble_sets[map_num].size()*3, -std::numeric_limits<Real>::max()); unsigned int set_counter = 0; for (std::list<BubbleData>::const_iterator it1 = _bubble_sets[map_num].begin(); it1 != _bubble_sets[map_num].end(); ++it1) { total_node_count += it1->_entity_ids.size(); // Find the min/max of our bounding box to calculate our bounding sphere for (std::set<dof_id_type>::iterator it2 = it1->_entity_ids.begin(); it2 != it1->_entity_ids.end(); ++it2) { Point point; Point * p_ptr = NULL; if (_is_elemental) { Elem *elem = mesh.query_elem(*it2); if (elem) { point = elem->centroid(); p_ptr = &point; } } else p_ptr = mesh.query_node_ptr(*it2); if (p_ptr) for (unsigned int i = 0; i < mesh.spatial_dimension(); ++i) { min_points[set_counter*3+i] = std::min(min_points[set_counter*3+i], (*p_ptr)(i)); max_points[set_counter*3+i] = std::max(max_points[set_counter*3+i], (*p_ptr)(i)); } } ++set_counter; } _communicator.min(min_points); _communicator.max(max_points); set_counter = 0; for (std::list<BubbleData>::const_iterator it1 = _bubble_sets[map_num].begin(); it1 != _bubble_sets[map_num].end(); ++it1) { Point min(min_points[set_counter*3], min_points[set_counter*3+1], min_points[set_counter*3+2]); Point max(max_points[set_counter*3], max_points[set_counter*3+1], max_points[set_counter*3+2]); // Calulate our bounding sphere Point center(min + ((max - min) / 2.0)); // The radius is the different between the outer edge of the "bounding box" // and the center plus the "hull buffer" value Real radius = (max - center).size() + _hull_buffer; unsigned int some_node_id = *(it1->_entity_ids.begin()); _bounding_spheres[map_num].push_back(new BoundingSphereInfo(some_node_id, center, radius)); ++set_counter; } } }