]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Introduce new constructors for NumberCache.
authorWolfgang Bangerth <bangerth@colostate.edu>
Sat, 24 Jun 2017 08:22:25 +0000 (02:22 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Mon, 26 Jun 2017 05:02:47 +0000 (23:02 -0600)
include/deal.II/dofs/number_cache.h
source/dofs/number_cache.cc

index 16c44d7e2c86f49f2ff7d4083f729d6e8f1fc438..bee2368e8336c912708c155ef26efc69c6eb0031 100644 (file)
@@ -51,6 +51,30 @@ namespace internal
        */
       NumberCache (NumberCache &&) = default;
 
+      /**
+       * Create a NumberCache object that corresponds to a sequential
+       * DoFHandler object in which a single processor stores all
+       * degrees of freedom.
+       */
+      NumberCache (const types::global_dof_index n_global_dofs);
+
+
+      /**
+       * Create a NumberCache object that corresponds to a parallel
+       * DoFHandler object with as many processors as the size of the
+       * given argument, in which each processor stores the degrees
+       * of freedom indicated in the corresponding element of the
+       * vector passed as first argument. The second argument indicates
+       * the rank among all participating processors the current
+       * processor has, so that we can set the @p locally_owned_dofs
+       * and @p n_locally_owned_dofs fields.
+       *
+       * All other fields stored by the current object can be and are computed
+       * from the argument.
+       */
+      NumberCache (const std::vector<IndexSet> &locally_owned_dofs_per_processor,
+                   const unsigned int           my_rank);
+
       /**
        * Copy operator. Simply copy all members of the referenced
        * object to the current object.
index ea16f3d0e884704fce125bd181fa498956768519..993a0c4811cc8dccb22c175a254974c31a3078d0 100644 (file)
@@ -16,6 +16,9 @@
 #include <deal.II/base/memory_consumption.h>
 #include <deal.II/dofs/number_cache.h>
 
+#include <numeric>
+
+
 DEAL_II_NAMESPACE_OPEN
 
 namespace internal
@@ -29,6 +32,44 @@ namespace internal
     {}
 
 
+
+    NumberCache::NumberCache (const types::global_dof_index n_global_dofs)
+      :
+      n_global_dofs (n_global_dofs),
+      n_locally_owned_dofs (n_global_dofs),
+      locally_owned_dofs (complete_index_set(n_global_dofs)),
+      n_locally_owned_dofs_per_processor (1, n_global_dofs),
+      locally_owned_dofs_per_processor (1, complete_index_set(n_global_dofs))
+    {}
+
+
+
+    NumberCache::NumberCache (const std::vector<IndexSet> &locally_owned_dofs_per_processor,
+                              const unsigned int           my_rank)
+      :
+      locally_owned_dofs_per_processor (locally_owned_dofs_per_processor)
+    {
+      const unsigned int n_procs = locally_owned_dofs_per_processor.size();
+
+      // compress IndexSet representation before using it for anything else
+      for (unsigned int p=0; p<n_procs; ++p)
+        locally_owned_dofs_per_processor[p].compress();
+
+      n_locally_owned_dofs_per_processor.resize (n_procs);
+      for (unsigned int p=0; p<n_procs; ++p)
+        n_locally_owned_dofs_per_processor[p]
+          = locally_owned_dofs_per_processor[p].n_elements();
+      n_locally_owned_dofs = n_locally_owned_dofs_per_processor[my_rank];
+      locally_owned_dofs = locally_owned_dofs_per_processor[my_rank];
+
+
+      n_global_dofs = std::accumulate (n_locally_owned_dofs_per_processor.begin(),
+                                       n_locally_owned_dofs_per_processor.end(),
+                                       types::global_dof_index(0));
+    }
+
+
+
     void NumberCache::clear ()
     {
       n_global_dofs = 0;

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.