DOLFIN
DOLFIN C++ interface
LocalSolver.h
1// Copyright (C) 2013-2015 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#ifndef __LOCAL_SOLVER_H
19#define __LOCAL_SOLVER_H
20
21#include <memory>
22#include <vector>
23#include <Eigen/Cholesky>
24#include <Eigen/Dense>
25#include <Eigen/LU>
26
27namespace dolfin
28{
29 // Forward declarations
30 class Form;
31 class Function;
32 class GenericDofMap;
33 class GenericVector;
34
36
64 {
65 public:
66
68 enum class SolverType {LU, Cholesky};
69
76 LocalSolver(std::shared_ptr<const Form> a, std::shared_ptr<const Form> L,
77 SolverType solver_type=SolverType::LU);
78
83 LocalSolver(std::shared_ptr<const Form> a, SolverType solver_type=SolverType::LU);
84
94 void solve_global_rhs(Function& u) const;
95
106 void solve_local_rhs(Function& u) const;
107
114 void solve_local(GenericVector& x, const GenericVector& b,
115 const GenericDofMap& dofmap_b) const;
116
118 void factorize();
119
121 void clear_factorization();
122
123 private:
124
125 // Bilinear and linear forms
126 std::shared_ptr<const Form> _a, _formL;
127
128 // Solver type to use
129 const SolverType _solver_type;
130
131 // Cached LU factorisations of matrices (_spd==false)
132 std::vector<Eigen::PartialPivLU<Eigen::Matrix<double, Eigen::Dynamic,
133 Eigen::Dynamic,
134 Eigen::RowMajor>>> _lu_cache;
135
136 // Cached Cholesky factorisations of matrices (_spd==true)
137 std::vector<Eigen::LLT<Eigen::Matrix<double, Eigen::Dynamic,
138 Eigen::Dynamic,
139 Eigen::RowMajor>>> _cholesky_cache;
140
141 // Helper function that does the actual calculations
142 void _solve_local(GenericVector& x,
143 const GenericVector* global_b,
144 const GenericDofMap* dofmap_L) const;
145 };
146
147}
148
149#endif
Definition: Function.h:66
This class provides a generic interface for dof maps.
Definition: GenericDofMap.h:50
This class defines a common interface for vectors.
Definition: GenericVector.h:48
Solve problems cell-wise.
Definition: LocalSolver.h:64
void clear_factorization()
Reset (clear) any stored factorizations.
Definition: LocalSolver.cpp:318
void solve_local(GenericVector &x, const GenericVector &b, const GenericDofMap &dofmap_b) const
Definition: LocalSolver.cpp:92
void solve_local_rhs(Function &u) const
Definition: LocalSolver.cpp:82
void factorize()
Factorise the local LHS matrices for all cells and store in cache.
Definition: LocalSolver.cpp:242
void solve_global_rhs(Function &u) const
Definition: LocalSolver.cpp:65
LocalSolver(std::shared_ptr< const Form > a, std::shared_ptr< const Form > L, SolverType solver_type=SolverType::LU)
Definition: LocalSolver.cpp:47
SolverType
SolverType.
Definition: LocalSolver.h:68
Definition: adapt.h:30