~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to src/kernel/function/ConstantFunction.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-2007 Anders Logg.
2
 
// Licensed under the GNU LGPL Version 2.1.
3
 
//
4
 
// First added:  2006-02-09
5
 
// Last changed: 2007-04-24
6
 
 
7
 
#include <dolfin/dolfin_log.h>
8
 
#include <dolfin/Mesh.h>
9
 
#include <dolfin/ConstantFunction.h>
10
 
 
11
 
using namespace dolfin;
12
 
 
13
 
//-----------------------------------------------------------------------------
14
 
ConstantFunction::ConstantFunction(Mesh& mesh, real value)
15
 
  : GenericFunction(mesh), ufc::function(), value(value), size(1)
16
 
{
17
 
  // Do nothing
18
 
}
19
 
//-----------------------------------------------------------------------------
20
 
ConstantFunction::~ConstantFunction()
21
 
{
22
 
  // Do nothing
23
 
}
24
 
//-----------------------------------------------------------------------------
25
 
dolfin::uint ConstantFunction::rank() const
26
 
{
27
 
  // Just return 0 for now (might extend to vectors later)
28
 
  return 0;
29
 
}
30
 
//-----------------------------------------------------------------------------
31
 
dolfin::uint ConstantFunction::dim(uint i) const
32
 
{
33
 
  // Just return 1 for now (might extend to vectors later)
34
 
  return 1;
35
 
}
36
 
//-----------------------------------------------------------------------------
37
 
void ConstantFunction::interpolate(real* values)
38
 
{
39
 
  dolfin_assert(values);
40
 
 
41
 
  // Set all vertex values to the constant value
42
 
  const uint num_values = size*mesh.numVertices();
43
 
  for (uint i = 0; i < num_values; i++)
44
 
    values[i] = value;
45
 
}
46
 
//-----------------------------------------------------------------------------
47
 
void ConstantFunction::interpolate(real* coefficients,
48
 
                                   const ufc::cell& cell,
49
 
                                   const ufc::finite_element& finite_element)
50
 
{
51
 
  dolfin_assert(coefficients);
52
 
 
53
 
  // Compute size of value (number of entries in tensor value)
54
 
  size = 1;
55
 
  for (uint i = 0; i < finite_element.value_rank(); i++)
56
 
    size *= finite_element.value_dimension(i);
57
 
 
58
 
  // Evaluate each dof to get coefficients for nodal basis expansion
59
 
  for (uint i = 0; i < finite_element.space_dimension(); i++)
60
 
    coefficients[i] = finite_element.evaluate_dof(i, *this, cell);
61
 
}
62
 
//-----------------------------------------------------------------------------
63
 
void ConstantFunction::evaluate(real* values,
64
 
                                const real* coordinates,
65
 
                                const ufc::cell& cell) const
66
 
{
67
 
  dolfin_assert(values);
68
 
  dolfin_assert(coordinates);
69
 
 
70
 
  // Set all values to the constant value
71
 
  for (uint i = 0; i < size; i++)
72
 
    values[i] = value;
73
 
}
74
 
//-----------------------------------------------------------------------------