From 43d8f4fcb09feef0241c9f3f2d0ef82f16ea4773 Mon Sep 17 00:00:00 2001 From: Marc Fehling Date: Mon, 2 Nov 2020 18:51:36 -0700 Subject: [PATCH] Slim interface for DoFHandler initialization. --- .../changes/incompatibilities/20201030Fehling | 8 ++ include/deal.II/dofs/dof_handler.h | 25 ++++- source/dofs/dof_handler.cc | 97 ++++++++----------- 3 files changed, 70 insertions(+), 60 deletions(-) create mode 100644 doc/news/changes/incompatibilities/20201030Fehling diff --git a/doc/news/changes/incompatibilities/20201030Fehling b/doc/news/changes/incompatibilities/20201030Fehling new file mode 100644 index 0000000000..b3f765153e --- /dev/null +++ b/doc/news/changes/incompatibilities/20201030Fehling @@ -0,0 +1,8 @@ +Deprecated: The initialization interface for the DoFHandler class has +changed. DoFHandler::initialize() and DoFHandler::set_fe() have been +deprecated. Instead, use the constructor DoFHandler::DoFHandler(tria) or +DoFHandler::DoFHandler() followed by DoFHandler::reinit(tria) to attach +a Triangulation tria, and DoFHandler::distribute_dofs() to enumerate +degrees of freedom. +
+(Marc Fehling, 2020/10/30) diff --git a/include/deal.II/dofs/dof_handler.h b/include/deal.II/dofs/dof_handler.h index 91228ebebc..a535398f20 100644 --- a/include/deal.II/dofs/dof_handler.h +++ b/include/deal.II/dofs/dof_handler.h @@ -542,8 +542,7 @@ public: /** * Standard constructor, not initializing any data. After constructing an - * object with this constructor, use initialize() to make a valid - * DoFHandler. + * object with this constructor, use reinit() to get a valid DoFHandler. */ DoFHandler(); @@ -577,14 +576,20 @@ public: /** * Assign a Triangulation and a FiniteElement to the DoFHandler and compute * the distribution of degrees of freedom over the mesh. + * + * @deprecated Use reinit() and distribute_dofs() instead. */ + DEAL_II_DEPRECATED void initialize(const Triangulation &tria, const FiniteElement &fe); /** * Same as above but taking an hp::FECollection object. + * + * @deprecated Use reinit() and distribute_dofs() instead. */ + DEAL_II_DEPRECATED void initialize(const Triangulation & tria, const hp::FECollection &fe); @@ -609,13 +614,19 @@ public: * either not been distributed yet, or are distributed using a previously set * element. In both cases, accessing degrees of freedom will lead to invalid * results. To restore consistency, call distribute_dofs(). + * + * @deprecated Use distribute_dofs() instead. */ + DEAL_II_DEPRECATED void set_fe(const FiniteElement &fe); /** * Same as above but taking an hp::FECollection object. + * + * @deprecated Use distribute_dofs() instead. */ + DEAL_II_DEPRECATED void set_fe(const hp::FECollection &fe); @@ -634,6 +645,16 @@ public: void get_active_fe_indices(std::vector &active_fe_indices) const; + /** + * Assign a Triangulation to the DoFHandler. + * + * Remove all associations with the previous Triangulation object and + * establish connections with the new one. All information about previous + * degrees of freedom will be removed. Activates hp-mode. + */ + void + reinit(const Triangulation &tria); + /** * Go through the triangulation and "distribute" the degrees of * freedom needed for the given finite element. "Distributing" diff --git a/source/dofs/dof_handler.cc b/source/dofs/dof_handler.cc index d2e755e4e1..a57e987a64 100644 --- a/source/dofs/dof_handler.cc +++ b/source/dofs/dof_handler.cc @@ -2008,15 +2008,9 @@ DoFHandler::DoFHandler() template DoFHandler::DoFHandler(const Triangulation &tria) - : hp_capability_enabled(true) - , tria(&tria, typeid(*this).name()) - , mg_faces(nullptr) + : DoFHandler() { - this->setup_policy(); - - // provide all hp functionalities before finite elements are registered - this->connect_to_triangulation_signals(); - this->create_active_fe_table(); + reinit(tria); } @@ -2059,37 +2053,39 @@ void DoFHandler::initialize(const Triangulation &tria, const hp::FECollection &fe) { - if (hp_capability_enabled) - { - this->clear(); + this->reinit(tria); + this->distribute_dofs(fe); +} - if (this->tria != &tria) - { - // remove association with old triangulation - for (auto &connection : this->tria_listeners) - connection.disconnect(); - this->tria_listeners.clear(); - } - } - else - { - // this->faces = nullptr; - this->number_cache.n_global_dofs = 0; - } - if (this->tria != &tria) - { - // establish connection to new triangulation - this->tria = &tria; - this->setup_policy(); - - // start in hp-mode and let distribute_dofs toggle it if necessary - hp_capability_enabled = true; - this->connect_to_triangulation_signals(); - this->create_active_fe_table(); - } - this->distribute_dofs(fe); +template +void +DoFHandler::reinit(const Triangulation &tria) +{ + // + // call destructor + // + // remove association with old triangulation + for (auto &connection : this->tria_listeners) + connection.disconnect(); + this->tria_listeners.clear(); + + // release allocated memory and policy + DoFHandler::clear(); + this->policy.reset(); + + // + // call constructor + // + // establish connection to new triangulation + this->tria = &tria; + this->setup_policy(); + + // start in hp-mode and let distribute_dofs toggle it if necessary + hp_capability_enabled = true; + this->connect_to_triangulation_signals(); + this->create_active_fe_table(); } @@ -2681,17 +2677,9 @@ template void DoFHandler::clear() { - if (hp_capability_enabled) - { - // release memory - this->clear_space(); - } - else - { - // release memory - this->clear_space(); - this->clear_mg_space(); - } + // release memory + this->clear_space(); + this->clear_mg_space(); } @@ -2708,17 +2696,10 @@ DoFHandler::clear_space() object_dof_ptr.clear(); - if (hp_capability_enabled) - { - this->hp_cell_active_fe_indices.clear(); - this->hp_cell_active_fe_indices.shrink_to_fit(); - this->hp_cell_future_fe_indices.clear(); - this->hp_cell_future_fe_indices.shrink_to_fit(); - } - else - { - this->number_cache.clear(); - } + this->number_cache.clear(); + + this->hp_cell_active_fe_indices.clear(); + this->hp_cell_future_fe_indices.clear(); } -- 2.39.5