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 
89  MultiMeshDirichletBC(std::shared_ptr<const MultiMeshFunctionSpace> V,
90  std::shared_ptr<const GenericFunction> g,
91  std::shared_ptr<const SubDomain> sub_domain,
92  std::size_t part,
93  std::string method="topological",
94  bool check_midpoint=true,
95  bool exclude_overlapped_boundaries=true);
96 
112  MultiMeshDirichletBC(std::shared_ptr<const MultiMeshFunctionSpace> V,
113  std::shared_ptr<const GenericFunction> g,
114  std::shared_ptr<const MeshFunction<std::size_t>> sub_domains,
115  std::size_t sub_domain,
116  std::size_t part,
117  std::string method="topological");
118 
125 
128 
133  std::shared_ptr<const MultiMeshFunctionSpace> function_space() const
134  { return _function_space; }
135 
140  std::shared_ptr<DirichletBC> view(std::size_t part) const
141  {
142  return _bcs.at(part);
143  }
144 
149  void apply(GenericMatrix& A) const;
150 
155  void apply(GenericVector& b) const;
156 
163  void apply(GenericMatrix& A,
164  GenericVector& b) const;
165 
172  void apply(GenericVector& b,
173  const GenericVector& x) const;
174 
183  void apply(GenericMatrix& A,
184  GenericVector& b,
185  const GenericVector& x) const;
186 
191  void zero(GenericMatrix& A) const;
192 
194  void homogenize();
195 
196  private:
197 
198  // Subclass of SubDomain wrapping user-defined subdomain
199  class MultiMeshSubDomain : public SubDomain
200  {
201  public:
202 
203  // Constructor
204  MultiMeshSubDomain(std::shared_ptr<const SubDomain> sub_domain,
205  std::shared_ptr<const MultiMesh> multimesh,
206  bool exclude_overlapped_boundaries);
207 
208  // Destructor
209  ~MultiMeshSubDomain();
210 
211  // Callback for checking whether point is in domain
212  bool inside(const Array<double>& x, bool on_boundary) const;
213 
214  // Set current part
215  void set_current_part(std::size_t current_part);
216 
217  private:
218 
219  // User-defined subdomain
220  std::shared_ptr<const SubDomain> _user_sub_domain;
221 
222  // Multimesh
223  std::shared_ptr<const MultiMesh> _multimesh;
224 
225  // Current part
226  std::size_t _current_part;
227 
228  // Check whether to exclude boundaries overlapped by other meshes
229  bool _exclude_overlapped_boundaries;
230 
231  };
232 
233  // Multimesh function space
234  std::shared_ptr<const MultiMeshFunctionSpace> _function_space;
235 
236  // Map from parts to boundary conditions
237  std::map<std::size_t, std::shared_ptr<DirichletBC>> _bcs;
238 
239  // Wrapper of user-defined subdomain
240  mutable std::shared_ptr<MultiMeshSubDomain> _sub_domain;
241 
242  // Check whether to exclude boundaries overlapped by other meshes
243  bool _exclude_overlapped_boundaries;
244 
245  };
246 
247 }
248 
249 #endif
std::shared_ptr< DirichletBC > view(std::size_t part) const
Definition: MultiMeshDirichletBC.h:140
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:159
Definition: SubDomain.h:42
Definition: MultiMeshDirichletBC.h:42
Definition: adapt.h:29
void homogenize()
Set value to 0.0.
Definition: MultiMeshDirichletBC.cpp:252
Definition: Array.h:41
std::shared_ptr< const MultiMeshFunctionSpace > function_space() const
Definition: MultiMeshDirichletBC.h:133
This class defines a common interface for matrices.
Definition: GenericMatrix.h:46
void zero(GenericMatrix &A) const
Definition: MultiMeshDirichletBC.cpp:238
This class defines a common interface for vectors.
Definition: GenericVector.h:47
void apply(GenericMatrix &A) const
Definition: MultiMeshDirichletBC.cpp:164