Commits

Anders Logg committed 9a2f732

Compute sparsity pattern for CCFEM function space

  • Participants
  • Parent commits 2abca6b

Comments (0)

Files changed (7)

dolfin/fem/CCFEMAssembler.cpp

 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
 //
 // First added:  2013-09-12
-// Last changed: 2013-09-18
+// Last changed: 2013-09-19
 
 #include <dolfin/log/log.h>
 #include <dolfin/la/GenericTensor.h>
 //-----------------------------------------------------------------------------
 void CCFEMAssembler::init_global_tensor(GenericTensor& A, const CCFEMForm& a)
 {
+  log(PROGRESS, "Initializing global tensor.");
+
   // This function initializes the big system matrix corresponding to
   // all dofs (including inactive dofs) on all parts of the CCFEM
   // function space.

dolfin/fem/CCFEMDofMap.cpp

   return _dofmaps[i];
 }
 //-----------------------------------------------------------------------------
+void CCFEMDofMap::set_current_part(std::size_t part) const
+{
+  dolfin_assert(part < num_parts());
+  _current_part = part; // mutable
+}
+//-----------------------------------------------------------------------------
 void CCFEMDofMap::add(boost::shared_ptr<const GenericDofMap> dofmap)
 {
   _dofmaps.push_back(dofmap);
 const std::vector<dolfin::la_index>&
 CCFEMDofMap::cell_dofs(std::size_t cell_index) const
 {
-  dolfin_assert(cell_index < _dofmap.size());
+  dolfin_assert(cell_index < _dofmap[_current_part].size());
   return _dofmap[_current_part][cell_index];
 }
 //-----------------------------------------------------------------------------

dolfin/fem/CCFEMDofMap.h

     ///         Dofmap (part) number i
     boost::shared_ptr<const GenericDofMap> part(std::size_t i) const;
 
+    /// Set current part. This will make the CCFEM dofmap act as a
+    /// dofmap for the part of the CCFEM function space defined on the
+    /// current part (mesh).
+    ///
+    /// *Arguments*
+    ///     part (std::size_t)
+    ///         The number of the part.
+    void set_current_part(std::size_t part) const;
+
     /// Add dofmap (shared pointer version)
     ///
     /// *Arguments*
     std::vector<boost::shared_ptr<const GenericDofMap> > _dofmaps;
 
     // Current part (mesh)
-    std::size_t _current_part;
+    mutable std::size_t _current_part;
 
     // Local-to-global dof map for all parts
     std::vector<std::vector<std::vector<dolfin::la_index> > > _dofmap;

dolfin/fem/SparsityPatternBuilder.cpp

 // Modified by Anders Logg 2008-2011
 //
 // First added:  2007-05-24
-// Last changed: 2013-09-18
+// Last changed: 2013-09-19
 
 #include <dolfin/common/timing.h>
 #include <dolfin/common/MPI.h>
 #include <dolfin/mesh/Cell.h>
 #include <dolfin/mesh/Facet.h>
 #include <dolfin/mesh/Mesh.h>
+#include <dolfin/function/FunctionSpace.h>
 #include <dolfin/function/CCFEMFunctionSpace.h>
 #include "CCFEMForm.h"
-#include "GenericDofMap.h"
+#include "CCFEMDofMap.h"
 #include "SparsityPatternBuilder.h"
 
 #include <dolfin/log/dolfin_log.h>
 void SparsityPatternBuilder::build_ccfem(GenericSparsityPattern& sparsity_pattern,
                                          const CCFEMForm& form)
 {
-  // FIXME: This is work in progress. Only building the simplest
-  // possible sparsity pattern for now.
-
-  // Get global dimensions and local range
-  std::vector<std::size_t> global_dimensions;
-  std::vector<std::pair<std::size_t, std::size_t> > local_ranges;
-  std::vector<const boost::unordered_map<std::size_t, unsigned int>* > off_process_owner;
+  // Build list of dofmaps
+  std::vector<const GenericDofMap*> dofmaps;
   for (std::size_t i = 0; i < form.rank(); i++)
-  {
-    boost::shared_ptr<const CCFEMFunctionSpace> V = form.function_space(i);
-    dolfin_assert(V);
+    dofmaps.push_back(&*form.function_space(i)->dofmap());
 
-    global_dimensions.push_back(V->dim());
-    local_ranges.push_back(std::make_pair(0, V->dim())); // FIXME: not parallel
-    off_process_owner.push_back(0);                      // FIXME: not parallel
-  }
-
-  // Initialize sparsity pattern
-  sparsity_pattern.init(global_dimensions, local_ranges, off_process_owner);
-
-  // Only build for rank >= 2 (matrices and higher order tensors) that
-  // require sparsity details
-  if (form.rank() < 2)
-    return;
-
-
-  /*
-  // Create vector to point to dofs
-  std::vector<const std::vector<dolfin::la_index>* > dofs(rank);
-
-  // Iterate over the parts of the CCFEM function space
+  // Iterate over each part
   for (std::size_t part = 0; part < form.num_parts(); part++)
   {
-    for (CellIterator cell(mesh); !cell.end(); ++cell)
-    {
-      // Tabulate dofs for each dimension and get local dimensions
-      for (std::size_t i = 0; i < rank; ++i)
-        dofs[i] = &dofmaps[i]->cell_dofs(cell->index());
+    // Set current part for each dofmap. Note that these will be the
+    // same dofmaps as in the list created above but accessed here as
+    // CCFEMDofMaps and not GenericDofMaps.
+    for (std::size_t i = 0; i < form.rank(); i++)
+      form.function_space(i)->dofmap()->set_current_part(part);
 
-      // Insert non-zeroes in sparsity pattern
-      sparsity_pattern.insert(dofs);
-      p++;
-    }
-  }
-  */
+    // Get mesh on current part (assume it's the same for all arguments)
+    const Mesh& mesh = *form.function_space(0)->part(part)->mesh();
 
+    // Build sparsity pattern for part
+    build(sparsity_pattern, mesh, dofmaps, true, false, false, true);
+  }
 }
 //-----------------------------------------------------------------------------

dolfin/function/CCFEMFunctionSpace.cpp

   return _dofmap->global_dimension();
 }
 //-----------------------------------------------------------------------------
+boost::shared_ptr<const CCFEMDofMap> CCFEMFunctionSpace::dofmap() const
+{
+  dolfin_assert(_dofmap);
+  return _dofmap;
+}
+//-----------------------------------------------------------------------------
 std::size_t CCFEMFunctionSpace::num_parts() const
 {
   return _function_spaces.size();

dolfin/function/CCFEMFunctionSpace.h

   class FunctionSpace;
   class BoundingBoxTree;
   class CCFEMDofMap;
+  class GenericDofMap;
 
   /// This class represents a cut and composite finite element
   /// function space (CCFEM) defined on one or more possibly
     ///         The dimension of the CCFEM function space.
     std::size_t dim() const;
 
+    /// Return CCFEM dofmap
+    ///
+    /// *Returns*
+    ///     _CCFEMDofMap_
+    ///         The dofmap.
+    boost::shared_ptr<const CCFEMDofMap> dofmap() const;
+
     /// Return the number function spaces (parts) of the CCFEM function space
     ///
     /// *Returns*

dolfin/function/FunctionSpace.h

 // Modified by Ola Skavhaug 2009
 //
 // First added:  2008-09-11
-// Last changed: 2013-08-06
+// Last changed: 2013-09-19
 
 #ifndef __FUNCTION_SPACE_H
 #define __FUNCTION_SPACE_H