DOLFIN
DOLFIN C++ interface
FunctionAssigner.h
1// Copyright (C) 2013 Johan Hake
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// First added: 2013-09-20
19// Last changed: 2013-11-11
20
21#ifndef __DOLFIN_FUNCTION_ASSIGNER_H
22#define __DOLFIN_FUNCTION_ASSIGNER_H
23
24#include <vector>
25#include <memory>
26
27namespace dolfin
28{
29
30 class Function;
31 class FunctionSpace;
32 class Mesh;
33
41 {
42 public:
43
53 FunctionAssigner(std::shared_ptr<const FunctionSpace> receiving_space,
54 std::shared_ptr<const FunctionSpace> assigning_space);
55
68 FunctionAssigner(std::vector<std::shared_ptr<const FunctionSpace>> receiving_spaces,
69 std::shared_ptr<const FunctionSpace> assigning_space);
70
83 FunctionAssigner(std::shared_ptr<const FunctionSpace> receiving_space,
84 std::vector<std::shared_ptr<const FunctionSpace>> assigning_spaces);
85
93 void assign(std::shared_ptr<Function> receiving_func,
94 std::shared_ptr<const Function> assigning_func) const;
95
104 void assign(std::shared_ptr<Function> receiving_func,
105 std::vector<std::shared_ptr<const Function>> assigning_funcs) const;
106
115 void assign(std::vector<std::shared_ptr<Function>> receiving_funcs,
116 std::shared_ptr<const Function> assigning_func) const;
117
120
122 inline std::size_t num_assigning_functions() const
123 { return _assigning_spaces.size(); }
124
126 inline std::size_t num_receiving_functions() const
127 { return _receiving_spaces.size(); }
128
129 private:
130
131 // Utility function to actually do the assignment
132 void _assign(std::vector<std::shared_ptr<Function>> receiving_funcs,
133 std::vector<std::shared_ptr<const Function>> assigning_funcs) const;
134
135 // Check the compatibility of the meshes and return a reference to
136 // the mesh
137 const Mesh& _get_mesh() const;
138
139 // Check the compatibility of the arguments to the constructor and
140 // build indices for assignment
141 void _check_and_build_indices(const Mesh& mesh,
142 const std::vector<std::shared_ptr<const FunctionSpace> >& receiving_spaces,
143 const std::vector<std::shared_ptr<const FunctionSpace> >& assigning_spaces);
144
145 // Shared pointers to the original FunctionSpaces
146 std::vector<std::shared_ptr<const FunctionSpace>> _receiving_spaces;
147 std::vector<std::shared_ptr<const FunctionSpace>> _assigning_spaces;
148
149 // Indices for accessing values to receiving Functions
150 std::vector<std::vector<la_index>> _receiving_indices;
151
152 // Indices for accessing values from assigning Functions
153 std::vector<std::vector<la_index>> _assigning_indices;
154
155 // Vector for value transfer between assigning and receiving Function
156 mutable std::vector<std::vector<double> > _transfer;
157
158 };
159}
160
161#endif
Definition: FunctionAssigner.h:41
~FunctionAssigner()
Destructor.
Definition: FunctionAssigner.cpp:113
std::size_t num_receiving_functions() const
Return the number of receiving functions.
Definition: FunctionAssigner.h:126
FunctionAssigner(std::shared_ptr< const FunctionSpace > receiving_space, std::shared_ptr< const FunctionSpace > assigning_space)
Definition: FunctionAssigner.cpp:36
void assign(std::shared_ptr< Function > receiving_func, std::shared_ptr< const Function > assigning_func) const
Definition: FunctionAssigner.cpp:119
std::size_t num_assigning_functions() const
Return the number of assigning functions.
Definition: FunctionAssigner.h:122
Definition: Mesh.h:84
Definition: adapt.h:30