Arcane  4.2.3.0
Developer documentation
Loading...
Searching...
No Matches
coupcons3d_spc.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7
8/*
9The MIT License
10
11Copyright (c) 2012-2022 Denis Demidov <dennis.demidov@gmail.com>
12
13Permission is hereby granted, free of charge, to any person obtaining a copy
14of this software and associated documentation files (the "Software"), to deal
15in the Software without restriction, including without limitation the rights
16to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17copies of the Software, and to permit persons to whom the Software is
18furnished to do so, subject to the following conditions:
19
20The above copyright notice and this permission notice shall be included in
21all copies or substantial portions of the Software.
22
23THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29THE SOFTWARE.
30*/
31
32#include <iostream>
33#include <string>
34
35#include "arccore/alina/BuiltinBackend.h"
36#include "arccore/alina/Adapters.h"
37#include "arccore/alina/StaticMatrix.h"
38#include "arccore/alina/SchurPressureCorrectionPreconditioner.h"
39#include "arccore/alina/PreconditionedSolver.h"
40#include "arccore/alina/make_block_solver.h"
41#include "arccore/alina/AMG.h"
42#include "arccore/alina/BiCGStabSolver.h"
43#include "arccore/alina/PreconditionerOnlySolver.h"
44#include "arccore/alina/Coarsening.h"
45#include "arccore/alina/Relaxation.h"
46
47#include "arccore/alina/IO.h"
48#include "arccore/alina/Profiler.h"
49
50using namespace Arcane;
51
52//---------------------------------------------------------------------------
53int main(int argc, char* argv[])
54{
55 // The command line should contain the matrix file name:
56 if (argc < 3) {
57 std::cerr << "Usage: " << argv[0] << " <matrix.mtx> <nu>" << std::endl;
58 return 1;
59 }
60
61 Alina::AlinaContext context;
62
63 // The profiler:
64 auto& prof = Alina::Profiler::globalProfiler();
65
66 // Read the system matrix:
67 ptrdiff_t rows, cols;
68 std::vector<ptrdiff_t> ptr, col;
69 std::vector<double> val;
70
71 prof.tic("read");
72 std::tie(rows, cols) = Alina::IO::mm_reader(argv[1])(ptr, col, val);
73 std::cout << "Matrix " << argv[1] << ": " << rows << "x" << cols << std::endl;
74 prof.toc("read");
75
76 // The RHS is filled with ones:
77 std::vector<double> f(rows, 1.0);
78
79 // The number of unknowns in the U subsystem
80 ptrdiff_t nu = std::stoi(argv[2]);
81
82 // We use the tuple of CRS arrays to represent the system matrix.
83 // Note that std::tie creates a tuple of references, so no data is actually
84 // copied here:
85 auto A = std::tie(rows, ptr, col, val);
86
87 // Compose the solver type
88 typedef Alina::BuiltinBackend<double> SBackend; // the outer iterative solver backend
89 typedef Alina::BuiltinBackend<float> PBackend; // the PSolver backend
90 typedef Alina::BuiltinBackend<Alina::StaticMatrix<float, 4, 4>> UBackend; // the USolver backend
91
94 Alina::AMG<UBackend,
103
104 // Solver parameters
105 Solver::params prm;
106 prm.precond.pmask.resize(rows);
107 for (ptrdiff_t i = 0; i < rows; ++i)
108 prm.precond.pmask[i] = (i >= nu);
109
110 // Initialize the solver with the system matrix.
111 prof.tic("setup");
112 Solver solve(context, A, prm);
113 prof.toc("setup");
114
115 // Show the mini-report on the constructed solver:
116 std::cout << solve << std::endl;
117
118 // Solve the system with the zero initial approximation:
119 std::vector<double> x(rows, 0.0);
120 prof.tic("solve");
121 Alina::SolverResult r = solve(A, f, x);
122 prof.toc("solve");
123
124 // Output the number of iterations, the relative error,
125 // and the profiling data:
126 std::cout << "Iters: " << r.nbIteration() << std::endl
127 << "Error: " << r.residual() << std::endl
128 << prof << std::endl;
129}
Algebraic multigrid method.
Definition AMG.h:71
BiConjugate Gradient Stabilized (BiCGSTAB) method.
Matrix market reader.
Definition IO.h:54
Convenience class that bundles together a preconditioner and an iterative solver.
Solver which only apply preconditioner once.
Allows to use an AMG smoother as standalone preconditioner.
Definition Relaxation.h:144
Result of a solution.
Definition AlinaUtils.h:56
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Non-smoothed aggregation.
Definition Coarsening.h:640
Sparse approximate interface smoother.