21 "field the result of a partitioning operation");
26 "Handle to a GraphPartitioner object to use for parallel partitioning.");
30 "Handle to, or name of, the field function that should "
31 "receive the result of the operation.");
35 "num_partitions",
"Number of parts to apply to the partitioning");
40 "Resulting component into which the result will be written.");
47 partitioner_(
Chi::GetStackItem<
chi::GraphPartitioner>(
49 params.GetParamValue<size_t>(
"partitioner"),
51 result_field_param_(params.GetParam(
"result_field")),
52 num_partitions_(params.GetParamValue<size_t>(
"num_partitions")),
53 result_component_(params.GetParamValue<size_t>(
"result_component"))
59 std::shared_ptr<FieldFunctionGridBased> grid_ff_ptr;
63 auto ff_ptr = Chi::GetStackItemPtrAsType<FieldFunction>(
65 grid_ff_ptr = std::dynamic_pointer_cast<FieldFunctionGridBased>(ff_ptr);
69 "Could not cast field function to FieldFunctionGridBased");
75 if (ff_ptr->TextName() == ff_name)
77 grid_ff_ptr = std::dynamic_pointer_cast<FieldFunctionGridBased>(ff_ptr);
81 "Could not cast field function to FieldFunctionGridBased");
86 not grid_ff_ptr,
"Could not find the associated resulting field function");
89 const auto& sdm = grid_ff_ptr->GetSpatialDiscretization();
90 const auto& grid = sdm.Grid();
92 typedef std::vector<uint64_t> CellGraphNode;
93 typedef std::vector<CellGraphNode> CellGraph;
95 std::vector<chi_mesh::Vector3> cell_centroids;
97 const size_t num_local_cells = grid.local_cells.size();
99 cell_graph.reserve(num_local_cells);
100 cell_centroids.reserve(num_local_cells);
102 for (
const auto& cell : grid.local_cells)
104 CellGraphNode cell_graph_node;
105 for (
const auto& face : cell.faces_)
106 if (face.has_neighbor_) cell_graph_node.push_back(face.neighbor_id_);
108 cell_graph.push_back(cell_graph_node);
109 cell_centroids.push_back(cell.centroid_);
117 auto& local_data = grid_ff_ptr->FieldVector();
118 const auto& uk_man = grid_ff_ptr->GetUnknownManager();
120 for (
const auto& cell : grid.local_cells)
122 const auto& cell_mapping = sdm.GetCellMapping(cell);
123 const size_t num_nodes = cell_mapping.NumNodes();
125 const int64_t cell_pid = cell_pids.at(cell.local_id_);
127 for (uint32_t i = 0; i < num_nodes; ++i)
129 const int64_t dof_map =
132 local_data[dof_map] =
static_cast<double>(cell_pid);
#define ChiLogicalErrorIf(condition, message)
#define ChiInvalidArgumentIf(condition, message)
static std::vector< chi_physics::FieldFunctionPtr > field_function_stack
virtual std::vector< int64_t > Partition(const std::vector< std::vector< uint64_t > > &graph, const std::vector< chi_mesh::Vector3 > ¢roids, int number_of_parts)=0
ParameterBlockType Type() const
static chi::InputParameters GetInputParameters()
const chi::ParameterBlock result_field_param_
static chi::InputParameters GetInputParameters()
const size_t result_component_
PartitionerPredicate(const chi::InputParameters ¶ms)
chi::GraphPartitioner & partitioner_
const size_t num_partitions_
RegisterChiObject(chi_physics::field_operations, FieldCopyOperation)