~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to src/kernel/mesh/MeshGeometry.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) 2006 Anders Logg.
2
 
// Licensed under the GNU LGPL Version 2.1.
3
 
//
4
 
// First added:  2006-05-19
5
 
// Last changed: 2006-10-19
6
 
 
7
 
#include <dolfin/dolfin_log.h>
8
 
#include <dolfin/MeshGeometry.h>
9
 
 
10
 
using namespace dolfin;
11
 
 
12
 
//-----------------------------------------------------------------------------
13
 
MeshGeometry::MeshGeometry() : _dim(0), _size(0), coordinates(0)
14
 
{
15
 
  // Do nothing
16
 
}
17
 
//-----------------------------------------------------------------------------
18
 
MeshGeometry::MeshGeometry(const MeshGeometry& geometry)
19
 
  : _dim(0), _size(0), coordinates(0)
20
 
{
21
 
  *this = geometry;
22
 
}
23
 
//-----------------------------------------------------------------------------
24
 
MeshGeometry::~MeshGeometry()
25
 
{
26
 
  clear();
27
 
}
28
 
//-----------------------------------------------------------------------------
29
 
const MeshGeometry& MeshGeometry::operator= (const MeshGeometry& geometry)
30
 
{
31
 
  // Clear old data if any
32
 
  clear();
33
 
 
34
 
  // Allocate data
35
 
  _dim = geometry._dim;
36
 
  _size = geometry._size;
37
 
  const uint n = _dim*_size;
38
 
  coordinates = new real[n];
39
 
 
40
 
  // Copy data
41
 
  for (uint i = 0; i < n; i++)
42
 
    coordinates[i] = geometry.coordinates[i];
43
 
 
44
 
  return *this;
45
 
}
46
 
//-----------------------------------------------------------------------------
47
 
Point MeshGeometry::point(uint n) const
48
 
{
49
 
  real _x = 0.0;
50
 
  real _y = 0.0;
51
 
  real _z = 0.0;
52
 
  
53
 
  if ( _dim > 0 )
54
 
    _x = x(n, 0);
55
 
  if ( _dim > 1 )
56
 
    _y = x(n, 1);
57
 
  if ( _dim > 2 )
58
 
    _z = x(n, 2);
59
 
 
60
 
  Point p(_x, _y, _z);
61
 
  return p;
62
 
}
63
 
//-----------------------------------------------------------------------------
64
 
void MeshGeometry::clear()
65
 
{
66
 
  _dim = 0;
67
 
  _size = 0;
68
 
  if ( coordinates )
69
 
    delete [] coordinates;
70
 
  coordinates = 0;
71
 
}
72
 
//-----------------------------------------------------------------------------
73
 
void MeshGeometry::init(uint dim, uint size)
74
 
{
75
 
  // Delete old data if any
76
 
  clear();
77
 
 
78
 
  // Allocate new data
79
 
  coordinates = new real[dim*size];
80
 
 
81
 
  // Save dimension and size
82
 
  _dim = dim;
83
 
  _size = size;
84
 
}
85
 
//-----------------------------------------------------------------------------
86
 
void MeshGeometry::set(uint n, uint i, real x)
87
 
{
88
 
  coordinates[n*_dim + i] = x;
89
 
}
90
 
//-----------------------------------------------------------------------------
91
 
void MeshGeometry::disp() const
92
 
{
93
 
  cout << "Mesh geometry" << endl;
94
 
  cout << "-------------" << endl << endl;
95
 
 
96
 
  // Begin indentation
97
 
  begin("");
98
 
 
99
 
  // Check if empty
100
 
  if ( _dim == 0 )
101
 
  {
102
 
    cout << "empty" << endl << endl;
103
 
    end();
104
 
    return;
105
 
  }
106
 
  
107
 
  // Display coordinates for all vertices
108
 
  for (uint i = 0; i < _size; i++)
109
 
  {
110
 
    cout << i << ":";
111
 
    for (uint d = 0; d < _dim; d++)
112
 
      cout << " " << x(i, d);
113
 
    cout << endl;
114
 
  }
115
 
  cout << endl;
116
 
 
117
 
  // End indentation
118
 
  end();
119
 
}
120
 
//-----------------------------------------------------------------------------