~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to src/kernel/mesh/UnitInterval.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 Kristian B. Oelgaard.
2
 
// Licensed under the GNU LGPL Version 2.1.
3
 
//
4
 
// First added:  2007-11-23
5
 
// Last changed: 2007-11-23
6
 
 
7
 
#include <dolfin/MeshEditor.h>
8
 
#include <dolfin/UnitInterval.h>
9
 
 
10
 
using namespace dolfin;
11
 
 
12
 
//-----------------------------------------------------------------------------
13
 
UnitInterval::UnitInterval(uint nx) : Mesh()
14
 
{
15
 
  if ( nx < 1 )
16
 
    error("Size of unit interval must be at least 1.");
17
 
 
18
 
  rename("mesh", "Mesh of the unit interval (0,1)");
19
 
 
20
 
  // Open mesh for editing
21
 
  MeshEditor editor;
22
 
  editor.open(*this, CellType::interval, 1, 1);
23
 
 
24
 
  // Create vertices and cells:
25
 
  editor.initVertices((nx+1));
26
 
  editor.initCells(nx);
27
 
 
28
 
  // Create main vertices:
29
 
  for (uint ix = 0; ix <= nx; ix++)
30
 
  {
31
 
    const real x = static_cast<real>(ix) / static_cast<real>(nx);
32
 
    editor.addVertex(ix, x);
33
 
  }
34
 
 
35
 
  // Create intervals
36
 
  for (uint ix = 0; ix < nx; ix++) {
37
 
        const uint v0 = ix;
38
 
        const uint v1 = v0 + 1;
39
 
        editor.addCell(ix, v0, v1);
40
 
  }
41
 
 
42
 
  // Close mesh editor
43
 
  editor.close();
44
 
 
45
 
}
46
 
//-----------------------------------------------------------------------------