DOLFIN
DOLFIN C++ interface
SystemAssembler.h
1 // Copyright (C) 2008-2015 Kent-Andre Mardal and Garth N. Wells
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 // Modified by Anders Logg 2008-2011
19 
20 #ifndef __SYSTEM_ASSEMBLER_H
21 #define __SYSTEM_ASSEMBLER_H
22 
23 #include <array>
24 #include <map>
25 #include <memory>
26 #include <vector>
27 
28 #include "DirichletBC.h"
29 #include "AssemblerBase.h"
30 
31 namespace ufc
32 {
33  class cell;
34  class cell_integral;
35  class exterior_facet_integral;
36  class interior_facet_integral;
37 }
38 
39 namespace dolfin
40 {
41 
42  // Forward declarations
43  template<typename T> class ArrayView;
44  class Cell;
45  class Facet;
46  class Form;
47  class GenericDofMap;
48  class GenericMatrix;
49  class GenericVector;
50  template<typename T> class MeshFunction;
51  class UFC;
52 
57 
59  {
60  public:
61 
63  SystemAssembler(std::shared_ptr<const Form> a,
64  std::shared_ptr<const Form> L,
65  std::vector<std::shared_ptr<const DirichletBC>> bcs);
66 
69 
71  void assemble(GenericMatrix& A);
72 
74  void assemble(GenericVector& b);
75 
79  void assemble(GenericMatrix& A, GenericVector& b, const GenericVector& x0);
80 
84  void assemble(GenericVector& b, const GenericVector& x0);
85 
86  private:
87 
88  // Class to hold temporary data
89  class Scratch
90  {
91  public:
92  Scratch(const Form& a, const Form& L);
93  ~Scratch();
94  std::array<std::vector<double>, 2> Ae;
95  };
96 
97  // Check form arity
98  static void check_arity(std::shared_ptr<const Form> a,
99  std::shared_ptr<const Form> L);
100 
101  // Check if _bcs[bc_index] is part of FunctionSpace fs
102  bool check_functionspace_for_bc
103  (std::shared_ptr<const FunctionSpace> fs, std::size_t bc_index);
104 
105  // Assemble system
106  void assemble(GenericMatrix* A, GenericVector* b,
107  const GenericVector* x0);
108 
109  // Bilinear and linear forms
110  std::shared_ptr<const Form> _a, _l;
111 
112  // Boundary conditions
113  std::vector<std::shared_ptr<const DirichletBC>> _bcs;
114 
115  static void cell_wise_assembly(
116  std::array<GenericTensor*, 2>& tensors,
117  std::array<UFC*, 2>& ufc,
118  Scratch& data,
119  const std::vector<DirichletBC::Map>& boundary_values,
120  std::shared_ptr<const MeshFunction<std::size_t>> cell_domains,
121  std::shared_ptr<const MeshFunction<std::size_t>> exterior_facet_domains);
122 
123  static void facet_wise_assembly(
124  std::array<GenericTensor*, 2>& tensors,
125  std::array<UFC*, 2>& ufc,
126  Scratch& data,
127  const std::vector<DirichletBC::Map>& boundary_values,
128  std::shared_ptr<const MeshFunction<std::size_t>> cell_domains,
129  std::shared_ptr<const MeshFunction<std::size_t>> exterior_facet_domains,
130  std::shared_ptr<const MeshFunction<std::size_t>> interior_facet_domains);
131 
132  // Compute exterior facet (and possibly connected cell)
133  // contribution
134  static void compute_exterior_facet_tensor(
135  std::array<std::vector<double>, 2>& Ae,
136  std::array<UFC*, 2>& ufc,
137  ufc::cell& ufc_cell,
138  std::vector<double>& coordinate_dofs,
139  const std::array<bool, 2>& tensor_required_cell,
140  const std::array<bool, 2>& tensor_required_facet,
141  const Cell& cell,
142  const Facet& facet,
143  const std::array<const ufc::cell_integral*, 2>& cell_integrals,
144  const std::array<const ufc::exterior_facet_integral*, 2>& exterior_facet_integrals,
145  const bool compute_cell_tensor);
146 
147  // Compute interior facet (and possibly connected cell)
148  // contribution
149  static void compute_interior_facet_tensor(
150  std::array<UFC*, 2>& ufc,
151  std::array<ufc::cell, 2>& ufc_cell,
152  std::array<std::vector<double>, 2>& coordinate_dofs,
153  const std::array<bool, 2>& tensor_required_cell,
154  const std::array<bool, 2>& tensor_required_facet,
155  const std::array<Cell, 2>& cell,
156  const std::array<std::size_t, 2>& local_facet,
157  const bool facet_owner,
158  const std::array<const ufc::cell_integral*, 2>& cell_integrals,
159  const std::array<const ufc::interior_facet_integral*, 2>& interior_facet_integrals,
160  const std::array<std::size_t, 2>& matrix_size,
161  const std::size_t vector_size,
162  const std::array<bool, 2> compute_cell_tensor);
163 
164  // Modified matrix insertion for case when rhs has facet integrals
165  // and lhs has no facet integrals
166  static void matrix_block_add(
167  GenericTensor& tensor,
168  std::vector<double>& Ae,
169  std::vector<double>& macro_A,
170  const std::array<bool, 2>& add_local_tensor,
171  const std::array<std::vector<ArrayView<const la_index>>, 2>& cell_dofs);
172 
173  static void apply_bc(double* A, double* b,
174  const std::vector<DirichletBC::Map>& boundary_values,
175  const ArrayView<const dolfin::la_index>& global_dofs0,
176  const ArrayView<const dolfin::la_index>& global_dofs1);
177 
178  // Return true if cell has an Dirichlet/essential boundary
179  // condition applied
180  static bool has_bc(const DirichletBC::Map& boundary_values,
182 
183  // Return true if element matrix is required
184  static bool
185  cell_matrix_required(const GenericTensor* A,
186  const void* integral,
187  const std::vector<DirichletBC::Map>& boundary_values,
189 
190  };
191 
192 }
193 
194 #endif
Base class for UFC code generated by FFC for DOLFIN with option -l.
Definition: Form.h:85
Definition: adapt.h:29
std::unordered_map< std::size_t, double > Map
map type used by DirichletBC
Definition: DirichletBC.h:130
Definition: Extrapolation.h:34
A Cell is a MeshEntity of topological codimension 0.
Definition: Cell.h:42
A common interface for arbitrary rank tensors.
Definition: GenericTensor.h:48
Definition: ArrayView.h:31
This class defines a common interface for matrices.
Definition: GenericMatrix.h:46
void assemble(GenericTensor &A, const Form &a)
Assemble tensor.
Definition: assemble.cpp:31
Provide some common functions used in assembler classes.
Definition: AssemblerBase.h:41
A Facet is a MeshEntity of topological codimension 1.
Definition: Facet.h:39
This class defines a common interface for vectors.
Definition: GenericVector.h:47
Definition: SystemAssembler.h:58