https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Namespaces | Functions | Variables
PolycrystalICTools.C File Reference

Go to the source code of this file.

Namespaces

namespace  GraphColoring
 
namespace  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.
 
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.
 

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

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

Referenced by PolycrystalICTools::assignOpsToGrains(), and colorGraph().

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

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

Referenced by colorGraph().

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

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