Loading...
Searching...
No Matches
LocalSolver.h
// Copyright (C) 2013-2015 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/>.
#ifndef __LOCAL_SOLVER_H
#define __LOCAL_SOLVER_H
#include <memory>
#include <vector>
#include <Eigen/Cholesky>
#include <Eigen/Dense>
#include <Eigen/LU>
namespace dolfin
{
// Forward declarations
class Form;
class Function;
class GenericDofMap;
class GenericVector;
class LocalSolver
{
public:
enum class SolverType {LU, Cholesky};
LocalSolver(std::shared_ptr<const Form> a, std::shared_ptr<const Form> L,
SolverType solver_type=SolverType::LU);
LocalSolver(std::shared_ptr<const Form> a, SolverType solver_type=SolverType::LU);
void solve_global_rhs(Function& u) const;
void solve_local_rhs(Function& u) const;
void solve_local(GenericVector& x, const GenericVector& b,
const GenericDofMap& dofmap_b) const;
void factorize();
void clear_factorization();
private:
// Bilinear and linear forms
std::shared_ptr<const Form> _a, _formL;
// Solver type to use
const SolverType _solver_type;
// Cached LU factorisations of matrices (_spd==false)
std::vector<Eigen::PartialPivLU<Eigen::Matrix<double, Eigen::Dynamic,
Eigen::Dynamic,
Eigen::RowMajor>>> _lu_cache;
// Cached Cholesky factorisations of matrices (_spd==true)
std::vector<Eigen::LLT<Eigen::Matrix<double, Eigen::Dynamic,
Eigen::Dynamic,
Eigen::RowMajor>>> _cholesky_cache;
// Helper function that does the actual calculations
void _solve_local(GenericVector& x,
const GenericVector* global_b,
const GenericDofMap* dofmap_L) const;
};
}
#endif
dolfin::Form
Base class for UFC code generated by FFC for DOLFIN with option -l.
Definition Form.h:86
dolfin::Function
Definition Function.h:66
dolfin::GenericDofMap
This class provides a generic interface for dof maps.
Definition GenericDofMap.h:50
dolfin::GenericVector
This class defines a common interface for vectors.
Definition GenericVector.h:48
dolfin::LocalSolver::clear_factorization
void clear_factorization()
Reset (clear) any stored factorizations.
Definition LocalSolver.cpp:318
dolfin::LocalSolver::solve_local
void solve_local(GenericVector &x, const GenericVector &b, const GenericDofMap &dofmap_b) const
Definition LocalSolver.cpp:92
dolfin::LocalSolver::solve_local_rhs
void solve_local_rhs(Function &u) const
Definition LocalSolver.cpp:82
dolfin::LocalSolver::factorize
void factorize()
Factorise the local LHS matrices for all cells and store in cache.
Definition LocalSolver.cpp:242
dolfin::LocalSolver::solve_global_rhs
void solve_global_rhs(Function &u) const
Definition LocalSolver.cpp:65
dolfin::LocalSolver::LocalSolver
LocalSolver(std::shared_ptr< const Form > a, std::shared_ptr< const Form > L, SolverType solver_type=SolverType::LU)
Definition LocalSolver.cpp:47
dolfin::LocalSolver::SolverType
SolverType
SolverType.
Definition LocalSolver.h:68
dolfin
Definition adapt.h:30