Loading...
Searching...
No Matches
system_solvers_split.hpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2024 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25#ifndef __BITPIT_SYSTEM_SOLVERS_SPLIT_HPP__
26#define __BITPIT_SYSTEM_SOLVERS_SPLIT_HPP__
27
28#include <string>
29#include <vector>
30
31#include "system_matrix.hpp"
32#include "system_solvers_large.hpp"
33
34namespace bitpit {
35
36enum SystemSplitStrategy {
37 SYSTEM_SPLIT_STRATEGY_DIAGONAL,
38 SYSTEM_SPLIT_STRATEGY_FULL,
39 SYSTEM_SPLIT_STRATEGY_LOWER,
40};
41
43
44public:
45 SystemSplitStrategy getSplitStrategy() const;
46 int getSplitCount() const;
47 const std::vector<int> & getSplitSizes() const;
48
49protected:
50 SplitSystemMatrixAssembler(SystemSplitStrategy splitStrategy, const std::vector<int> &splitSizes);
51
52private:
53 SystemSplitStrategy m_splitStrategy;
54 std::vector<int> m_splitSizes;
55
56};
57
59
60public:
61 SplitSystemSparseMatrixAssembler(const SparseMatrix *matrix, SystemSplitStrategy splitStrategy,
62 const std::vector<int> &splitSizes);
63
64};
65
67
68public:
70
71 typedef SystemSplitStrategy splitStrategy;
72
73 friend class SystemSolver;
74
75 SplitSystemSolver(bool debug = false);
76 SplitSystemSolver(bool transpose, bool debug);
77 SplitSystemSolver(bool flatten, bool transpose, bool debug);
78 SplitSystemSolver(const std::string &prefix, bool debug = false);
79 SplitSystemSolver(const std::string &prefix, bool transpose, bool debug);
80 SplitSystemSolver(const std::string &prefix, bool flatten, bool transpose, bool debug);
81
83
84 void assembly(const SparseMatrix &matrix, SystemSplitStrategy splitStrategy, const std::vector<int> &splitSizes);
85 void assembly(const SparseMatrix &matrix, SystemSplitStrategy splitStrategy, const std::vector<int> &splitSizes,
86 const SystemMatrixOrdering &reordering);
87 void assembly(const Assembler &assembler);
88 void assembly(const Assembler &assembler, const SystemMatrixOrdering &reordering);
89
90 void update(const SparseMatrix &elements);
91 void update(long nRows, const long *rows, const SparseMatrix &elements);
92 void update(const Assembler &assembler);
93 void update(long nRows, const long *rows, const Assembler &assembler);
94
95 int getBlockSize() const override;
96
97 SystemSplitStrategy getSplitStrategy() const;
98 int getSplitCount() const;
99 std::vector<int> getSplitSizes() const;
100 std::vector<int> getSplitOffsets() const;
101
102 KSPOptions & getSplitKSPOptions(int split);
103 const KSPOptions & getSplitKSPOptions(int split) const;
104
105 const KSPStatus & getSplitKSPStatus(int split) const;
106
107 void exportMatrix(const std::string &filePath, FileFormat exportFormat = FILE_BINARY) const override;
108
109protected:
110 SystemSplitStrategy m_splitStrategy;
111
112 std::vector<Mat> m_splitAs;
113
114 std::vector<KSPOptions> m_splitKSPOptions;
115 std::vector<KSPStatus> m_splitKSPStatuses;
116
118 using SystemSolver::update;
119
120 void matrixAssembly(const Assembler &assembler);
121 void matrixUpdate(long nRows, const long *rows, const Assembler &assembler);
122 void matrixFill(const std::string &filePath) override;
123 void matrixDump(std::ostream &systemStream, const std::string &directory, const std::string &prefix) const override;
124#if BITPIT_ENABLE_MPI==1
125 void matrixRestore(std::istream &systemStream, const std::string &directory, const std::string &prefix, bool redistribute) override;
126#else
127 void matrixRestore(std::istream &systemStream, const std::string &directory, const std::string &prefix) override;
128#endif
129 void matrixDestroy() override;
130
131 void vectorsCreate() override;
132 void vectorsReorder(bool invert) override;
133 void vectorsRestore(std::istream &systemStream, const std::string &directory, const std::string &prefix) override;
135 void vectorsDestroy() override;
136
137 void setupPreconditioner() override;
139 virtual void setupSplitPreconditioners();
140
141 void setupKrylov() override;
143 virtual void setupSplitKrylovs();
144
145 void preKrylovSetupActions() override;
146
147 void postKSPSolveActions() override;
148
149 void initializeKSPOptions() override;
150 virtual void initializeSplitKSPOptions();
152 void destroyKSPOptions() override;
153 virtual void destroySplitKSPOptions();
154
155 void initializeKSPStatus() override;
156 virtual void initializeSplitKSPStatuses();
157 void fillKSPStatus() override;
159 virtual void fillSplitKSPStatuses();
160 void resetKSPStatus() override;
162 virtual void resetSplitKSPStatuses();
163 void destroyKSPStatus() override;
164 virtual void destroySplitKSPStatuses();
165
166 void dumpInfo(std::ostream &systemStream) const override;
167 void restoreInfo(std::istream &systemStream) override;
168
170
171#if BITPIT_ENABLE_MPI == 1
172 void generateSplitPermutation(long nItems, long itemGlobalOffset, IS *splitReordering) const;
173#else
174 void generateSplitPermutation(long nItems, IS *splitReordering) const;
175#endif
176 void generateSplitIndexes(int split, long nItems, std::vector<std::size_t> *indexes) const;
177
178 std::string generateSplitPath(const std::string &path, int i) const;
179 std::string generateSplitPath(const std::string &path, int i, int j) const;
180 std::string generateSplitPath(const std::string &path, const std::string &index) const;
181
182private:
183 IS m_rhsSplitPermutation;
184 IS m_solutionSplitPermutation;
185
186 int getBlockSplitLinearIndex(int i, int j) const;
187 int getBlockSplitLinearIndex(int i, int j, int nSplits) const;
188
189};
190
191}
192
193#endif
The SplitSystemMatrixAssembler class is the base class for defining assemblers for split system solve...
SystemSplitStrategy getSplitStrategy() const
SplitSystemMatrixAssembler(SystemSplitStrategy splitStrategy, const std::vector< int > &splitSizes)
const std::vector< int > & getSplitSizes() const
The SplitSystemSolver class allows to solve a split linear system.
std::vector< int > getSplitSizes() const
SystemSplitStrategy getSplitStrategy() const
void matrixUpdate(long nRows, const long *rows, const Assembler &assembler)
std::vector< int > getSplitOffsets() const
void generateSplitIndexes(int split, long nItems, std::vector< std::size_t > *indexes) const
void vectorsReorder(bool invert) override
const KSPStatus & getSplitKSPStatus(int split) const
void matrixAssembly(const Assembler &assembler)
void matrixRestore(std::istream &systemStream, const std::string &directory, const std::string &prefix, bool redistribute) override
KSPOptions & getSplitKSPOptions(int split)
void vectorsRestore(std::istream &systemStream, const std::string &directory, const std::string &prefix) override
void assembly(const SparseMatrix &matrix, SystemSplitStrategy splitStrategy, const std::vector< int > &splitSizes)
void restoreInfo(std::istream &systemStream) override
void matrixFill(const std::string &filePath) override
std::string generateSplitPath(const std::string &path, int i) const
void generateSplitPermutation(long nItems, long itemGlobalOffset, IS *splitReordering) const
void update(const SparseMatrix &elements)
void matrixDump(std::ostream &systemStream, const std::string &directory, const std::string &prefix) const override
void exportMatrix(const std::string &filePath, FileFormat exportFormat=FILE_BINARY) const override
void dumpInfo(std::ostream &systemStream) const override
The SplitSystemSparseMatrixAssembler class allows to assembly a split system solver from a sparse mat...
SplitSystemSparseMatrixAssembler(const SparseMatrix *matrix, SystemSplitStrategy splitStrategy, const std::vector< int > &splitSizes)
The SystemMatrixAssembler class provides an interface for defining system matrix assemblers.
The SystemMatrixOrdering class provides an interface for defining classes that allows to reorder the ...
The SystemSolver class provides methods for building and solving large linear systems.
virtual void exportMatrix(const std::string &filePath, FileFormat exportFormat=FILE_BINARY) const
virtual void resetKSPOptions(KSPOptions *options) const
void assembly(const SparseMatrix &matrix)
The SystemSparseMatrixAssembler class defines an assembler for building the system matrix form a spar...
--- layout: doxygen_footer ---