From 4887eacdb96b65a7ce43b81382823af87c3f094c Mon Sep 17 00:00:00 2001 From: Daniel Garcia-Sanchez Date: Fri, 26 Apr 2019 18:07:05 +0200 Subject: [PATCH] Use the function n_locally_owned_active_cells() --- examples/step-18/step-18.cc | 41 +++++++++++++++---------------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/examples/step-18/step-18.cc b/examples/step-18/step-18.cc index cef0f64dde..1d0c795274 100644 --- a/examples/step-18/step-18.cc +++ b/examples/step-18/step-18.cc @@ -1608,40 +1608,33 @@ namespace Step18 template void TopLevel::setup_quadrature_point_history() { - // What we need to do here is to first count how many quadrature points - // are within the responsibility of this processor. This, of course, - // equals the number of cells that belong to this processor times the - // number of quadrature points our quadrature formula has on each cell. - // - // For good measure, we also set all user pointers of all cells, whether + // For good measure, we set all user pointers of all cells, whether // ours of not, to the null pointer. This way, if we ever access the user // pointer of a cell which we should not have accessed, a segmentation // fault will let us know that this should not have happened: - unsigned int our_cells = 0; - for (auto cell : triangulation.active_cell_iterators()) - if (cell->is_locally_owned()) - ++our_cells; triangulation.clear_user_data(); - // Next, allocate as many quadrature objects as we need. Since the - // resize function does not actually shrink the amount of - // allocated memory if the requested new size is smaller than the old - // size, we resort to a trick to first free all memory, and then - // reallocate it: we declare an empty vector as a temporary variable and - // then swap the contents of the old vector and this temporary - // variable. This makes sure that the - // quadrature_point_history is now really empty, and we can - // let the temporary variable that now holds the previous contents of the - // vector go out of scope and be destroyed. In the next step. we can then - // re-allocate as many elements as we need, with the vector - // default-initializing the PointHistory objects, which - // includes setting the stress variables to zero. + // Next, allocate the quadrature objects that are within the responsibility + // of this processor. This, of course, equals the number of cells that + // belong to this processor times the number of quadrature points our + // quadrature formula has on each cell. Since the `resize()` function does + // not actually shrink the amount of allocated memory if the requested new + // size is smaller than the old size, we resort to a trick to first free all + // memory, and then reallocate it: we declare an empty vector as a temporary + // variable and then swap the contents of the old vector and this temporary + // variable. This makes sure that the `quadrature_point_history` is now + // really empty, and we can let the temporary variable that now holds the + // previous contents of the vector go out of scope and be destroyed. In the + // next step we can then re-allocate as many elements as we need, with the + // vector default-initializing the `PointHistory` objects, which includes + // setting the stress variables to zero. { std::vector> tmp; quadrature_point_history.swap(tmp); } - quadrature_point_history.resize(our_cells * quadrature_formula.size()); + quadrature_point_history.resize( + triangulation.n_locally_owned_active_cells() * quadrature_formula.size()); // Finally loop over all cells again and set the user pointers from the // cells that belong to the present processor to point to the first -- 2.39.5