GKOBiCGStab.H 4.58 KB
Newer Older
Gregor Olenik's avatar
Gregor Olenik committed
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
/*---------------------------------------------------------------------------*\
License
    This file is part of OGL.

    OGL 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.

    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
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Class
    Foam::GKOBiCGStab

Author: Gregor Olenik <go@hpsim.de>

SourceFiles
    GKOBiCGStab.C

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

#ifndef GKOBiCGStab_H
#define GKOBiCGStab_H

greole's avatar
Ir (#1)    
greole committed
31
#include "GKOlduBase.H"
Gregor Olenik's avatar
Gregor Olenik committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45

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

namespace Foam {

/*---------------------------------------------------------------------------*\
                           Class GKOBiCGStab Declaration
\*---------------------------------------------------------------------------*/
class GKOBiCGStabFactory {
private:
    // executor where Ginkgo will perform the computation

    const word preconditioner_;

46
47
    const label blockSize_;

Gregor Olenik's avatar
Gregor Olenik committed
48
public:
49
50
51
52
    GKOBiCGStabFactory(const dictionary &dictionary_)
        : preconditioner_(
              dictionary_.lookupOrDefault("preconditioner", word("none"))),
          blockSize_(dictionary_.lookupOrDefault("maxBlockSize", label(16))){};
Gregor Olenik's avatar
Gregor Olenik committed
53
54
55

    std::unique_ptr<gko::solver::Bicgstab<double>::Factory,
                    std::default_delete<gko::solver::Bicgstab<double>::Factory>>
56
57
58
59
    create_solver(
        std::shared_ptr<gko::Executor> exec,
        std::vector<std::shared_ptr<const gko::stop::CriterionFactory>>
            criterion_vec) const
Gregor Olenik's avatar
Gregor Olenik committed
60
    {
61
        if (preconditioner_ == "BJ") return create_BJ(exec, criterion_vec);
62
        return create_default(exec, criterion_vec);
Gregor Olenik's avatar
Gregor Olenik committed
63
64
65
66
    };

    std::unique_ptr<gko::solver::Bicgstab<double>::Factory,
                    std::default_delete<gko::solver::Bicgstab<double>::Factory>>
67
68
69
70
    create_default(
        std::shared_ptr<gko::Executor> exec,
        std::vector<std::shared_ptr<const gko::stop::CriterionFactory>>
            criterion_vec) const
Gregor Olenik's avatar
Gregor Olenik committed
71
72
    {
        return gko::solver::Bicgstab<scalar>::build()
73
            .with_criteria(criterion_vec)
Gregor Olenik's avatar
Gregor Olenik committed
74
75
76
77
78
            .on(exec);
    };

    std::unique_ptr<gko::solver::Bicgstab<double>::Factory,
                    std::default_delete<gko::solver::Bicgstab<double>::Factory>>
79
80
81
    create_BJ(std::shared_ptr<gko::Executor> exec,
              std::vector<std::shared_ptr<const gko::stop::CriterionFactory>>
                  criterion_vec) const
Gregor Olenik's avatar
Gregor Olenik committed
82
83
84
    {
        using bj = gko::preconditioner::Jacobi<>;
        return gko::solver::Bicgstab<scalar>::build()
85
86
87
            .with_criteria(criterion_vec)
            .with_preconditioner(
                bj::build().with_max_block_size(blockSize_).on(exec))
Gregor Olenik's avatar
Gregor Olenik committed
88
89
90
91
92
            .on(exec);
    };
};


greole's avatar
Ir (#1)    
greole committed
93
class GKOBiCGStab : public GKOlduBaseSolver<GKOBiCGStabFactory> {
Gregor Olenik's avatar
Gregor Olenik committed
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
    // Private Member Functions

public:
    TypeName("GKOBiCGStab");

    //- Disallow default bitwise copy construct
    GKOBiCGStab(const GKOBiCGStab &);

    //- Disallow default bitwise assignment
    void operator=(const GKOBiCGStab &);


    // Constructors

    //- Construct from matrix components and solver controls
    GKOBiCGStab(const word &fieldName, const lduMatrix &matrix,
110
111
112
113
                const FieldField<Field, scalar> &interfaceBouCoeffs,
                const FieldField<Field, scalar> &interfaceIntCoeffs,
                const lduInterfaceFieldPtrsList &interfaces,
                const dictionary &solverControls)
greole's avatar
Ir (#1)    
greole committed
114
        : GKOlduBaseSolver(fieldName, matrix, interfaceBouCoeffs,
115
                           interfaceIntCoeffs, interfaces, solverControls){};
Gregor Olenik's avatar
Gregor Olenik committed
116
117
118
119
120
121
122
123
124
125

    //- Destructor
    virtual ~GKOBiCGStab(){};


    // Member Functions

    //- Solve the matrix with this solver

    virtual solverPerformance solve(scalarField &psi, const scalarField &source,
126
127
                                    const direction cmpt = 0) const
    {
Gregor Olenik's avatar
Gregor Olenik committed
128
129
130
131
132
133
134
135
136
137
138
139
140
141
        return solve_impl(this->typeName, psi, source, cmpt);
    }
};


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

}  // End namespace Foam

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

#endif

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