www.mooseframework.org
Namespaces | Functions | Variables
PolycrystalICTools.C File Reference

Go to the source code of this file.

Namespaces

 GraphColoring
 
 PolycrystalICTools
 

Functions

bool colorGraph (const PolycrystalICTools::AdjacencyMatrix< Real > &adjacency_matrix, std::vector< unsigned int > &colors, unsigned int n_vertices, unsigned int n_colors, unsigned int vertex)
 Backtracking graph coloring routines. More...
 
bool isGraphValid (const PolycrystalICTools::AdjacencyMatrix< Real > &adjacency_matrix, std::vector< unsigned int > &colors, unsigned int n_vertices, unsigned int vertex, unsigned int color)
 
void visitElementalNeighbors (const Elem *elem, const MeshBase &mesh, const PointLocatorBase &point_locator, const PeriodicBoundaries *pb, std::set< dof_id_type > &halo_ids)
 Utility routines. More...
 

Variables

const unsigned int GraphColoring::INVALID_COLOR = std::numeric_limits<unsigned int>::max()
 
const unsigned int PolycrystalICTools::HALO_THICKNESS = 4
 

Function Documentation

bool colorGraph ( const PolycrystalICTools::AdjacencyMatrix< Real > &  adjacency_matrix,
std::vector< unsigned int > &  colors,
unsigned int  n_vertices,
unsigned int  n_ops,
unsigned int  vertex 
)

Backtracking graph coloring routines.

Definition at line 406 of file PolycrystalICTools.C.

Referenced by PolycrystalICTools::assignOpsToGrains().

411 {
412  // Base case: All grains are assigned
413  if (vertex == n_vertices)
414  return true;
415 
416  // Consider this grain and try different ops
417  for (unsigned int color_idx = 0; color_idx < n_colors; ++color_idx)
418  {
419  // We'll try to spread these colors around a bit rather than
420  // packing them all on the first few colors if we have several colors.
421  unsigned int color = (vertex + color_idx) % n_colors;
422 
423  if (isGraphValid(adjacency_matrix, colors, n_vertices, vertex, color))
424  {
425  colors[vertex] = color;
426 
427  if (colorGraph(adjacency_matrix, colors, n_vertices, n_colors, vertex + 1))
428  return true;
429 
430  // Backtrack...
431  colors[vertex] = GraphColoring::INVALID_COLOR;
432  }
433  }
434 
435  return false;
436 }
bool isGraphValid(const PolycrystalICTools::AdjacencyMatrix< Real > &adjacency_matrix, std::vector< unsigned int > &colors, unsigned int n_vertices, unsigned int vertex, unsigned int color)
const unsigned int INVALID_COLOR
bool colorGraph(const PolycrystalICTools::AdjacencyMatrix< Real > &adjacency_matrix, std::vector< unsigned int > &colors, unsigned int n_vertices, unsigned int n_ops, unsigned int vertex)
Backtracking graph coloring routines.
bool isGraphValid ( const PolycrystalICTools::AdjacencyMatrix< Real > &  adjacency_matrix,
std::vector< unsigned int > &  colors,
unsigned int  n_vertices,
unsigned int  vertex,
unsigned int  color 
)

Definition at line 439 of file PolycrystalICTools.C.

Referenced by colorGraph().

444 {
445  // See if the proposed color is valid based on the current neighbor colors
446  for (unsigned int neighbor = 0; neighbor < n_vertices; ++neighbor)
447  if (adjacency_matrix(vertex, neighbor) && color == colors[neighbor])
448  return false;
449  return true;
450 }
void visitElementalNeighbors ( const Elem *  elem,
const MeshBase &  mesh,
const PointLocatorBase &  point_locator,
const PeriodicBoundaries *  pb,
std::set< dof_id_type > &  halo_ids 
)

Utility routines.

Definition at line 373 of file PolycrystalICTools.C.

Referenced by PolycrystalICTools::buildElementalGrainAdjacencyMatrix().

378 {
379  mooseAssert(elem, "Elem is NULL");
380 
381  std::vector<const Elem *> all_active_neighbors;
382 
383  // Loop over all neighbors (at the the same level as the current element)
384  for (unsigned int i = 0; i < elem->n_neighbors(); ++i)
385  {
386  const Elem * neighbor_ancestor = elem->topological_neighbor(i, mesh, point_locator, pb);
387  if (neighbor_ancestor)
388  // Retrieve only the active neighbors for each side of this element, append them to the list
389  // of active neighbors
390  neighbor_ancestor->active_family_tree_by_topological_neighbor(
391  all_active_neighbors, elem, mesh, point_locator, pb, false);
392  }
393 
394  // Loop over all active element neighbors
395  for (std::vector<const Elem *>::const_iterator neighbor_it = all_active_neighbors.begin();
396  neighbor_it != all_active_neighbors.end();
397  ++neighbor_it)
398  if (*neighbor_it)
399  halo_ids.insert((*neighbor_it)->id());
400 }