/usr/include/dolfin/fem/LocalSolver.h is in libdolfin-dev 2017.2.0.post0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | // 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;
/// Solve problems cell-wise
/// This class solves problems cell-wise. It computes the local
/// left-hand side A_local which must be square locally but not
/// globally. The right-hand side b_local is either computed locally
/// for one cell or globally for all cells depending on which of the
/// solve_local_rhs or solve_global_rhs methods which are
/// called. You can optionally assemble the right-hand side vector
/// yourself and use the solve_local method. You must then provide
/// the DofMap of the right-hand side.
///
/// The local solver solves A_local x_local = b_local. The result
/// x_local is copied into the global vector x of the provided
/// Function u. You can optionally call the factorize() method to
/// pre-calculate the local left-hand side factorizations to speed
/// up repeated applications of the LocalSolver with the same
/// LHS. The solve_xxx methods will factorise the LHS A_local
/// matrices each time if they are not cached by a previous call to
/// factorize. You can chose upon initialization whether you want
/// Cholesky or LU (default) factorisations.
///
/// For forms with no coupling across cell edges, this function is
/// identical to a global solve. For problems with coupling across
/// cells it is not.
///
/// This class can be used for post-processing solutions,
/// e.g. computing stress fields for visualisation, far more cheaply
/// that using global projections.
class LocalSolver
{
public:
/// SolverType
enum class SolverType {LU, Cholesky};
/// Constructor (shared pointer version)
/// @param a (Form)
/// input LHS form
/// @param L (Form)
/// input RHS form
/// @param solver_type (SolverType)
LocalSolver(std::shared_ptr<const Form> a, std::shared_ptr<const Form> L,
SolverType solver_type=SolverType::LU);
/// Constructor (shared pointer version)
/// @param a (Form)
/// input LHS form
/// @param solver_type (SolverType)
LocalSolver(std::shared_ptr<const Form> a, SolverType solver_type=SolverType::LU);
/// Solve local (cell-wise) problems A_e x_e = b_e, where A_e is
/// the cell matrix LHS and b_e is the global RHS vector b
/// restricted to the cell, i.e. b_e may contain contributions
/// from neighbouring cells. The solution is exact for the case in
/// which there is no coupling between cell contributions to the
/// global matrix A, e.g. the discontinuous Galerkin matrix. The
/// result is copied into x.
/// @param u (Function&)
/// Function
void solve_global_rhs(Function& u) const;
/// Solve local (cell-wise) problems A_e x_e = b_e where A_e and
/// b_e are the cell element tensors. Compared to solve_global_rhs
/// this function calculates local RHS vectors for each cell and
/// hence does not include contributions from neighbouring cells.
///
/// This function is useful for computing (approximate) cell-wise
/// projections, for example for post-processing. It much more
/// efficient than computing global projections.
/// @param u (Function&)
/// Function
void solve_local_rhs(Function& u) const;
/// Solve local problems for given RHS and corresponding dofmap
/// for RHS
/// @param x (GenericVector)
/// @param b (GenericVector)
/// @param dofmap_b (GenericDofMap)
///
void solve_local(GenericVector& x, const GenericVector& b,
const GenericDofMap& dofmap_b) const;
/// Factorise the local LHS matrices for all cells and store in cache
void factorize();
/// Reset (clear) any stored factorizations
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
|