From: Peter Munch Date: Thu, 4 Feb 2021 10:17:34 +0000 (+0100) Subject: Enable AffineConstraints::copy_from for mixed number (double/float) X-Git-Tag: v9.3.0-rc1~499^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F11678%2Fhead;p=dealii.git Enable AffineConstraints::copy_from for mixed number (double/float) --- diff --git a/doc/news/changes/minor/20210205Munch b/doc/news/changes/minor/20210205Munch new file mode 100644 index 0000000000..8f82d8d383 --- /dev/null +++ b/doc/news/changes/minor/20210205Munch @@ -0,0 +1,5 @@ +Improved: AffineConstraints::copy_from() now also works for differing +number template types. +
+(Peter Munch, Maximilian Bergbauer, 2021/02/05) + diff --git a/include/deal.II/lac/affine_constraints.h b/include/deal.II/lac/affine_constraints.h index eede1cc32b..93f242cdb5 100644 --- a/include/deal.II/lac/affine_constraints.h +++ b/include/deal.II/lac/affine_constraints.h @@ -594,8 +594,9 @@ public: * This function exists because @p operator=() is explicitly * disabled. */ + template void - copy_from(const AffineConstraints &other); + copy_from(const AffineConstraints &other); /** * clear() the AffineConstraints object and supply an IndexSet with lines @@ -1597,6 +1598,26 @@ public: */ number inhomogeneity; + /** + * Default constructor. + */ + ConstraintLine(const size_type &index = numbers::invalid_dof_index, + const Entries & entries = {}, + const number & inhomogeneity = 0.0); + + /** + * Copy constructor. + */ + template + ConstraintLine(const ConstraintLineType &other); + + /** + * Copy assignment. + */ + template + ConstraintLine & + operator=(const ConstraintLineType &other); + /** * This operator is a bit weird and unintuitive: it compares the line * numbers of two lines. We need this to sort the lines; in fact we could @@ -1797,6 +1818,9 @@ public: << "that every processor who owns a DoF that constrains " << "another DoF also knows about this constraint?"); + template + friend class AffineConstraints; + private: /** * Store the lines of the matrix. Entries are usually appended in an @@ -2394,6 +2418,22 @@ namespace internal } // namespace internal + +template +template +inline void +AffineConstraints::copy_from( + const AffineConstraints &other) +{ + lines.clear(); + lines.insert(lines.begin(), other.lines.begin(), other.lines.end()); + lines_cache = other.lines_cache; + local_lines = other.local_lines; + sorted = other.sorted; +} + + + template template inline void @@ -2467,6 +2507,51 @@ AffineConstraints::add_entries_local_to_global( SparsityPatternType>::value>()); } + + +template +inline AffineConstraints::ConstraintLine::ConstraintLine( + const size_type & index, + const typename AffineConstraints::ConstraintLine::Entries &entries, + const number &inhomogeneity) + : index(index) + , entries(entries) + , inhomogeneity(inhomogeneity) +{} + + + +template +template +inline AffineConstraints::ConstraintLine::ConstraintLine( + const ConstraintLineType &other) +{ + this->index = other.index; + + entries.clear(); + entries.insert(entries.begin(), other.entries.begin(), other.entries.end()); + + this->inhomogeneity = other.inhomogeneity; +} + + + +template +template +inline typename AffineConstraints::ConstraintLine & +AffineConstraints::ConstraintLine:: +operator=(const ConstraintLineType &other) +{ + this->index = other.index; + + entries.clear(); + entries.insert(entries.begin(), other.entries.begin(), other.entries.end()); + + this->inhomogeneity = other.inhomogeneity; + + return *this; +} + DEAL_II_NAMESPACE_CLOSE #endif diff --git a/include/deal.II/lac/affine_constraints.templates.h b/include/deal.II/lac/affine_constraints.templates.h index 4d0c728c8c..28d4eca745 100644 --- a/include/deal.II/lac/affine_constraints.templates.h +++ b/include/deal.II/lac/affine_constraints.templates.h @@ -62,18 +62,6 @@ DEAL_II_NAMESPACE_OPEN -template -void -AffineConstraints::copy_from(const AffineConstraints &other) -{ - lines = other.lines; - lines_cache = other.lines_cache; - local_lines = other.local_lines; - sorted = other.sorted; -} - - - template bool AffineConstraints::ConstraintLine:: diff --git a/tests/lac/constraints_copy_from_mixed.cc b/tests/lac/constraints_copy_from_mixed.cc new file mode 100644 index 0000000000..921de11195 --- /dev/null +++ b/tests/lac/constraints_copy_from_mixed.cc @@ -0,0 +1,63 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2021 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + +// Test AffineConstraints::copy_from() for different types (float, double). + +#include + +#include + +#include "../tests.h" + +template +void +test() +{ + AffineConstraints constraints; + + constraints.add_line(1); + constraints.add_entry(1, 2, 1.); + constraints.add_entry(1, 3, 1.); + + constraints.add_line(3); + constraints.add_entry(3, 4, 1.); + constraints.add_entry(3, 5, 1.); + + constraints.add_line(5); + constraints.add_entry(5, 0, 1.); + + constraints.close(); + + AffineConstraints constraints_float; + + constraints_float.copy_from(constraints); + + constraints.print(deallog.get_file_stream()); + deallog << std::endl; + constraints_float.print(deallog.get_file_stream()); + deallog << std::endl; +} + +int +main() +{ + initlog(); + deallog << std::setprecision(2); + + test(); + test(); + test(); + test(); +} diff --git a/tests/lac/constraints_copy_from_mixed.output b/tests/lac/constraints_copy_from_mixed.output new file mode 100644 index 0000000000..cf81ab1bed --- /dev/null +++ b/tests/lac/constraints_copy_from_mixed.output @@ -0,0 +1,57 @@ + + 1 0: 1.00000 + 1 2: 1.00000 + 1 4: 1.00000 + 3 0: 1.00000 + 3 4: 1.00000 + 5 0: 1.00000 +DEAL:: + 1 0: 1.00000 + 1 2: 1.00000 + 1 4: 1.00000 + 3 0: 1.00000 + 3 4: 1.00000 + 5 0: 1.00000 +DEAL:: + 1 0: 1.00000 + 1 2: 1.00000 + 1 4: 1.00000 + 3 0: 1.00000 + 3 4: 1.00000 + 5 0: 1.00000 +DEAL:: + 1 0: 1.00000 + 1 2: 1.00000 + 1 4: 1.00000 + 3 0: 1.00000 + 3 4: 1.00000 + 5 0: 1.00000 +DEAL:: + 1 0: 1.00000 + 1 2: 1.00000 + 1 4: 1.00000 + 3 0: 1.00000 + 3 4: 1.00000 + 5 0: 1.00000 +DEAL:: + 1 0: 1.00000 + 1 2: 1.00000 + 1 4: 1.00000 + 3 0: 1.00000 + 3 4: 1.00000 + 5 0: 1.00000 +DEAL:: + 1 0: 1.00000 + 1 2: 1.00000 + 1 4: 1.00000 + 3 0: 1.00000 + 3 4: 1.00000 + 5 0: 1.00000 +DEAL:: + 1 0: 1.00000 + 1 2: 1.00000 + 1 4: 1.00000 + 3 0: 1.00000 + 3 4: 1.00000 + 5 0: 1.00000 +DEAL::