75 vector < CellID > myNeighbors;
78 for (
const auto& [neighbor, dir] : grid.get_face_neighbors_of(
id)) {
79 if (cell.second == dimension + 1)
80 myNeighbors.push_back(cell.first);
85 switch( myNeighbors.size() ) {
94 neighbor = myNeighbors[0];
98 neighbor = myNeighbors[path];
104 throw "Invalid neighbor count!";
115 vector<CellID> ids, uint dimension,
118 const bool debug =
false;
120 uint
id = startingId;
121 uint startingRefLvl = grid.get_refinement_level(
id);
123 if( ids.size() == 0 )
124 ids.push_back(startingId);
131 if( startingRefLvl > path.size() ) {
132 for ( uint
i = path.size();
i < startingRefLvl;
i++) {
133 auto parent = grid.mapping.get_parent(
id);
135 std::array<uint64_t, 8> childrenarr = mpiGrid.mapping.get_all_children(parent);
136 vector<CellID> children(childrenarr.begin(), childrenarr.end());
137 auto it = std::find(children.begin(),children.end(),
id);
138 auto index = std::distance(children.begin(),it);
141 switch( dimension ) {
155 path.insert(path.begin(),index2);
169 if (nextNeighbor == 0)
172 uint refLvl = grid.get_refinement_level(nextNeighbor);
179 if ( path.size() >= refLvl ) {
182 std::cout <<
"I am cell " <<
id <<
". ";
183 std::cout <<
"I have seen refinement level " << refLvl <<
" before. Path is ";
184 for (
auto k = path.begin();
k != path.end(); ++
k)
185 std::cout << *
k <<
" ";
186 std::cout << std::endl;
194 std::cout <<
"I am cell " <<
id <<
". ";
195 std::cout <<
"I have NOT seen refinement level " << refLvl <<
" before. Path is ";
196 for (
auto k = path.begin();
k != path.end(); ++
k)
197 std::cout << *
k <<
' ';
198 std::cout << std::endl;
202 for ( uint
i : {0,1,2,3} ) {
204 vector < uint > myPath = path;
212 ids.push_back(nextNeighbor);
228 std::cout <<
"I am cell " <<
id <<
". ";
229 std::cout <<
" I am on refinement level 0." << std::endl;
236 std::cout <<
" Next neighbor is " << nextNeighbor <<
"." << std::endl;
238 ids.push_back(nextNeighbor);
247 const auto coordinates = grid.get_center(ids[0]);
286 pencils.addPencil(ids,x,y);
300int main(
int argc,
char* argv[]) {
302 if (MPI_Init(&argc, &argv) != MPI_SUCCESS) {
307 MPI_Comm comm = MPI_COMM_WORLD;
309 int rank = 0, comm_size = 0;
310 MPI_Comm_rank(comm, &rank);
311 MPI_Comm_size(comm, &comm_size);
313 dccrg::Dccrg<grid_data> grid;
319 const std::array<uint64_t, 3> grid_size = {{xDim,yDim,zDim}};
320 const int dimension = 0;
321 const bool doRefine =
true;
322 const std::array<uint,4> refinementIds = {{10,14,64,72}};
324 grid.initialize(grid_size, comm,
"RANDOM", 1);
326 typedef dccrg::Types<3>::neighborhood_item_t neigh_t;
327 std::vector<neigh_t> neighborhood_x;
328 std::vector<neigh_t> neighborhood_y;
330 int neighborhood_width = 2;
331 for (
int d = -neighborhood_width; d <= neighborhood_width; d++) {
333 neighborhood_x.push_back({{d, 0, 0}});
334 neighborhood_y.push_back({{0, d, 0}});
337 grid.add_neighborhood(1, neighborhood_x);
338 grid.add_neighborhood(2, neighborhood_y);
343 for(uint
i = 0;
i < refinementIds.size();
i++) {
344 if(refinementIds[
i] > 0) {
345 grid.refine_completely(refinementIds[
i]);
346 grid.stop_refining();
353 auto cells = grid.cells;
354 sort(cells.begin(), cells.end());
357 vector<CellID> startingIds;
359 for (
const auto& cell: cells) {
362 ids.push_back(cell.id);
365 vector<CellID> negativeNeighbors;
366 for (
auto neighbor : grid.get_face_neighbors_of(cell.id)) {
368 if (neighbor.second == - (dimension + 1))
369 negativeNeighbors.push_back(neighbor.first);
371 if (negativeNeighbors.size() == 0)
372 startingIds.push_back(cell.id);
375 std::cout <<
"Starting cell ids for pencils are ";
378 sort(ids.begin(),ids.end());
380 vector<CellID> idsInitial;
384 for (
auto id : startingIds) {
391 std::cout <<
"I have created " << pencils.N <<
" pencils along dimension " << dimension <<
":\n";
392 std::cout <<
"(x, y): indices " << std::endl;
393 std::cout <<
"-----------------------------------------------------------------" << std::endl;
394 for (uint
i = 0;
i < pencils.N;
i++) {
395 iend += pencils.lengthOfPencils[
i];
396 std::cout <<
"(" << pencils.x[
i] <<
", " << pencils.y[
i] <<
"): ";
397 for (
auto j = pencils.ids.begin() + ibeg;
j != pencils.ids.begin() + iend; ++
j) {
398 std::cout << *
j <<
" ";
401 std::cout << std::endl;
406 const vector<CellID>* neighbors = grid.get_neighbors_of(
id, 1);
407 if (neighbors != NULL) {
408 std::cout <<
"Neighbors of cell " <<
id << std::endl;
409 for (
auto neighbor : *neighbors) {
410 std::cout << neighbor << std::endl;
416 std::ofstream outfile;
418 grid.write_vtk_file(
"test.vtk");
420 outfile.open(
"test.vtk", std::ofstream::app);
422 outfile <<
"CELL_DATA " << cells.size() << std::endl;
423 outfile <<
"SCALARS id int 1" << std::endl;
424 outfile <<
"LOOKUP_TABLE default" << std::endl;
425 for (
const auto& cell: cells) {
426 outfile << cell.id << std::endl;