1
// Copyright (C) 2012 Anders Logg
3
// This file is part of DOLFIN.
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.
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.
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/>.
18
// First added: 2012-11-14
19
// Last changed: 2012-11-19
21
#include <dolfin/common/NoDeleter.h>
22
#include "SubDomain.h"
23
#include "Restriction.h"
25
using namespace dolfin;
27
//-----------------------------------------------------------------------------
28
Restriction::Restriction(const Mesh& mesh,
29
const SubDomain& sub_domain)
31
init_from_subdomain(mesh, sub_domain, mesh.topology().dim());
33
//-----------------------------------------------------------------------------
34
Restriction::Restriction(const Mesh& mesh,
35
const SubDomain& sub_domain, std::size_t dim)
37
init_from_subdomain(mesh, sub_domain, dim);
39
//-----------------------------------------------------------------------------
40
Restriction::Restriction(const MeshFunction<std::size_t>& domain_markers,
41
std::size_t domain_number)
42
: _domain_markers(reference_to_no_delete_pointer(domain_markers)),
43
_domain_number(domain_number)
47
//-----------------------------------------------------------------------------
48
Restriction::Restriction(boost::shared_ptr<const MeshFunction<std::size_t> > domain_markers,
49
std::size_t domain_number)
50
: _domain_markers(domain_markers),
51
_domain_number(domain_number)
55
//-----------------------------------------------------------------------------
56
const Mesh& Restriction::mesh() const
58
dolfin_assert(_domain_markers);
59
return _domain_markers->mesh();
61
//-----------------------------------------------------------------------------
62
std::size_t Restriction::dim() const
64
dolfin_assert(_domain_markers);
65
return _domain_markers->dim();
67
//-----------------------------------------------------------------------------
68
void Restriction::init_from_subdomain(const Mesh& mesh,
69
const SubDomain& sub_domain, std::size_t dim)
71
// Create mesh function
72
MeshFunction<std::size_t>* __domain_markers = new MeshFunction<std::size_t>(mesh, dim);
73
dolfin_assert(__domain_markers);
75
// Set all markers to 1 and mark current domain as 0
76
__domain_markers->set_all(1);
77
sub_domain.mark(*__domain_markers, 0);
80
// Store shared pointer
81
_domain_markers = boost::shared_ptr<const MeshFunction<std::size_t> >(__domain_markers);
83
//-----------------------------------------------------------------------------