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

Referenced by PolycrystalICTools::assignOpsToGrains().

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

Referenced by colorGraph().

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

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

Referenced by PolycrystalICTools::buildElementalGrainAdjacencyMatrix().

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