From cd0c52b12298c12a11331ba0be7870b8fd10744a Mon Sep 17 00:00:00 2001 From: Marc Fehling Date: Fri, 11 Mar 2022 20:18:17 -0700 Subject: [PATCH] cell_weight: fix bug with AMR in step-68. --- examples/step-68/step-68.cc | 37 +++++++++++++++++++------------------ tests/particles/step-68.cc | 37 +++++++++++++++++++------------------ 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/examples/step-68/step-68.cc b/examples/step-68/step-68.cc index a79f2f106f..bde1d7d5a4 100644 --- a/examples/step-68/step-68.cc +++ b/examples/step-68/step-68.cc @@ -350,27 +350,28 @@ namespace Step68 // should have the status `CELL_PERSIST`. However this function can also // be used to distribute load during refinement, therefore we consider // refined or coarsened cells as well. - if (status == parallel::distributed::Triangulation::CELL_PERSIST || - status == parallel::distributed::Triangulation::CELL_REFINE) + unsigned int n_particles_in_cell = 0; + switch (status) { - const unsigned int n_particles_in_cell = - particle_handler.n_particles_in_cell(cell); - return n_particles_in_cell * particle_weight; - } - else if (status == parallel::distributed::Triangulation::CELL_COARSEN) - { - unsigned int n_particles_in_cell = 0; - - for (unsigned int child_index = 0; child_index < cell->n_children(); - ++child_index) - n_particles_in_cell += - particle_handler.n_particles_in_cell(cell->child(child_index)); - - return n_particles_in_cell * particle_weight; + case parallel::distributed::Triangulation::CELL_PERSIST: + case parallel::distributed::Triangulation::CELL_REFINE: + n_particles_in_cell = particle_handler.n_particles_in_cell(cell); + break; + + case parallel::distributed::Triangulation::CELL_INVALID: + break; + + case parallel::distributed::Triangulation::CELL_COARSEN: + for (const auto &child : cell->child_iterators()) + n_particles_in_cell += particle_handler.n_particles_in_cell(child); + break; + + default: + Assert(false, ExcInternalError()); + break; } - Assert(false, ExcInternalError()); - return 0; + return base_weight + particle_weight * n_particles_in_cell; } diff --git a/tests/particles/step-68.cc b/tests/particles/step-68.cc index 72713fbc65..544f59feed 100644 --- a/tests/particles/step-68.cc +++ b/tests/particles/step-68.cc @@ -278,27 +278,28 @@ namespace Step68 // should have the status `CELL_PERSIST`. However this function can also // be used to distribute load during refinement, therefore we consider // refined or coarsened cells as well. - if (status == parallel::distributed::Triangulation::CELL_PERSIST || - status == parallel::distributed::Triangulation::CELL_REFINE) + unsigned int n_particles_in_cell = 0; + switch (status) { - const unsigned int n_particles_in_cell = - particle_handler.n_particles_in_cell(cell); - return n_particles_in_cell * particle_weight; - } - else if (status == parallel::distributed::Triangulation::CELL_COARSEN) - { - unsigned int n_particles_in_cell = 0; - - for (unsigned int child_index = 0; child_index < cell->n_children(); - ++child_index) - n_particles_in_cell += - particle_handler.n_particles_in_cell(cell->child(child_index)); - - return n_particles_in_cell * particle_weight; + case parallel::distributed::Triangulation::CELL_PERSIST: + case parallel::distributed::Triangulation::CELL_REFINE: + n_particles_in_cell = particle_handler.n_particles_in_cell(cell); + break; + + case parallel::distributed::Triangulation::CELL_INVALID: + break; + + case parallel::distributed::Triangulation::CELL_COARSEN: + for (const auto &child : cell->child_iterators()) + n_particles_in_cell += particle_handler.n_particles_in_cell(child); + break; + + default: + Assert(false, ExcInternalError()); + break; } - Assert(false, ExcInternalError()); - return 0; + return base_weight + particle_weight * n_particles_in_cell; } -- 2.39.5