~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to src/kernel/fem/DofMapSet.cpp

  • 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.
2
 
// Licensed under the GNU LGPL Version 2.1.
3
 
//
4
 
// Modified by Garth N. Wells, 2007.
5
 
//
6
 
// First added:  2007-01-17
7
 
// Last changed: 2008-02-15
8
 
 
9
 
#include <dolfin/dolfin_log.h>
10
 
#include <dolfin/DofMap.h>
11
 
#include <dolfin/DofMapSet.h>
12
 
#include <dolfin/Mesh.h>
13
 
#include <dolfin/Form.h>
14
 
 
15
 
#include <ufc.h>
16
 
 
17
 
using namespace dolfin;
18
 
 
19
 
//-----------------------------------------------------------------------------
20
 
DofMapSet::DofMapSet()
21
 
{
22
 
  // Do nothing
23
 
}
24
 
//-----------------------------------------------------------------------------
25
 
DofMapSet::DofMapSet(const Form& form, Mesh& mesh) : _parallel(false)
26
 
{
27
 
  update(form.form(), mesh);
28
 
}
29
 
//-----------------------------------------------------------------------------
30
 
DofMapSet::DofMapSet(const Form& form, Mesh& mesh, 
31
 
                     MeshFunction<uint>& partitions) : _parallel(true)
32
 
{
33
 
  update(form, mesh, partitions);
34
 
}
35
 
//-----------------------------------------------------------------------------
36
 
DofMapSet::DofMapSet(const ufc::form& form, Mesh& mesh) : _parallel(false)
37
 
{
38
 
  update(form, mesh);
39
 
}
40
 
//-----------------------------------------------------------------------------
41
 
DofMapSet::DofMapSet(const ufc::form& form, Mesh& mesh, 
42
 
                     MeshFunction<uint>& partitions) : _parallel(true)
43
 
{
44
 
  update(form, mesh, partitions);
45
 
}
46
 
//-----------------------------------------------------------------------------
47
 
DofMapSet::~DofMapSet()
48
 
{
49
 
  // Delete all dof maps in the cache
50
 
  for (map_iterator it = dof_map_cache.begin(); it != dof_map_cache.end(); it++)
51
 
  {
52
 
    // Delete UFC dof map
53
 
    delete it->second.first;
54
 
 
55
 
    // Delete DOLFIN dof map
56
 
    delete it->second.second;
57
 
  }
58
 
}
59
 
//-----------------------------------------------------------------------------
60
 
void DofMapSet::update(const Form& form, Mesh& mesh)
61
 
{
62
 
  update(form.form(), mesh);
63
 
}
64
 
//-----------------------------------------------------------------------------
65
 
void DofMapSet::update(const Form& form, Mesh& mesh, MeshFunction<uint>& partitions)
66
 
{
67
 
  update(form.form(), mesh, partitions);
68
 
}
69
 
//-----------------------------------------------------------------------------
70
 
void DofMapSet::update(const ufc::form& form, Mesh& mesh)
71
 
{
72
 
  const uint num_arguments = form.rank() +
73
 
    form.num_coefficients();
74
 
 
75
 
  // Resize array of dof maps
76
 
  dof_map_set.resize(num_arguments);
77
 
 
78
 
  // Create dof maps and reuse previously computed dof maps
79
 
  for (uint i = 0; i < num_arguments; i++)
80
 
  {
81
 
    // Create UFC dof map
82
 
    ufc::dof_map* ufc_dof_map = form.create_dof_map(i);
83
 
    dolfin_assert(ufc_dof_map);
84
 
    
85
 
    // Check if dof map is in cache
86
 
    map_iterator it = dof_map_cache.find(ufc_dof_map->signature());
87
 
    if ( it == dof_map_cache.end() )
88
 
    {
89
 
      message(2, "Creating dof map (not in cache): %s", ufc_dof_map->signature());
90
 
 
91
 
      // Create DOLFIN dof map
92
 
      DofMap* dolfin_dof_map = new DofMap(*ufc_dof_map, mesh);
93
 
      dolfin_assert(dolfin_dof_map);
94
 
 
95
 
      // Save pair of UFC and DOLFIN dof maps in cache
96
 
      std::pair<ufc::dof_map*, DofMap*> dof_map_pair(ufc_dof_map, dolfin_dof_map);
97
 
      dof_map_cache[ufc_dof_map->signature()] = dof_map_pair;
98
 
      
99
 
      // Set dof map for argument i
100
 
      dof_map_set[i] = dolfin_dof_map;
101
 
    }
102
 
    else
103
 
    {
104
 
      message(2, "Reusing dof map (already in cache): %s", ufc_dof_map->signature());
105
 
      
106
 
      // Set dof map for argument i
107
 
      dof_map_set[i] = it->second.second;
108
 
     
109
 
      // Delete UFC dof map (not used)
110
 
      delete ufc_dof_map;
111
 
    }
112
 
  }
113
 
}
114
 
//-----------------------------------------------------------------------------
115
 
void DofMapSet::update(const ufc::form& form, Mesh& mesh,
116
 
        MeshFunction<uint>& partitions)
117
 
{
118
 
  // Resize array of dof maps
119
 
  dof_map_set.resize(form.rank());
120
 
 
121
 
  // Create dof maps and reuse previously computed dof maps
122
 
  for (uint i = 0; i < form.rank(); i++)
123
 
  {
124
 
    // Create UFC dof map
125
 
    ufc::dof_map* ufc_dof_map = form.create_dof_map(i);
126
 
    dolfin_assert(ufc_dof_map);
127
 
    
128
 
    // Check if dof map is in cache
129
 
    map_iterator it = dof_map_cache.find(ufc_dof_map->signature());
130
 
    if ( it == dof_map_cache.end() )
131
 
    {
132
 
      message(2, "Creating dof map (not in cache): %s", ufc_dof_map->signature());
133
 
 
134
 
      // Create DOLFIN dof map
135
 
      DofMap* dolfin_dof_map = new DofMap(*ufc_dof_map, mesh, partitions);
136
 
      dolfin_assert(dolfin_dof_map);
137
 
 
138
 
      // Save pair of UFC and DOLFIN dof maps in cache
139
 
      std::pair<ufc::dof_map*, DofMap*> dof_map_pair(ufc_dof_map, dolfin_dof_map);
140
 
      dof_map_cache[ufc_dof_map->signature()] = dof_map_pair;
141
 
      
142
 
      // Set dof map for argument i
143
 
      dof_map_set[i] = dolfin_dof_map;
144
 
    }
145
 
    else
146
 
    {
147
 
      message(2, "Reusing dof map (already in cache): %s", ufc_dof_map->signature());
148
 
      
149
 
      // Set dof map for argument i
150
 
      dof_map_set[i] = it->second.second;
151
 
     
152
 
      // Delete UFC dof map (not used)
153
 
      delete ufc_dof_map;
154
 
    }
155
 
  }
156
 
}
157
 
//-----------------------------------------------------------------------------
158
 
void DofMapSet::build(UFC& ufc) const
159
 
{
160
 
  for (uint i=0; i<dof_map_set.size(); ++i)
161
 
    dof_map_set[i]->build(ufc);
162
 
}
163
 
//-----------------------------------------------------------------------------
164
 
dolfin::uint DofMapSet::size() const
165
 
{
166
 
  return dof_map_set.size();
167
 
}
168
 
//-----------------------------------------------------------------------------
169
 
DofMap& DofMapSet::operator[] (uint i) const
170
 
{
171
 
  dolfin_assert(i < dof_map_set.size());
172
 
  return *dof_map_set[i];
173
 
}
174
 
//-----------------------------------------------------------------------------
175