https://mooseframework.inl.gov
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

◆ colorGraph()

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 401 of file PolycrystalICTools.C.

Referenced by PolycrystalICTools::assignOpsToGrains().

406 {
407  // Base case: All grains are assigned
408  if (vertex == n_vertices)
409  return true;
410 
411  // Consider this grain and try different ops
412  for (unsigned int color_idx = 0; color_idx < n_colors; ++color_idx)
413  {
414  // We'll try to spread these colors around a bit rather than
415  // packing them all on the first few colors if we have several colors.
416  unsigned int color = (vertex + color_idx) % n_colors;
417 
418  if (isGraphValid(adjacency_matrix, colors, n_vertices, vertex, color))
419  {
420  colors[vertex] = color;
421 
422  if (colorGraph(adjacency_matrix, colors, n_vertices, n_colors, vertex + 1))
423  return true;
424 
425  // Backtrack...
426  colors[vertex] = GraphColoring::INVALID_COLOR;
427  }
428  }
429 
430  return false;
431 }
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.

◆ isGraphValid()

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 434 of file PolycrystalICTools.C.

Referenced by colorGraph().

439 {
440  // See if the proposed color is valid based on the current neighbor colors
441  for (unsigned int neighbor = 0; neighbor < n_vertices; ++neighbor)
442  if (adjacency_matrix(vertex, neighbor) && color == colors[neighbor])
443  return false;
444  return true;
445 }

◆ visitElementalNeighbors()

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 368 of file PolycrystalICTools.C.

Referenced by PolycrystalICTools::buildElementalGrainAdjacencyMatrix().

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