-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update tutorials (mostly CoupCons3D one)
- Loading branch information
Showing
13 changed files
with
577 additions
and
398 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
add_executable(coupcons3d coupcons3d.cpp) | ||
target_link_libraries(coupcons3d amgcl) | ||
|
||
#if (VexCL_FOUND) | ||
# vexcl_add_executables(coupcons3d_vexcl coupcons3d_vexcl.cpp) | ||
# target_link_libraries(coupcons3d_vexcl INTERFACE amgcl) | ||
#endif() | ||
add_executable(coupcons3d_spc coupcons3d_spc.cpp) | ||
target_link_libraries(coupcons3d_spc amgcl) | ||
|
||
if (VexCL_FOUND) | ||
vexcl_add_executables(coupcons3d_vexcl coupcons3d_vexcl.cpp) | ||
target_link_libraries(coupcons3d_vexcl INTERFACE amgcl) | ||
endif() |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,107 @@ | ||
#include <iostream> | ||
#include <string> | ||
|
||
#include <amgcl/backend/builtin.hpp> | ||
#include <amgcl/adapter/crs_tuple.hpp> | ||
#include <amgcl/value_type/static_matrix.hpp> | ||
#include <amgcl/adapter/block_matrix.hpp> | ||
#include <amgcl/preconditioner/schur_pressure_correction.hpp> | ||
#include <amgcl/make_solver.hpp> | ||
#include <amgcl/make_block_solver.hpp> | ||
#include <amgcl/amg.hpp> | ||
#include <amgcl/solver/bicgstab.hpp> | ||
#include <amgcl/solver/preonly.hpp> | ||
#include <amgcl/coarsening/aggregation.hpp> | ||
#include <amgcl/relaxation/ilu0.hpp> | ||
#include <amgcl/relaxation/spai0.hpp> | ||
#include <amgcl/relaxation/as_preconditioner.hpp> | ||
|
||
#include <amgcl/io/mm.hpp> | ||
#include <amgcl/profiler.hpp> | ||
|
||
//--------------------------------------------------------------------------- | ||
int main(int argc, char *argv[]) { | ||
// The matrix and the RHS file names should be in the command line options: | ||
if (argc < 3) { | ||
std::cerr << "Usage: " << argv[0] << " <matrix.mtx> <nu>" << std::endl; | ||
return 1; | ||
} | ||
|
||
// The profiler: | ||
amgcl::profiler<> prof("CoupCons3D"); | ||
|
||
// Read the system matrix: | ||
size_t rows, cols; | ||
std::vector<ptrdiff_t> ptr, col; | ||
std::vector<double> val; | ||
|
||
prof.tic("read"); | ||
std::tie(rows, cols) = amgcl::io::mm_reader(argv[1])(ptr, col, val); | ||
std::cout << "Matrix " << argv[1] << ": " << rows << "x" << cols << std::endl; | ||
prof.toc("read"); | ||
|
||
// The RHS is filled with ones: | ||
std::vector<double> f(rows, 1.0); | ||
|
||
// The number of unknowns in the U subsystem | ||
size_t nu = std::stoi(argv[2]); | ||
|
||
// We use the tuple of CRS arrays to represent the system matrix. | ||
// Note that std::tie creates a tuple of references, so no data is actually | ||
// copied here: | ||
auto A = std::tie(rows, ptr, col, val); | ||
|
||
// Compose the solver type | ||
typedef amgcl::backend::builtin<double> SBackend; // the outer iterative solver backend | ||
typedef amgcl::backend::builtin<float> PBackend; // the PSolver backend | ||
typedef amgcl::backend::builtin< | ||
amgcl::static_matrix<float,4,4>> UBackend; // the USolver backend | ||
|
||
typedef amgcl::make_solver< | ||
amgcl::preconditioner::schur_pressure_correction< | ||
amgcl::make_block_solver< | ||
amgcl::amg< | ||
UBackend, | ||
amgcl::coarsening::aggregation, | ||
amgcl::relaxation::ilu0 | ||
>, | ||
amgcl::solver::preonly<UBackend> | ||
>, | ||
amgcl::make_solver< | ||
amgcl::relaxation::as_preconditioner< | ||
PBackend, | ||
amgcl::relaxation::spai0 | ||
>, | ||
amgcl::solver::preonly<PBackend> | ||
> | ||
>, | ||
amgcl::solver::bicgstab<SBackend> | ||
> Solver; | ||
|
||
// Solver parameters | ||
Solver::params prm; | ||
prm.precond.pmask.resize(rows); | ||
for(size_t i = 0; i < rows; ++i) prm.precond.pmask[i] = (i >= nu); | ||
|
||
// Initialize the solver with the system matrix. | ||
prof.tic("setup"); | ||
Solver solve(A, prm); | ||
prof.toc("setup"); | ||
|
||
// Show the mini-report on the constructed solver: | ||
std::cout << solve << std::endl; | ||
|
||
// Solve the system with the zero initial approximation: | ||
int iters; | ||
double error; | ||
std::vector<double> x(rows, 0.0); | ||
prof.tic("solve"); | ||
std::tie(iters, error) = solve(A, f, x); | ||
prof.toc("solve"); | ||
|
||
// Output the number of iterations, the relative error, | ||
// and the profiling data: | ||
std::cout << "Iters: " << iters << std::endl | ||
<< "Error: " << error << std::endl | ||
<< prof << std::endl; | ||
} |
Oops, something went wrong.