From 9800ab670f526b1f90076ce17d2267473bae2c59 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 11 Apr 2018 21:23:24 -0600 Subject: [PATCH] Minor cleanup and documentation of code. --- source/distributed/tria.cc | 58 +++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/source/distributed/tria.cc b/source/distributed/tria.cc index 1b977c4305..fd52ba428e 100644 --- a/source/distributed/tria.cc +++ b/source/distributed/tria.cc @@ -609,13 +609,18 @@ namespace } else if (!p4est_has_children && !dealii_cell->has_children()) { - //this active cell didn't change + // this active cell didn't change typename internal::p4est::types::quadrant *q; q = static_cast::quadrant *> ( sc_array_index (const_cast(&tree.quadrants), idx) ); *static_cast::CellStatus *>(q->p.user_data) = parallel::distributed::Triangulation::CELL_PERSIST; + // double check the condition that we will only ever attach data + // to active cells when we get here + Assert (dealii_cell->active(), ExcInternalError()); + + // call all callbacks for (typename callback_list_t::const_iterator it = attached_data_pack_callbacks.begin(); it != attached_data_pack_callbacks.end(); ++it) @@ -628,9 +633,10 @@ namespace } else if (p4est_has_children) { - //this cell got refined + // this cell got refined in p4est, but the dealii_cell has not yet been + // refined - //attach to the first child, because we can only attach to active + // attach to the first child, because we can only attach to active // quadrants typename internal::p4est::types::quadrant p4est_child[GeometryInfo::max_children_per_cell]; @@ -660,18 +666,25 @@ namespace ); *static_cast::CellStatus *>(q->p.user_data) = parallel::distributed::Triangulation::CELL_REFINE; + // double check the condition that we will only ever attach data + // to active cells when we get here + Assert (dealii_cell->active(), ExcInternalError()); + + // call all callbacks for (typename callback_list_t::const_iterator it = attached_data_pack_callbacks.begin(); it != attached_data_pack_callbacks.end(); ++it) { - void *ptr = static_cast(q->p.user_data) + (*it).first; //add offset + // compute the address where this particular callback is allowed + // to write its data, using the correct offset + void *ptr = static_cast(q->p.user_data) + (*it).first; ((*it).second)(dealii_cell, parallel::distributed::Triangulation::CELL_REFINE, ptr); } - //mark other children as invalid, so that unpack only happens once + // mark other children as invalid, so that unpack only happens once for (unsigned int i=1; i::max_children_per_cell; ++i) { int child_idx = sc_array_bsearch(const_cast(&tree.quadrants), @@ -687,13 +700,23 @@ namespace } else { - //its children got coarsened into this cell + // its children got coarsened into this cell in p4est, but the dealii_cell + // still has its children typename internal::p4est::types::quadrant *q; q = static_cast::quadrant *> ( sc_array_index (const_cast(&tree.quadrants), idx) ); *static_cast::CellStatus *>(q->p.user_data) = parallel::distributed::Triangulation::CELL_COARSEN; + // double check the condition that we will only ever attach data + // to cells with children when we get here. however, we can + // only tolerate one level of coarsening at a time, so check + // that the children are all active + Assert (dealii_cell->active() == false, ExcInternalError()); + for (unsigned int c=0; c::max_children_per_cell; ++c) + Assert (dealii_cell->child(c)->active(), ExcInternalError()); + + // then call all callbacks for (typename callback_list_t::const_iterator it = attached_data_pack_callbacks.begin(); it != attached_data_pack_callbacks.end(); ++it) @@ -1804,12 +1827,16 @@ namespace parallel dealii::internal::p4est::functions::save(filename, parallel_forest, attached_data_size>0); - dealii::parallel::distributed::Triangulation *tria - = const_cast*>(this); + // clear all of the callback data, as explained in the documentation of + // register_data_attach() + { + dealii::parallel::distributed::Triangulation *tria + = const_cast*>(this); - tria->n_attached_datas = 0; - tria->attached_data_size = 0; - tria->attached_data_pack_callbacks.clear(); + tria->n_attached_datas = 0; + tria->attached_data_size = 0; + tria->attached_data_pack_callbacks.clear(); + } // and release the data void *userptr = parallel_forest->user_pointer; @@ -1858,6 +1885,8 @@ namespace parallel "save() when using p4est 0.3.4.2.")); #endif + // clear all of the callback data, as explained in the documentation of + // register_data_attach() attached_data_size = 0; n_attached_datas = 0; n_attached_deserialize = attached_count; @@ -3213,10 +3242,11 @@ namespace parallel Assert(attached_data_pack_callbacks.size()==n_attached_datas, ExcMessage("register_data_attach(), not all data has been unpacked last time?")); - unsigned int offset = attached_data_size+sizeof(CellStatus); + const unsigned int offset = attached_data_size+sizeof(CellStatus); ++n_attached_datas; - attached_data_size+=size; + attached_data_size += size; attached_data_pack_callbacks.emplace_back(offset, pack_callback); + return offset; } @@ -3279,7 +3309,7 @@ namespace parallel // tests/mpi/p4est_save_03 with more than one SolutionTransfer. if (!n_attached_datas && n_attached_deserialize == 0) { - // everybody got his data, time for cleanup! + // everybody got their data, time for cleanup! attached_data_size = 0; attached_data_pack_callbacks.clear(); -- 2.39.5