~corrado-maurini/dolfin/tao

« back to all changes in this revision

Viewing changes to dolfin/mesh/MeshDomains.cpp

  • Committer: corrado maurini
  • Date: 2012-12-18 12:16:08 UTC
  • mfrom: (6685.78.207 trunk)
  • Revision ID: corrado.maurini@upmc.fr-20121218121608-nk82ly9jgsld9u84
updating with trunk, fix uint in TAO solver and hacking the check for tao FindTAO.cmake

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
using namespace dolfin;
31
31
 
32
 
const unsigned int MeshDomains::default_unset_value = std::numeric_limits<unsigned int>::max();
 
32
const std::size_t MeshDomains::default_unset_value = std::numeric_limits<std::size_t>::max();
33
33
 
34
34
//-----------------------------------------------------------------------------
35
35
MeshDomains::MeshDomains()
42
42
  // Do nothing
43
43
}
44
44
//-----------------------------------------------------------------------------
45
 
dolfin::uint MeshDomains::max_dim() const
 
45
std::size_t MeshDomains::max_dim() const
46
46
{
47
47
  if (!_markers.empty())
48
48
    return _markers.size() - 1;
50
50
    return 0;
51
51
}
52
52
//-----------------------------------------------------------------------------
53
 
dolfin::uint MeshDomains::num_marked(uint dim) const
 
53
std::size_t MeshDomains::num_marked(std::size_t dim) const
54
54
{
55
55
  dolfin_assert(dim < _markers.size());
56
56
  dolfin_assert(_markers[dim]);
59
59
//-----------------------------------------------------------------------------
60
60
bool MeshDomains::is_empty() const
61
61
{
62
 
  uint size = 0;
63
 
  for (uint i = 0; i < _markers.size(); i++)
 
62
  std::size_t size = 0;
 
63
  for (std::size_t i = 0; i < _markers.size(); i++)
64
64
  {
65
65
    dolfin_assert(_markers[i]);
66
66
    size += _markers[i]->size();
68
68
  return size == 0;
69
69
}
70
70
//-----------------------------------------------------------------------------
71
 
boost::shared_ptr<MeshValueCollection<unsigned int> >
72
 
MeshDomains::markers(uint dim)
73
 
{
74
 
  dolfin_assert(dim < _markers.size());
75
 
  return _markers[dim];
76
 
}
77
 
//-----------------------------------------------------------------------------
78
 
boost::shared_ptr<const MeshValueCollection<unsigned int> >
79
 
MeshDomains::markers(uint dim) const
80
 
{
81
 
  dolfin_assert(dim < _markers.size());
82
 
  return _markers[dim];
83
 
}
84
 
//-----------------------------------------------------------------------------
85
 
std::vector<std::string> MeshDomains::marker_names(uint dim) const
 
71
boost::shared_ptr<MeshValueCollection<std::size_t> >
 
72
  MeshDomains::markers(std::size_t dim)
 
73
{
 
74
  dolfin_assert(dim < _markers.size());
 
75
  return _markers[dim];
 
76
}
 
77
//-----------------------------------------------------------------------------
 
78
boost::shared_ptr<const MeshValueCollection<std::size_t> >
 
79
  MeshDomains::markers(std::size_t dim) const
 
80
{
 
81
  dolfin_assert(dim < _markers.size());
 
82
  return _markers[dim];
 
83
}
 
84
//-----------------------------------------------------------------------------
 
85
std::vector<std::string> MeshDomains::marker_names(std::size_t dim) const
86
86
{
87
87
  dolfin_assert(dim < _named_markers.size());
88
88
  std::vector<std::string> names;
89
 
  boost::unordered_map<std::string, boost::shared_ptr<MeshValueCollection<uint> > >::const_iterator m;
 
89
  boost::unordered_map<std::string, boost::shared_ptr<MeshValueCollection<std::size_t> > >::const_iterator m;
90
90
  for (m = _named_markers[dim].begin(); m != _named_markers[dim].end(); ++m)
91
91
    names.push_back(m->first);
92
92
  return names;
93
93
}
94
94
//-----------------------------------------------------------------------------
95
 
boost::shared_ptr<const MeshFunction<dolfin::uint> >
96
 
MeshDomains::cell_domains(const Mesh& mesh, uint unset_value) const
 
95
boost::shared_ptr<const MeshFunction<std::size_t> >
 
96
  MeshDomains::cell_domains(const Mesh& mesh, std::size_t unset_value) const
97
97
{
98
98
  // Check if any markers have been set
99
 
  const uint D = mesh.topology().dim();
 
99
  const std::size_t D = mesh.topology().dim();
100
100
  dolfin_assert(D < _markers.size());
101
101
 
102
102
  // Create markers if mesh collection present
103
103
  if (!_markers[D]->empty() and !_cell_domains)
104
104
  {
105
 
    MeshValueCollection<unsigned int> domain = *(_markers[D]);
 
105
    MeshValueCollection<std::size_t> domain = *(_markers[D]);
106
106
    _cell_domains = mesh_function(mesh, domain, unset_value);
107
107
  }
108
108
 
109
109
  return _cell_domains;
110
110
}
111
111
//-----------------------------------------------------------------------------
112
 
boost::shared_ptr<const MeshFunction<dolfin::uint> >
113
 
MeshDomains::facet_domains(const Mesh& mesh, uint unset_value) const
 
112
boost::shared_ptr<const MeshFunction<std::size_t> >
 
113
  MeshDomains::facet_domains(const Mesh& mesh, std::size_t unset_value) const
114
114
{
115
115
  // Check if any markers have been set
116
 
  const uint D = mesh.topology().dim();
 
116
  const std::size_t D = mesh.topology().dim();
117
117
  dolfin_assert((D - 1) < _markers.size());
118
118
 
119
119
  // Create markers if mesh collection present
120
120
  if (!_markers[D - 1]->empty() and !_facet_domains)
121
121
  {
122
 
    const MeshValueCollection<unsigned int> domain = *(_markers[D - 1]);
 
122
    const MeshValueCollection<std::size_t> domain = *(_markers[D - 1]);
123
123
    _facet_domains = mesh_function(mesh, domain, unset_value);
124
124
  }
125
125
 
126
126
  return _facet_domains;
127
127
}
128
128
//-----------------------------------------------------------------------------
129
 
boost::shared_ptr<MeshFunction<dolfin::uint> >
 
129
boost::shared_ptr<MeshFunction<std::size_t> >
130
130
MeshDomains::mesh_function(const Mesh& mesh,
131
 
                           const MeshValueCollection<unsigned int>& collection,
132
 
                           uint unset_value)
 
131
                           const MeshValueCollection<std::size_t>& collection,
 
132
                           std::size_t unset_value)
133
133
{
134
134
  // Get dimensions
135
 
  const uint d = collection.dim();
136
 
  const uint D = mesh.topology().dim();
 
135
  const std::size_t d = collection.dim();
 
136
  const std::size_t D = mesh.topology().dim();
137
137
 
138
138
  // Create MeshFunction
139
 
  boost::shared_ptr<MeshFunction<uint> >
140
 
    mesh_function(new MeshFunction<uint>(mesh, d, unset_value));
 
139
  boost::shared_ptr<MeshFunction<std::size_t> >
 
140
    mesh_function(new MeshFunction<std::size_t>(mesh, d, unset_value));
141
141
 
142
142
  // Get mesh connectivity D --> d
143
143
  dolfin_assert(d <= D);
145
145
  dolfin_assert(D == d || !connectivity.empty());
146
146
 
147
147
  // Iterate over all values
148
 
  const std::map<std::pair<uint, uint>, uint> values = collection.values();
149
 
  std::map<std::pair<uint, uint>, uint>::const_iterator it;
 
148
  const std::map<std::pair<std::size_t, std::size_t>, std::size_t>& values = collection.values();
 
149
  std::map<std::pair<std::size_t, std::size_t>, std::size_t>::const_iterator it;
150
150
  for (it = values.begin(); it != values.end(); ++it)
151
151
  {
152
152
    // Get marker data
153
 
    const uint cell_index = it->first.first;
154
 
    const uint local_entity = it->first.second;
155
 
    const uint value = it->second;
 
153
    const std::size_t cell_index = it->first.first;
 
154
    const std::size_t local_entity = it->first.second;
 
155
    const std::size_t value = it->second;
156
156
 
157
157
    // Get global entity index. Note that we ignore the local entity
158
158
    // index when the function is defined over cells.
159
 
    uint entity_index = 0;
 
159
    std::size_t entity_index = 0;
160
160
    if (d == D)
161
161
      entity_index = cell_index;
162
162
    else
173
173
  return mesh_function;
174
174
}
175
175
//-----------------------------------------------------------------------------
176
 
void MeshDomains::init(uint dim)
 
176
void MeshDomains::init(std::size_t dim)
177
177
{
178
178
  // Clear old data
179
179
  clear();
180
180
 
181
181
  // Add markers for each topological dimension
182
 
  for (uint d = 0; d <= dim; d++)
 
182
  for (std::size_t d = 0; d <= dim; d++)
183
183
  {
184
 
    boost::shared_ptr<MeshValueCollection<uint> >
185
 
      m(new MeshValueCollection<uint>(d));
 
184
    boost::shared_ptr<MeshValueCollection<std::size_t> >
 
185
        m(new MeshValueCollection<std::size_t>(d));
186
186
    _markers.push_back(m);
187
187
  }
188
188
}