Loading...
Searching...
No Matches
DirichletBC.h
// Copyright (C) 2007-2012 Anders Logg and Garth N. Wells
//
// This file is part of DOLFIN.
//
// DOLFIN is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// DOLFIN is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
//
// Modified by Kristian Oelgaard, 2007
// Modified by Johan Hake, 2009
// Modified by Joachim B Haga, 2012
// Modified by Mikael Mortensen, 2014
//
// First added: 2007-04-10
// Last changed: 2014-01-23
//
// FIXME: This class needs some cleanup, in particular collecting
// all data from different representations into a common
// data structure (perhaps an std::vector<std::size_t> with
// facet indices).
#ifndef __DIRICHLET_BC_H
#define __DIRICHLET_BC_H
#include <map>
#include <set>
#include <string>
#include <vector>
#include <boost/multi_array.hpp>
#include <memory>
#include <unordered_map>
#include <dolfin/common/types.h>
#include <dolfin/common/Hierarchical.h>
#include <dolfin/common/MPI.h>
#include <dolfin/common/Variable.h>
namespace dolfin
{
class GenericFunction;
class FunctionSpace;
class Facet;
class GenericMatrix;
class GenericVector;
class SubDomain;
template<typename T> class MeshFunction;
class DirichletBC : public Hierarchical<DirichletBC>, public Variable
{
public:
typedef std::unordered_map<std::size_t, double> Map;
DirichletBC(std::shared_ptr<const FunctionSpace> V,
std::shared_ptr<const GenericFunction> g,
std::shared_ptr<const SubDomain> sub_domain,
std::string method="topological",
bool check_midpoint=true);
DirichletBC(std::shared_ptr<const FunctionSpace> V,
std::shared_ptr<const GenericFunction> g,
std::shared_ptr<const MeshFunction<std::size_t>> sub_domains,
std::size_t sub_domain,
std::string method="topological");
// TODO: Remove/deprecate this function
DirichletBC(std::shared_ptr<const FunctionSpace> V,
std::shared_ptr<const GenericFunction> g,
std::size_t sub_domain,
std::string method="topological");
DirichletBC(std::shared_ptr<const FunctionSpace> V,
std::shared_ptr<const GenericFunction> g,
const std::vector<std::size_t>& markers,
std::string method="topological");
DirichletBC(const DirichletBC& bc);
~DirichletBC();
const DirichletBC& operator= (const DirichletBC& bc);
void apply(GenericMatrix& A) const;
void apply(GenericVector& b) const;
void apply(GenericMatrix& A, GenericVector& b) const;
void apply(GenericVector& b, const GenericVector& x) const;
void apply(GenericMatrix& A, GenericVector& b,
const GenericVector& x) const;
void get_boundary_values(Map& boundary_values) const;
void gather(Map& boundary_values) const;
void zero(GenericMatrix& A) const;
void zero_columns(GenericMatrix& A, GenericVector& b,
double diag_val=0, bool transpose=false) const;
const std::vector<std::size_t>& markers() const;
std::shared_ptr<const FunctionSpace> function_space() const
{ return _function_space; }
std::shared_ptr<const GenericFunction> value() const;
std::shared_ptr<const SubDomain> user_sub_domain() const;
void set_value(std::shared_ptr<const GenericFunction> g);
void homogenize();
std::string method() const;
static Parameters default_parameters()
{
Parameters p("dirichlet_bc");
p.add("use_ident", true);
p.add("check_dofmap_range", true);
return p;
}
private:
class LocalData;
// Apply boundary conditions, common method
void apply(GenericMatrix* A, GenericVector* b,
const GenericVector* x) const;
// Check input data to constructor
void check() const;
// Initialize facets (from sub domain, mesh, etc)
void init_facets(const MPI_Comm mpi_comm) const;
// Initialize sub domain markers from sub domain
void
init_from_sub_domain(std::shared_ptr<const SubDomain> sub_domain) const;
// Initialize sub domain markers from MeshFunction
void init_from_mesh_function(const MeshFunction<std::size_t>& sub_domains,
std::size_t sub_domain) const;
// Initialize sub domain markers from mesh
void init_from_mesh(std::size_t sub_domain) const;
// Compute dofs and values for application of boundary conditions
// using given method
void compute_bc(Map& boundary_values, LocalData& data,
std::string method) const;
// Compute boundary values for facet (topological approach)
void compute_bc_topological(Map& boundary_values,
LocalData& data) const;
// Compute boundary values for facet (geometrical approach)
void compute_bc_geometric(Map& boundary_values,
LocalData& data) const;
// Compute boundary values for facet (pointwise approach)
void compute_bc_pointwise(Map& boundary_values,
LocalData& data) const;
// Check if the point is in the same plane as the given facet
bool on_facet(const double* coordinates, const Facet& facet) const;
// Check arguments for compatibility of tensors and dofmap,
// dim is means an axis to which bc applies
void check_arguments(GenericMatrix* A, GenericVector* b,
const GenericVector* x,
std::size_t dim) const;
// The function space (possibly a sub function space)
std::shared_ptr<const FunctionSpace> _function_space;
// The function
std::shared_ptr<const GenericFunction> _g;
// Search method
std::string _method;
// Possible search methods
static const std::set<std::string> methods;
public:
// User defined sub domain
std::shared_ptr<const SubDomain> _user_sub_domain;
private:
// Cached number of bc dofs, used for memory allocation on second use
mutable std::size_t _num_dofs;
// Boundary facets, stored by facet index (local to process)
mutable std::vector<std::size_t> _facets;
// Cells attached to boundary, stored by cell index with map to
// local dof number
mutable std::map<std::size_t, std::vector<std::size_t>>
_cells_to_localdofs;
// User defined mesh function
std::shared_ptr<const MeshFunction<std::size_t>> _user_mesh_function;
// User defined sub domain marker for mesh or mesh function
std::size_t _user_sub_domain_marker;
// Flag for whether midpoints should be checked
bool _check_midpoint;
// Local data for application of boundary conditions
class LocalData
{
public:
// Constructor
LocalData(const FunctionSpace& V);
// Coefficients
std::vector<double> w;
// Facet dofs
std::vector<std::size_t> facet_dofs;
// Coordinates for dofs
boost::multi_array<double, 2> coordinates;
};
};
}
#endif
dolfin::DirichletBC::value
std::shared_ptr< const GenericFunction > value() const
Definition DirichletBC.cpp:403
dolfin::DirichletBC::function_space
std::shared_ptr< const FunctionSpace > function_space() const
Definition DirichletBC.h:306
dolfin::DirichletBC::markers
const std::vector< std::size_t > & markers() const
Definition DirichletBC.cpp:398
dolfin::DirichletBC::operator=
const DirichletBC & operator=(const DirichletBC &bc)
Definition DirichletBC.cpp:129
dolfin::DirichletBC::apply
void apply(GenericMatrix &A) const
Definition DirichletBC.cpp:149
dolfin::DirichletBC::homogenize
void homogenize()
Set value to 0.0.
Definition DirichletBC.cpp:413
dolfin::DirichletBC::default_parameters
static Parameters default_parameters()
Definition DirichletBC.h:339
dolfin::DirichletBC::~DirichletBC
~DirichletBC()
Destructor.
Definition DirichletBC.cpp:124
dolfin::DirichletBC::set_value
void set_value(std::shared_ptr< const GenericFunction > g)
Definition DirichletBC.cpp:439
dolfin::DirichletBC::Map
std::unordered_map< std::size_t, double > Map
map type used by DirichletBC
Definition DirichletBC.h:130
dolfin::DirichletBC::zero
void zero(GenericMatrix &A) const
Definition DirichletBC.cpp:283
dolfin::DirichletBC::get_boundary_values
void get_boundary_values(Map &boundary_values) const
Definition DirichletBC.cpp:273
dolfin::DirichletBC::gather
void gather(Map &boundary_values) const
Definition DirichletBC.cpp:176
dolfin::DirichletBC::method
std::string method() const
Definition DirichletBC.cpp:444
dolfin::DirichletBC::user_sub_domain
std::shared_ptr< const SubDomain > user_sub_domain() const
Definition DirichletBC.cpp:408
dolfin::DirichletBC::DirichletBC
DirichletBC(std::shared_ptr< const FunctionSpace > V, std::shared_ptr< const GenericFunction > g, std::shared_ptr< const SubDomain > sub_domain, std::string method="topological", bool check_midpoint=true)
Definition DirichletBC.cpp:69
dolfin::DirichletBC::zero_columns
void zero_columns(GenericMatrix &A, GenericVector &b, double diag_val=0, bool transpose=false) const
Definition DirichletBC.cpp:311
dolfin::Facet
A Facet is a MeshEntity of topological codimension 1.
Definition Facet.h:40
dolfin::FunctionSpace
Definition FunctionSpace.h:54
dolfin::GenericFunction
Definition GenericFunction.h:54
dolfin::GenericMatrix
This class defines a common interface for matrices.
Definition GenericMatrix.h:47
dolfin::GenericVector
This class defines a common interface for vectors.
Definition GenericVector.h:48
dolfin::Hierarchical< DirichletBC >::Hierarchical
Hierarchical(DirichletBC &self)
Definition Hierarchical.h:48
dolfin::MeshFunction
Definition MeshFunction.h:58
dolfin::Parameters
Definition Parameters.h:95
dolfin::Parameters::add
void add(std::string key)
Definition Parameters.h:128
dolfin::SubDomain
Definition SubDomain.h:43
dolfin::Variable::Variable
Variable()
Create unnamed variable.
Definition Variable.cpp:31
dolfin
Definition adapt.h:30