~ubuntu-branches/ubuntu/vivid/ffc/vivid

« back to all changes in this revision

Viewing changes to ffc/backends/dolfin/functionspace.py

  • Committer: Package Import Robot
  • Author(s): Johannes Ring
  • Date: 2014-06-03 18:26:02 UTC
  • mfrom: (1.1.15)
  • Revision ID: package-import@ubuntu.com-20140603182602-zvnubjjh7i78e1v0
Tags: 1.4.0-1
* New upstream release.
* debian/control:
  - Add swig in Build-Depends.
  - Remove python-ufc from Depends.
  - Add ufc and python-ufc to Provides, Conflicts and Replaces.
  - Remove python-ferari and python-dolfin from Suggests.
  - Bump minimum required version for python-fiat, python-instant and
    python-ufl to 1.4.0.
* debian/rules: Add override for auto clean target to remove generated
  cmake and pkg-config files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2011 Marie E. Rognes
 
2
#
 
3
# This file is part of DOLFIN.
 
4
#
 
5
# DOLFIN is free software: you can redistribute it and/or modify
 
6
# it under the terms of the GNU Lesser General Public License as published by
 
7
# the Free Software Foundation, either version 3 of the License, or
 
8
# (at your option) any later version.
 
9
#
 
10
# DOLFIN is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
13
# GNU Lesser General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU Lesser General Public License
 
16
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
 
17
#
 
18
# Based on original implementation by Martin Alnes and Anders Logg
 
19
#
 
20
# Last changed: 2012-11-14
 
21
 
 
22
from includes import snippets
 
23
 
 
24
__all__ = ["apply_function_space_template", "extract_coefficient_spaces",
 
25
           "generate_typedefs"]
 
26
 
 
27
#-------------------------------------------------------------------------------
 
28
def extract_coefficient_spaces(forms):
 
29
    """Extract a list of tuples
 
30
 
 
31
      (classname, finite_element_classname, dofmap_classname)
 
32
 
 
33
    for the coefficient spaces in the set of given forms. This can
 
34
    then be used for input to the function space template."""
 
35
 
 
36
    # Extract data for each coefficient space
 
37
    spaces = {}
 
38
    for form in forms:
 
39
        for (i, name) in enumerate(form.coefficient_names):
 
40
            # Skip if already considered
 
41
            if name in spaces:
 
42
                continue
 
43
 
 
44
            # Map element name, dof map name etc to this coefficient
 
45
            spaces[name] = ("CoefficientSpace_%s" % name,
 
46
                            form.ufc_finite_element_classnames[form.rank + i],
 
47
                            form.ufc_dofmap_classnames[form.rank + i])
 
48
 
 
49
    # Return coefficient spaces sorted alphabetically by coefficient
 
50
    # name
 
51
    names = spaces.keys()
 
52
    names.sort()
 
53
    return [spaces[name] for name in names]
 
54
#-------------------------------------------------------------------------------
 
55
def generate_typedefs(form, classname):
 
56
    """Generate typedefs for test, trial and coefficient spaces
 
57
    relative to a function space."""
 
58
 
 
59
    # Generate typedef data for test/trial spaces
 
60
    pairs = [("%s_FunctionSpace_%d" % (classname, i),
 
61
              snippets["functionspace"][i]) for i in range(form.rank)]
 
62
 
 
63
    # Generate typedefs for coefficient spaces
 
64
    pairs += [("%s_FunctionSpace_%d" % (classname, form.rank + i),
 
65
               "CoefficientSpace_%s" % form.coefficient_names[i])
 
66
              for i in range(form.num_coefficients)]
 
67
 
 
68
    # Combine data to typedef code
 
69
    code = "\n".join("  typedef %s %s;" % (to, fro) for (to, fro) in pairs)
 
70
    return code
 
71
#-------------------------------------------------------------------------------
 
72
function_space_template = """\
 
73
class %(classname)s: public dolfin::FunctionSpace
 
74
{
 
75
public:
 
76
 
 
77
  //--- Constructors for standard function space, 2 different versions ---
 
78
 
 
79
  // Create standard function space (reference version)
 
80
  %(classname)s(const dolfin::Mesh& mesh):
 
81
    dolfin::FunctionSpace(dolfin::reference_to_no_delete_pointer(mesh),
 
82
                          std::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(std::shared_ptr<ufc::finite_element>(new %(ufc_finite_element_classname)s()))),
 
83
                          std::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(std::shared_ptr<ufc::dofmap>(new %(ufc_dofmap_classname)s()), mesh)))
 
84
  {
 
85
    // Do nothing
 
86
  }
 
87
 
 
88
  // Create standard function space (shared pointer version)
 
89
  %(classname)s(std::shared_ptr<const dolfin::Mesh> mesh):
 
90
    dolfin::FunctionSpace(mesh,
 
91
                          std::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(std::shared_ptr<ufc::finite_element>(new %(ufc_finite_element_classname)s()))),
 
92
                          std::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(std::shared_ptr<ufc::dofmap>(new %(ufc_dofmap_classname)s()), *mesh)))
 
93
  {
 
94
    // Do nothing
 
95
  }
 
96
 
 
97
  //--- Constructors for constrained function space, 2 different versions ---
 
98
 
 
99
  // Create standard function space (reference version)
 
100
  %(classname)s(const dolfin::Mesh& mesh, const dolfin::SubDomain& constrained_domain):
 
101
    dolfin::FunctionSpace(dolfin::reference_to_no_delete_pointer(mesh),
 
102
                          std::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(std::shared_ptr<ufc::finite_element>(new %(ufc_finite_element_classname)s()))),
 
103
                          std::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(std::shared_ptr<ufc::dofmap>(new %(ufc_dofmap_classname)s()), mesh,
 
104
                              dolfin::reference_to_no_delete_pointer(constrained_domain))))
 
105
  {
 
106
    // Do nothing
 
107
  }
 
108
 
 
109
  // Create standard function space (shared pointer version)
 
110
  %(classname)s(std::shared_ptr<const dolfin::Mesh> mesh, std::shared_ptr<const dolfin::SubDomain> constrained_domain):
 
111
    dolfin::FunctionSpace(mesh,
 
112
                          std::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(std::shared_ptr<ufc::finite_element>(new %(ufc_finite_element_classname)s()))),
 
113
                          std::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(std::shared_ptr<ufc::dofmap>(new %(ufc_dofmap_classname)s()), *mesh, constrained_domain)))
 
114
  {
 
115
    // Do nothing
 
116
  }
 
117
 
 
118
  //--- Constructors for restricted function space, 2 different versions ---
 
119
 
 
120
  // Create restricted function space (reference version)
 
121
  %(classname)s(const dolfin::Restriction& restriction):
 
122
    dolfin::FunctionSpace(dolfin::reference_to_no_delete_pointer(restriction.mesh()),
 
123
                          std::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(std::shared_ptr<ufc::finite_element>(new %(ufc_finite_element_classname)s()))),
 
124
                          std::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(std::shared_ptr<ufc::dofmap>(new %(ufc_dofmap_classname)s()),
 
125
                                                                                     reference_to_no_delete_pointer(restriction))))
 
126
  {
 
127
    // Do nothing
 
128
  }
 
129
 
 
130
  // Create restricted function space (shared pointer version)
 
131
  %(classname)s(std::shared_ptr<const dolfin::Restriction> restriction):
 
132
    dolfin::FunctionSpace(dolfin::reference_to_no_delete_pointer(restriction->mesh()),
 
133
                          std::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(std::shared_ptr<ufc::finite_element>(new %(ufc_finite_element_classname)s()))),
 
134
                          std::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(std::shared_ptr<ufc::dofmap>(new %(ufc_dofmap_classname)s()),
 
135
                                                                                     restriction)))
 
136
  {
 
137
    // Do nothing
 
138
  }
 
139
 
 
140
  // Copy constructor
 
141
  ~%(classname)s()
 
142
  {
 
143
  }
 
144
 
 
145
};
 
146
"""
 
147
#-------------------------------------------------------------------------------
 
148
def apply_function_space_template(name, element_name, dofmap_name):
 
149
    args = {"classname": name,
 
150
            "ufc_finite_element_classname": element_name,
 
151
            "ufc_dofmap_classname": dofmap_name }
 
152
    return function_space_template % args