lduMatrixPreconditioner.C 3.88 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
5
    \\  /    A nd           | www.openfoam.com
6
     \\/     M anipulation  |
OpenFOAM bot's avatar
OpenFOAM bot committed
7
-------------------------------------------------------------------------------
OpenFOAM bot's avatar
OpenFOAM bot committed
8
    Copyright (C) 2011-2016 OpenFOAM Foundation
9
    Copyright (C) 2019 OpenCFD Ltd.
10 11 12 13
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

14 15 16 17
    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
18 19 20 21 22 23 24

    OpenFOAM 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 General Public License
    for more details.

    You should have received a copy of the GNU General Public License
25
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

\*---------------------------------------------------------------------------*/

#include "lduMatrix.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
{
    defineRunTimeSelectionTable(lduMatrix::preconditioner, symMatrix);
    defineRunTimeSelectionTable(lduMatrix::preconditioner, asymMatrix);
}


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

42
Foam::word Foam::lduMatrix::preconditioner::getName
43 44 45 46 47 48
(
    const dictionary& solverControls
)
{
    word name;

49 50 51 52
    // Handle primitive or dictionary entry
    const entry& e =
        solverControls.lookupEntry("preconditioner", keyType::LITERAL);

53 54
    if (e.isDict())
    {
55
        e.dict().readEntry("preconditioner", name);
56 57 58 59 60 61 62 63 64 65
    }
    else
    {
        e.stream() >> name;
    }

    return name;
}


66 67 68 69
Foam::autoPtr<Foam::lduMatrix::preconditioner>
Foam::lduMatrix::preconditioner::New
(
    const solver& sol,
70
    const dictionary& solverControls
71 72
)
{
73 74
    word name;

75 76 77 78 79
    // Handle primitive or dictionary entry

    const entry& e =
        solverControls.lookupEntry("preconditioner", keyType::LITERAL);

80 81
    if (e.isDict())
    {
82
        e.dict().readEntry("preconditioner", name);
83 84 85 86 87 88 89
    }
    else
    {
        e.stream() >> name;
    }

    const dictionary& controls = e.isDict() ? e.dict() : dictionary::null;
90 91 92

    if (sol.matrix().symmetric())
    {
93
        auto cstrIter = symMatrixConstructorTablePtr_->cfind(name);
94

95
        if (!cstrIter.found())
96
        {
97 98 99 100 101 102 103
            FatalIOErrorInLookup
            (
                controls,
                "symmetric matrix preconditioner",
                name,
                *symMatrixConstructorTablePtr_
            ) << exit(FatalIOError);
104 105 106 107
        }

        return autoPtr<lduMatrix::preconditioner>
        (
108
            cstrIter()
109 110
            (
                sol,
111
                controls
112 113 114 115 116
            )
        );
    }
    else if (sol.matrix().asymmetric())
    {
117
        auto cstrIter = asymMatrixConstructorTablePtr_->cfind(name);
118

119
        if (!cstrIter.found())
120
        {
121 122 123 124 125 126 127
            FatalIOErrorInLookup
            (
                controls,
                "asymmetric matrix preconditioner",
                name,
                *asymMatrixConstructorTablePtr_
            ) << exit(FatalIOError);
128 129 130 131
        }

        return autoPtr<lduMatrix::preconditioner>
        (
132
            cstrIter()
133 134
            (
                sol,
135
                controls
136 137 138 139
            )
        );
    }

140 141
    FatalIOErrorInFunction(controls)
        << "cannot solve incomplete matrix, "
142 143 144
           "no diagonal or off-diagonal coefficient"
        << exit(FatalIOError);

145
    return nullptr;
146 147 148 149
}


// ************************************************************************* //