~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to src/kernel/fem/dolfin/DofMap.h

  • Committer: Johannes Ring
  • Date: 2008-03-05 22:43:06 UTC
  • Revision ID: johannr@simula.no-20080305224306-2npsdyhfdpl2esji
The BIG commit!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright (C) 2007 Anders Logg and Garth N. Wells.
2
 
// Licensed under the GNU LGPL Version 2.1.
3
 
 
4
 
// First added:  2007-03-01
5
 
// Last changed: 2007-04-03
6
 
 
7
 
#ifndef __DOF_MAP_H
8
 
#define __DOF_MAP_H
9
 
 
10
 
#include <map>
11
 
#include <ufc.h>
12
 
#include <dolfin/Mesh.h>
13
 
#include <dolfin/UFCCell.h>
14
 
#include <dolfin/UFCMesh.h>
15
 
#include <dolfin/constants.h>
16
 
#include <dolfin/MeshFunction.h>
17
 
 
18
 
 
19
 
namespace dolfin
20
 
{
21
 
  class SubSytem;
22
 
  class UFC;
23
 
 
24
 
  /// This class handles the mapping of degrees of freedom.
25
 
  /// It wraps a ufc::dof_map on a specific mesh and provides
26
 
  /// optional precomputation and reordering of dofs.
27
 
 
28
 
  class DofMap
29
 
  {
30
 
  public:
31
 
 
32
 
    /// Create dof map on mesh
33
 
    DofMap(ufc::dof_map& dof_map, Mesh& mesh);
34
 
 
35
 
    /// Create dof map on mesh (parallel)
36
 
    DofMap(ufc::dof_map& dof_map, Mesh& mesh, MeshFunction<uint>& partitions);
37
 
 
38
 
    /// Create dof map on mesh
39
 
    DofMap(const std::string signature, Mesh& mesh);
40
 
 
41
 
    /// Create dof map on mesh (parallel)
42
 
    DofMap(const std::string signature, Mesh& mesh, 
43
 
        MeshFunction<uint>& partitions);
44
 
 
45
 
    /// Destructor
46
 
    ~DofMap();
47
 
 
48
 
    /// Return a string identifying the dof map
49
 
    const char* signature() const
50
 
      { 
51
 
        if(ufc_map)
52
 
          return ufc_dof_map->signature(); 
53
 
        else
54
 
        {
55
 
          error("DofMap has been re-ordered. Cannot return signature string.");
56
 
          return ufc_dof_map->signature(); 
57
 
        }  
58
 
      }
59
 
 
60
 
    /// Return the dimension of the global finite element function space
61
 
    unsigned int global_dimension() const
62
 
      { return ufc_dof_map->global_dimension(); }
63
 
 
64
 
    /// Return the dimension of the local finite element function space
65
 
    unsigned int local_dimension() const
66
 
    { return ufc_dof_map->local_dimension(); }
67
 
 
68
 
    /// Return the dimension of the local finite element function space
69
 
    unsigned int macro_local_dimension() const
70
 
    { return ufc_dof_map->local_dimension(); }
71
 
 
72
 
    /// Return number of facet dofs
73
 
    unsigned int num_facet_dofs() const
74
 
    { return ufc_dof_map->num_facet_dofs(); }
75
 
 
76
 
    /// Tabulate the local-to-global mapping of dofs on a cell
77
 
    void tabulate_dofs(uint* dofs, Cell& cell) 
78
 
    {
79
 
      if (dof_map)
80
 
      {
81
 
        for (uint i = 0; i < local_dimension(); i++)
82
 
          dofs[i] = dof_map[cell.index()][i];
83
 
      }
84
 
      else
85
 
      {
86
 
        ufc_cell.update(cell);
87
 
        ufc_dof_map->tabulate_dofs(dofs, ufc_mesh, ufc_cell);
88
 
      }
89
 
    }
90
 
 
91
 
    /// Tabulate local-local facet dofs
92
 
    void tabulate_facet_dofs(uint* dofs, uint local_facet) const
93
 
    { ufc_dof_map->tabulate_facet_dofs(dofs, local_facet); }
94
 
 
95
 
    // FIXME: Can this function eventually be removed?
96
 
    /// Tabulate the local-to-global mapping of dofs on a ufc cell
97
 
    void tabulate_dofs(uint* dofs, const ufc::cell& cell) const 
98
 
      { ufc_dof_map->tabulate_dofs(dofs, ufc_mesh, cell); }
99
 
 
100
 
    void tabulate_coordinates(real** coordinates, const ufc::cell& ufc_cell) const
101
 
      { ufc_dof_map->tabulate_coordinates(coordinates, ufc_cell); }
102
 
 
103
 
    /// Extract sub dof map
104
 
    DofMap* extractDofMap(const Array<uint>& sub_system, uint& offset) const;
105
 
 
106
 
    /// Return mesh associated with map
107
 
    Mesh& mesh() const
108
 
      { return dolfin_mesh; }
109
 
 
110
 
    /// Build parallel dof map
111
 
    void build(UFC& ufc);
112
 
 
113
 
    /// Return renumbering (used for testing)
114
 
    std::map<uint, uint> getMap() const;
115
 
 
116
 
  private:
117
 
 
118
 
    /// Initialise DofMap
119
 
    void init();
120
 
 
121
 
    /// Extract sub DofMap
122
 
    ufc::dof_map* extractDofMap(const ufc::dof_map& dof_map, uint& offset, const Array<uint>& sub_system) const;
123
 
 
124
 
    // Parallel dof map
125
 
    uint** dof_map;
126
 
 
127
 
    // UFC dof map
128
 
    ufc::dof_map* ufc_dof_map;
129
 
 
130
 
    // Local UFC dof map
131
 
    ufc::dof_map* ufc_dof_map_local;
132
 
 
133
 
    // UFC mesh
134
 
    UFCMesh ufc_mesh;
135
 
 
136
 
    // DOLFIN mesh
137
 
    Mesh& dolfin_mesh;
138
 
 
139
 
    // UFC cell
140
 
    UFCCell ufc_cell;
141
 
 
142
 
    bool ufc_map;
143
 
 
144
 
    // Number of cells in the mesh
145
 
    uint num_cells;
146
 
 
147
 
    // Partitions
148
 
    MeshFunction<uint>* partitions;
149
 
 
150
 
    // Provide easy access to map for testing
151
 
    std::map<uint, uint> map;
152
 
 
153
 
  };
154
 
 
155
 
}
156
 
 
157
 
#endif