1
// Copyright (C) 2007 Anders Logg.
2
// Licensed under the GNU LGPL Version 2.1.
4
// Modified by Garth N. Wells, 2007.
6
// First added: 2007-01-17
7
// Last changed: 2008-02-15
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>
17
using namespace dolfin;
19
//-----------------------------------------------------------------------------
20
DofMapSet::DofMapSet()
24
//-----------------------------------------------------------------------------
25
DofMapSet::DofMapSet(const Form& form, Mesh& mesh) : _parallel(false)
27
update(form.form(), mesh);
29
//-----------------------------------------------------------------------------
30
DofMapSet::DofMapSet(const Form& form, Mesh& mesh,
31
MeshFunction<uint>& partitions) : _parallel(true)
33
update(form, mesh, partitions);
35
//-----------------------------------------------------------------------------
36
DofMapSet::DofMapSet(const ufc::form& form, Mesh& mesh) : _parallel(false)
40
//-----------------------------------------------------------------------------
41
DofMapSet::DofMapSet(const ufc::form& form, Mesh& mesh,
42
MeshFunction<uint>& partitions) : _parallel(true)
44
update(form, mesh, partitions);
46
//-----------------------------------------------------------------------------
47
DofMapSet::~DofMapSet()
49
// Delete all dof maps in the cache
50
for (map_iterator it = dof_map_cache.begin(); it != dof_map_cache.end(); it++)
53
delete it->second.first;
55
// Delete DOLFIN dof map
56
delete it->second.second;
59
//-----------------------------------------------------------------------------
60
void DofMapSet::update(const Form& form, Mesh& mesh)
62
update(form.form(), mesh);
64
//-----------------------------------------------------------------------------
65
void DofMapSet::update(const Form& form, Mesh& mesh, MeshFunction<uint>& partitions)
67
update(form.form(), mesh, partitions);
69
//-----------------------------------------------------------------------------
70
void DofMapSet::update(const ufc::form& form, Mesh& mesh)
72
const uint num_arguments = form.rank() +
73
form.num_coefficients();
75
// Resize array of dof maps
76
dof_map_set.resize(num_arguments);
78
// Create dof maps and reuse previously computed dof maps
79
for (uint i = 0; i < num_arguments; i++)
82
ufc::dof_map* ufc_dof_map = form.create_dof_map(i);
83
dolfin_assert(ufc_dof_map);
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() )
89
message(2, "Creating dof map (not in cache): %s", ufc_dof_map->signature());
91
// Create DOLFIN dof map
92
DofMap* dolfin_dof_map = new DofMap(*ufc_dof_map, mesh);
93
dolfin_assert(dolfin_dof_map);
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;
99
// Set dof map for argument i
100
dof_map_set[i] = dolfin_dof_map;
104
message(2, "Reusing dof map (already in cache): %s", ufc_dof_map->signature());
106
// Set dof map for argument i
107
dof_map_set[i] = it->second.second;
109
// Delete UFC dof map (not used)
114
//-----------------------------------------------------------------------------
115
void DofMapSet::update(const ufc::form& form, Mesh& mesh,
116
MeshFunction<uint>& partitions)
118
// Resize array of dof maps
119
dof_map_set.resize(form.rank());
121
// Create dof maps and reuse previously computed dof maps
122
for (uint i = 0; i < form.rank(); i++)
124
// Create UFC dof map
125
ufc::dof_map* ufc_dof_map = form.create_dof_map(i);
126
dolfin_assert(ufc_dof_map);
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() )
132
message(2, "Creating dof map (not in cache): %s", ufc_dof_map->signature());
134
// Create DOLFIN dof map
135
DofMap* dolfin_dof_map = new DofMap(*ufc_dof_map, mesh, partitions);
136
dolfin_assert(dolfin_dof_map);
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;
142
// Set dof map for argument i
143
dof_map_set[i] = dolfin_dof_map;
147
message(2, "Reusing dof map (already in cache): %s", ufc_dof_map->signature());
149
// Set dof map for argument i
150
dof_map_set[i] = it->second.second;
152
// Delete UFC dof map (not used)
157
//-----------------------------------------------------------------------------
158
void DofMapSet::build(UFC& ufc) const
160
for (uint i=0; i<dof_map_set.size(); ++i)
161
dof_map_set[i]->build(ufc);
163
//-----------------------------------------------------------------------------
164
dolfin::uint DofMapSet::size() const
166
return dof_map_set.size();
168
//-----------------------------------------------------------------------------
169
DofMap& DofMapSet::operator[] (uint i) const
171
dolfin_assert(i < dof_map_set.size());
172
return *dof_map_set[i];
174
//-----------------------------------------------------------------------------