DOLFIN
DOLFIN C++ interface
MultiMeshDirichletBC.h
1 // Copyright (C) 2014-2016 Anders Logg
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 4 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: 2014-05-12
19 // Last changed: 2016-03-02
20 
21 #ifndef __MULTI_MESH_DIRICHLET_BC_H
22 #define __MULTI_MESH_DIRICHLET_BC_H
23 
24 #include <vector>
25 #include <memory>
26 #include <dolfin/mesh/SubDomain.h>
27 
28 namespace dolfin
29 {
30 
31  // Forward declarations
32  class MultiMeshFunctionSpace;
33  class GenericFunction;
34  class SubDomain;
35  class GenericMatrix;
36  class GenericVector;
37  class DirichletBC;
38 
41 
43  {
44  public:
45 
63  MultiMeshDirichletBC(std::shared_ptr<const MultiMeshFunctionSpace> V,
64  std::shared_ptr<const GenericFunction> g,
65  std::shared_ptr<const SubDomain> sub_domain,
66  std::string method="topological",
67  bool check_midpoint=true,
68  bool exclude_overlapped_boundaries=true);
69 
85  MultiMeshDirichletBC(std::shared_ptr<const MultiMeshFunctionSpace> V,
86  std::shared_ptr<const GenericFunction> g,
87  std::shared_ptr<const MeshFunction<std::size_t>> sub_domains,
88  std::size_t sub_domain,
89  std::size_t part,
90  std::string method="topological");
91 
98 
101 
106  std::shared_ptr<const MultiMeshFunctionSpace> function_space() const
107  { return _function_space; }
108 
113  std::shared_ptr<DirichletBC> view(std::size_t part) const
114  {
115  dolfin_assert(part < _bcs.size());
116  return _bcs[part];
117  }
118 
123  void apply(GenericMatrix& A) const;
124 
129  void apply(GenericVector& b) const;
130 
137  void apply(GenericMatrix& A,
138  GenericVector& b) const;
139 
146  void apply(GenericVector& b,
147  const GenericVector& x) const;
148 
157  void apply(GenericMatrix& A,
158  GenericVector& b,
159  const GenericVector& x) const;
160 
165  void zero(GenericMatrix& A) const;
166 
168  void homogenize();
169 
170  private:
171 
172  // Subclass of SubDomain wrapping user-defined subdomain
173  class MultiMeshSubDomain : public SubDomain
174  {
175  public:
176 
177  // Constructor
178  MultiMeshSubDomain(std::shared_ptr<const SubDomain> sub_domain,
179  std::shared_ptr<const MultiMesh> multimesh,
180  bool exclude_overlapped_boundaries);
181 
182  // Destructor
183  ~MultiMeshSubDomain();
184 
185  // Callback for checking whether point is in domain
186  bool inside(const Array<double>& x, bool on_boundary) const;
187 
188  // Set current part
189  void set_current_part(std::size_t current_part);
190 
191  private:
192 
193  // User-defined subdomain
194  std::shared_ptr<const SubDomain> _user_sub_domain;
195 
196  // Multimesh
197  std::shared_ptr<const MultiMesh> _multimesh;
198 
199  // Current part
200  std::size_t _current_part;
201 
202  // Check whether to exclude boundaries overlapped by other meshes
203  bool _exclude_overlapped_boundaries;
204 
205  };
206 
207  // Multimesh function space
208  std::shared_ptr<const MultiMeshFunctionSpace> _function_space;
209 
210  // List of boundary conditions for parts
211  std::vector<std::shared_ptr<DirichletBC>> _bcs;
212 
213  // Wrapper of user-defined subdomain
214  mutable std::shared_ptr<MultiMeshSubDomain> _sub_domain;
215 
216  // Check whether to exclude boundaries overlapped by other meshes
217  bool _exclude_overlapped_boundaries;
218 
219  };
220 
221 }
222 
223 #endif
MultiMeshDirichletBC(std::shared_ptr< const MultiMeshFunctionSpace > V, std::shared_ptr< const GenericFunction > g, std::shared_ptr< const SubDomain > sub_domain, std::string method="topological", bool check_midpoint=true, bool exclude_overlapped_boundaries=true)
Definition: MultiMeshDirichletBC.cpp:35
~MultiMeshDirichletBC()
Destructor.
Definition: MultiMeshDirichletBC.cpp:146
Definition: SubDomain.h:42
Definition: MultiMeshDirichletBC.h:42
Definition: adapt.h:29
void homogenize()
Set value to 0.0.
Definition: MultiMeshDirichletBC.cpp:239
Definition: Array.h:41
void zero(GenericMatrix &A) const
Definition: MultiMeshDirichletBC.cpp:225
void apply(GenericMatrix &A) const
Definition: MultiMeshDirichletBC.cpp:151
std::shared_ptr< DirichletBC > view(std::size_t part) const
Definition: MultiMeshDirichletBC.h:113
std::shared_ptr< const MultiMeshFunctionSpace > function_space() const
Definition: MultiMeshDirichletBC.h:106
This class defines a common interface for matrices.
Definition: GenericMatrix.h:46
This class defines a common interface for vectors.
Definition: GenericVector.h:47