~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to dolfin/mesh/MeshData.cpp

  • Committer: Anders Logg
  • Date: 2008-05-21 22:42:48 UTC
  • mfrom: (2668.6.1 trunk)
  • mto: (2668.8.3 trunk)
  • mto: This revision was merged to the branch mainline in revision 2670.
  • Revision ID: logg@simula.no-20080521224248-7baydkw3uy323fur
merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
// Licensed under the GNU LGPL Version 2.1.
3
3
//
4
4
// First added:  2008-05-19
5
 
// Last changed: 2008-05-19
 
5
// Last changed: 2008-05-21
6
6
 
7
7
#include "MeshData.h"
8
8
 
9
9
using namespace dolfin;
10
10
 
11
 
typedef std::map<std::string, MeshFunction<dolfin::uint>*>::iterator iterator;
12
 
typedef std::map<std::string, MeshFunction<dolfin::uint>*>::const_iterator const_iterator;
 
11
typedef std::map<std::string, MeshFunction<dolfin::uint>*>::iterator mf_iterator;
 
12
typedef std::map<std::string, MeshFunction<dolfin::uint>*>::const_iterator mf_const_iterator;
 
13
 
 
14
typedef std::map<std::string, Array<dolfin::uint>*>::iterator a_iterator;
 
15
typedef std::map<std::string, Array<dolfin::uint>*>::const_iterator a_const_iterator;
13
16
 
14
17
//-----------------------------------------------------------------------------
15
18
MeshData::MeshData(Mesh& mesh) : mesh(mesh)
24
27
//-----------------------------------------------------------------------------
25
28
void MeshData::clear()
26
29
27
 
  for (iterator it = data.begin(); it != data.end(); ++it)
28
 
    delete it->second;
29
 
  data.clear();
 
30
  for (mf_iterator it = meshfunctions.begin(); it != meshfunctions.end(); ++it)
 
31
    delete it->second;
 
32
  meshfunctions.clear();
 
33
 
 
34
  for (a_iterator it = arrays.begin(); it != arrays.end(); ++it)
 
35
    delete it->second;
 
36
  arrays.clear();
30
37
}
31
38
//-----------------------------------------------------------------------------
32
 
MeshFunction<dolfin::uint>* MeshData::create(std::string name, uint dim)
 
39
MeshFunction<dolfin::uint>* MeshData::createMeshFunction(std::string name, uint dim)
33
40
{
34
41
  // Check if data already exists
35
 
  iterator it = data.find(name);
36
 
  if (it != data.end())
 
42
  mf_iterator it = meshfunctions.find(name);
 
43
  if (it != meshfunctions.end())
37
44
  {
38
45
    warning("Mesh data named \"%s\" already exists.", name.c_str());
39
46
    return it->second;
40
47
  }
41
48
 
42
49
  // Create new data
43
 
  MeshFunction<uint>* f = new MeshFunction<uint>;
 
50
  MeshFunction<uint>* f = new MeshFunction<uint>(mesh);
44
51
  f->init(mesh, dim);
45
52
 
46
53
  // Add to map
47
 
  data[name] = f;
 
54
  meshfunctions[name] = f;
48
55
 
49
56
  return f;
50
57
}
51
58
//-----------------------------------------------------------------------------
52
 
MeshFunction<dolfin::uint>* MeshData::operator[] (std::string name)
53
 
{
54
 
  // Check if data exists
55
 
  iterator it = data.find(name);
56
 
  if (it == data.end())
57
 
    error("No mesh data named \"%s\" exists.", name.c_str());
 
59
Array<dolfin::uint>* MeshData::createArray(std::string name, uint size)
 
60
{
 
61
  // Check if data already exists
 
62
  a_iterator it = arrays.find(name);
 
63
  if (it != arrays.end())
 
64
  {
 
65
    warning("Mesh data named \"%s\" already exists.", name.c_str());
 
66
    return it->second;
 
67
  }
 
68
 
 
69
  // Create new data
 
70
  Array<uint>* a = new Array<uint>(size);
 
71
  *a = 0;
 
72
 
 
73
  // Add to map
 
74
  arrays[name] = a;
 
75
 
 
76
  return a;
 
77
}
 
78
//-----------------------------------------------------------------------------
 
79
MeshFunction<dolfin::uint>* MeshData::meshfunction(std::string name)
 
80
{
 
81
  // Check if data exists
 
82
  mf_iterator it = meshfunctions.find(name);
 
83
  if (it == meshfunctions.end())
 
84
    return 0;
 
85
  
 
86
  return it->second;
 
87
}
 
88
//-----------------------------------------------------------------------------
 
89
Array<dolfin::uint>* MeshData::array(std::string name)
 
90
{
 
91
  // Check if data exists
 
92
  a_iterator it = arrays.find(name);
 
93
  if (it == arrays.end())
 
94
    return 0;
58
95
  
59
96
  return it->second;
60
97
}
66
103
  begin("-------------------");
67
104
  cout << endl;
68
105
 
69
 
  for (const_iterator it = data.begin(); it != data.end(); ++it)
 
106
  for (mf_const_iterator it = meshfunctions.begin(); it != meshfunctions.end(); ++it)
70
107
  {
71
108
    cout << "MeshFunction<uint> of size "
72
109
         << it->second->size()
74
111
         << it->second->dim()
75
112
         << ": \"" << it->first << "\"" << endl;
76
113
  }
77
 
  
 
114
 
 
115
  for (a_const_iterator it = arrays.begin(); it != arrays.end(); ++it)
 
116
    cout << "Array<uint> of size " << it->second->size()
 
117
         << ": \"" << it->first << "\"" << endl;
 
118
 
78
119
  // End indentation
79
120
  end();
80
121
}