-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
138 changed files
with
74,964 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ Toolbox/metis-src | |
Toolbox/mumps-src | ||
Toolbox/superlu-src | ||
Toolbox/superlumt-src | ||
Toolbox/lis-src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/******************************************************************************* | ||
* Copyright (C) 2017-2023 Theodore Chang | ||
* | ||
* This program 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. | ||
* | ||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
/** | ||
* @class SparseMatLis | ||
* @brief A SparseMatLis class that holds matrices. | ||
* | ||
* @author tlc | ||
* @date 15/06/2023 | ||
* @version 0.1.0 | ||
* @file SparseMatLis.hpp | ||
* @addtogroup MetaMat | ||
* @{ | ||
*/ | ||
|
||
#ifndef SPARSEMATLIS_HPP | ||
#define SPARSEMATLIS_HPP | ||
|
||
#include <lis/lislib.h> | ||
#include "SparseMat.hpp" | ||
#include "csr_form.hpp" | ||
|
||
template<sp_d T> class SparseMatLis final : public SparseMat<T> { | ||
LIS_SOLVER solver = nullptr; | ||
|
||
protected: | ||
using SparseMat<T>::direct_solve; | ||
using SparseMat<T>::setting; | ||
|
||
int direct_solve(Mat<T>&, const Mat<T>&) override; | ||
|
||
public: | ||
SparseMatLis(const uword in_row, const uword in_col, const uword in_elem = 0) | ||
: SparseMat<T>(in_row, in_col, in_elem) { | ||
lis_solver_create(&solver); | ||
lis_solver_set_option("-i fgmres -p ilu", solver); | ||
} | ||
|
||
SparseMatLis(const SparseMatLis& other) | ||
: SparseMat<T>(other) { | ||
lis_solver_create(&solver); | ||
lis_solver_set_option("-i fgmres -p ilu", solver); | ||
} | ||
|
||
SparseMatLis(SparseMatLis&&) noexcept = delete; | ||
SparseMatLis& operator=(const SparseMatLis&) = delete; | ||
SparseMatLis& operator=(SparseMatLis&&) noexcept = delete; | ||
|
||
~SparseMatLis() override { lis_solver_destroy(solver); } | ||
|
||
unique_ptr<MetaMat<T>> make_copy() override { return std::make_unique<SparseMatLis>(*this); } | ||
}; | ||
|
||
template<sp_d T> int SparseMatLis<T>::direct_solve(Mat<T>& X, const Mat<T>& B) { | ||
X.set_size(B.n_rows, B.n_cols); | ||
|
||
csr_form<double, LIS_INT> csr_mat(this->triplet_mat, SparseBase::ZERO, true); | ||
|
||
const sp_i auto n = csr_mat.n_rows; | ||
const sp_i auto nnz = csr_mat.n_elem; | ||
|
||
LIS_MATRIX A; | ||
LIS_VECTOR b, x; | ||
|
||
lis_matrix_create(0, &A); | ||
lis_matrix_set_size(A, n, 0); | ||
lis_matrix_set_csr(nnz, csr_mat.row_mem(), csr_mat.col_mem(), csr_mat.val_mem(), A); | ||
lis_matrix_assemble(A); | ||
|
||
lis_vector_create(0, &b); | ||
lis_vector_create(0, &x); | ||
lis_vector_set_size(b, n, 0); | ||
lis_vector_set_size(x, n, 0); | ||
|
||
lis_solver_set_option(setting.lis_options.c_str(), solver); | ||
|
||
for(uword I = 0; I < B.n_cols; ++I) { | ||
// ReSharper disable CppCStyleCast | ||
lis_vector_set(b, (double*)B.colptr(I)); | ||
lis_vector_set(x, (double*)X.colptr(I)); | ||
// ReSharper restore CppCStyleCast | ||
|
||
lis_solve(A, b, x, solver); | ||
} | ||
|
||
A->ptr = nullptr; | ||
A->index = nullptr; | ||
A->value = nullptr; | ||
b->value = nullptr; | ||
x->value = nullptr; | ||
|
||
lis_matrix_destroy(A); | ||
lis_vector_destroy(b); | ||
lis_vector_destroy(x); | ||
|
||
return SUANPAN_SUCCESS; | ||
} | ||
|
||
#endif | ||
|
||
//! @} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
node 1 0 0 | ||
node 2 .5 0 | ||
node 3 .5 .5 | ||
node 4 0 .5 | ||
|
||
material Elastic2D 1 12 .1 1E-4 | ||
|
||
element CP3 1 1 2 3 1 1 | ||
element CP3 2 1 3 4 1 1 | ||
|
||
fix2 1 1 1 4 | ||
fix2 2 2 1 | ||
|
||
cload 1 0 1 2 2 3 | ||
|
||
step static 1 | ||
set ini_step_size 1E-1 | ||
set fixed_step_size 1 | ||
set sparse_mat 1 | ||
set system_solver lis -print 2 -i 17 -p ilu -ilu_fill 1 | ||
|
||
converger RelIncreDisp 1 1E-8 20 1 | ||
|
||
analyze | ||
|
||
# Node 2: | ||
# Coordinate: | ||
# 0.5000 0 | ||
# Displacement: | ||
# 0.1498 0.6417 | ||
# Resistance: | ||
# -1.1102e-16 1.0000e+00 | ||
# | ||
# Node 3: | ||
# Coordinate: | ||
# 0.5000 0.5000 | ||
# Displacement: | ||
# -0.1665 0.6081 | ||
# Resistance: | ||
# 0 1.0000 | ||
peek node 2 3 | ||
|
||
reset | ||
clear | ||
exit |
Oops, something went wrong.