DOLFIN
DOLFIN C++ interface
Loading...
Searching...
No Matches
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// Modified by Cecile Daversin-Catty 2018
20
21#ifndef __SYSTEM_ASSEMBLER_H
22#define __SYSTEM_ASSEMBLER_H
23
24#include <array>
25#include <map>
26#include <memory>
27#include <vector>
28
29#include "DirichletBC.h"
30#include "AssemblerBase.h"
31
32namespace ufc
33{
34 class cell;
35 class cell_integral;
36 class exterior_facet_integral;
37 class interior_facet_integral;
38}
39
40namespace dolfin
41{
42
43 // Forward declarations
44 template<typename T> class ArrayView;
45 class Cell;
46 class Facet;
47 class Form;
48 class GenericDofMap;
49 class GenericMatrix;
50 class GenericVector;
51 template<typename T> class MeshFunction;
52 class UFC;
53
58
60 {
61 public:
62
64 SystemAssembler(std::shared_ptr<const Form> a,
65 std::shared_ptr<const Form> L,
66 std::vector<std::shared_ptr<const DirichletBC>> bcs);
67
70 SystemAssembler(std::vector<std::shared_ptr<const Form>> a,
71 std::vector<std::shared_ptr<const Form>> L,
72 std::vector<std::vector<std::shared_ptr<const DirichletBC>>> bcs);
73
76 SystemAssembler(std::vector<std::shared_ptr<const Form>> a,
77 std::vector<std::shared_ptr<const Form>> L,
78 std::vector<std::shared_ptr<const DirichletBC>> bcs0,
79 std::vector<std::shared_ptr<const DirichletBC>> bcs1);
80
83
85 void assemble(GenericMatrix& A);
86
88 void assemble(GenericVector& b);
89
93 void assemble(GenericMatrix& A, GenericVector& b, const GenericVector& x0);
94
98 void assemble(GenericVector& b, const GenericVector& x0);
99
101 void assemble(std::vector<std::shared_ptr<GenericMatrix>> A,
102 std::vector<std::shared_ptr<GenericVector>> b);
103
104 private:
105
106 // Class to hold temporary data
107 class Scratch
108 {
109 public:
110 Scratch(const Form& a, const Form& L);
111 ~Scratch();
112 std::array<std::vector<double>, 2> Ae;
113 };
114
115 // Check form arity etc
116 static void check_forms(std::vector<std::shared_ptr<const Form>> a,
117 std::vector<std::shared_ptr<const Form>> L);
118
119 // Assemble system
121 const GenericVector* x0,
122 std::shared_ptr<const Form> a,
123 std::shared_ptr<const Form> L,
124 std::vector<std::vector<std::shared_ptr<const DirichletBC>>> bcs,
125 bool integrate_rhs);
126
127 // Bilinear and linear forms
128 std::vector<std::shared_ptr<const Form>> _a;
129 std::vector<std::shared_ptr<const Form>> _l;
130
131 // Boundary conditions for each space in the forms
132 std::vector<std::vector<std::shared_ptr<const DirichletBC>>> _bcs;
133
134 static void cell_wise_assembly(
135 std::array<GenericTensor*, 2>& tensors,
136 std::array<UFC*, 2>& ufc,
137 Scratch& data,
138 const std::vector<DirichletBC::Map>& boundary_values,
139 std::shared_ptr<const MeshFunction<std::size_t>> cell_domains,
140 std::shared_ptr<const MeshFunction<std::size_t>> exterior_facet_domains,
141 bool integrate_rhs);
142
143 static void facet_wise_assembly(
144 std::array<GenericTensor*, 2>& tensors,
145 std::array<UFC*, 2>& ufc,
146 Scratch& data,
147 const std::vector<DirichletBC::Map>& boundary_values,
148 std::shared_ptr<const MeshFunction<std::size_t>> cell_domains,
149 std::shared_ptr<const MeshFunction<std::size_t>> exterior_facet_domains,
150 std::shared_ptr<const MeshFunction<std::size_t>> interior_facet_domains);
151
152 // Compute exterior facet (and possibly connected cell)
153 // contribution
154 static void compute_exterior_facet_tensor(
155 std::array<std::vector<double>, 2>& Ae,
156 std::array<UFC*, 2>& ufc,
157 ufc::cell& ufc_cell,
158 std::vector<double>& coordinate_dofs,
159 const std::array<bool, 2>& tensor_required_cell,
160 const std::array<bool, 2>& tensor_required_facet,
161 const Cell& cell,
162 const Facet& facet,
163 const std::array<const ufc::cell_integral*, 2>& cell_integrals,
164 const std::array<const ufc::exterior_facet_integral*, 2>& exterior_facet_integrals,
165 const bool compute_cell_tensor);
166
167 // Compute interior facet (and possibly connected cell)
168 // contribution
169 static void compute_interior_facet_tensor(
170 std::array<UFC*, 2>& ufc,
171 std::array<ufc::cell, 2>& ufc_cell,
172 std::array<std::vector<double>, 2>& coordinate_dofs,
173 const std::array<bool, 2>& tensor_required_cell,
174 const std::array<bool, 2>& tensor_required_facet,
175 const std::array<Cell, 2>& cell,
176 const std::array<std::size_t, 2>& local_facet,
177 const bool facet_owner,
178 const std::array<const ufc::cell_integral*, 2>& cell_integrals,
179 const std::array<const ufc::interior_facet_integral*, 2>& interior_facet_integrals,
180 const std::array<std::size_t, 2>& matrix_size,
181 const std::size_t vector_size,
182 const std::array<bool, 2> compute_cell_tensor);
183
184 // Modified matrix insertion for case when rhs has facet integrals
185 // and lhs has no facet integrals
186 static void matrix_block_add(
187 GenericTensor& tensor,
188 std::vector<double>& Ae,
189 std::vector<double>& macro_A,
190 const std::array<bool, 2>& add_local_tensor,
191 const std::array<std::vector<ArrayView<const la_index>>, 2>& cell_dofs);
192
193 static void apply_bc(double* A, double* b,
194 const std::vector<DirichletBC::Map>& boundary_values,
195 const ArrayView<const dolfin::la_index>& global_dofs0,
196 const ArrayView<const dolfin::la_index>& global_dofs1);
197
198 bool check_functionspace_for_bc
199 (std::shared_ptr<const FunctionSpace> fs, std::shared_ptr<const DirichletBC> bc) const;
200
201 // Return true if cell has an Dirichlet/essential boundary
202 // condition applied
203 static bool has_bc(const DirichletBC::Map& boundary_values,
205
206 // Return true if element matrix is required
207 static bool
208 cell_matrix_required(const GenericTensor* A,
209 const void* integral,
210 const std::vector<DirichletBC::Map>& boundary_values,
212
213 };
214
215}
216
217#endif
Definition SystemAssembler.h:44
Provide some common functions used in assembler classes.
Definition AssemblerBase.h:42
A Cell is a MeshEntity of topological codimension 0.
Definition Cell.h:43
std::unordered_map< std::size_t, double > Map
map type used by DirichletBC
Definition DirichletBC.h:130
A Facet is a MeshEntity of topological codimension 1.
Definition Facet.h:40
Base class for UFC code generated by FFC for DOLFIN with option -l.
Definition Form.h:86
This class provides a generic interface for dof maps.
Definition GenericDofMap.h:50
This class defines a common interface for matrices.
Definition GenericMatrix.h:47
A common interface for arbitrary rank tensors.
Definition GenericTensor.h:49
This class defines a common interface for vectors.
Definition GenericVector.h:48
Definition RegularCutRefinement.h:31
Definition SystemAssembler.h:60
void assemble(GenericMatrix &A, GenericVector &b)
Assemble system (A, b)
Definition SystemAssembler.cpp:141
SystemAssembler(std::shared_ptr< const Form > a, std::shared_ptr< const Form > L, std::vector< std::shared_ptr< const DirichletBC > > bcs)
Constructor.
Definition SystemAssembler.cpp:54
Definition UFC.h:47
Definition adapt.h:30