Arcane  v4.1.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
BackendBlockCSR.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/*---------------------------------------------------------------------------*/
9/*
10 * This file is based on the work on AMGCL library (version march 2026)
11 * which can be found at https://github.com/ddemidov/amgcl.
12 *
13 * Copyright (c) 2012-2022 Denis Demidov <dennis.demidov@gmail.com>
14 * SPDX-License-Identifier: MIT
15 */
16/*---------------------------------------------------------------------------*/
17/*---------------------------------------------------------------------------*/
18
19#include <iostream>
20#include <fstream>
21#include <iterator>
22#include <algorithm>
23
24#include "arccore/alina/AMG.h"
25
26#include "arccore/alina/Adapters.h"
27#include "arccore/alina/BlockCSRBackend.h"
28#include "arccore/alina/Coarsening.h"
29#include "arccore/alina/Relaxation.h"
30#include "arccore/alina/BiCGStabSolver.h"
31#include "arccore/alina/Profiler.h"
32
33using namespace Arcane;
34
35int main()
36{
37 auto& prof = Alina::Profiler::globalProfiler();
38
41
42 std::vector<ptrdiff_t> ptr;
43 std::vector<ptrdiff_t> col;
44 std::vector<double> val;
45 std::vector<double> rhs;
46
47 prof.tic("read");
48 {
49 std::istream_iterator<int> iend;
50 std::istream_iterator<double> dend;
51
52 std::ifstream fptr("rows.txt");
53 std::ifstream fcol("cols.txt");
54 std::ifstream fval("values.txt");
55 std::ifstream frhs("rhs.txt");
56
57 Alina::precondition(fptr, "rows.txt not found");
58 Alina::precondition(fcol, "cols.txt not found");
59 Alina::precondition(fval, "values.txt not found");
60 Alina::precondition(frhs, "rhs.txt not found");
61
62 std::istream_iterator<int> iptr(fptr);
63 std::istream_iterator<int> icol(fcol);
64 std::istream_iterator<double> ival(fval);
65 std::istream_iterator<double> irhs(frhs);
66
67 ptr.assign(iptr, iend);
68 col.assign(icol, iend);
69 val.assign(ival, dend);
70 rhs.assign(irhs, dend);
71 }
72
73 int n = ptr.size() - 1;
74 prof.toc("read");
75
76 prof.tic("build");
77 AMG::params prm;
78 prm.coarsening.aggr.eps_strong = 0;
79 prm.coarsening.aggr.block_size = 4;
80 prm.npre = prm.npost = 2;
81
82 Backend::params bprm;
83 bprm.block_size = 4;
84
85 AMG amg(std::tie(n, ptr, col, val), prm, bprm);
86 prof.toc("build");
87
88 std::cout << amg << std::endl;
89
90 std::vector<double> x(n, 0);
91
93
94 prof.tic("solve");
95 Alina::SolverResult r = solve(amg, rhs, x);
96 prof.toc("solve");
97
98 std::cout << "Iterations: " << r.nbIteration() << std::endl
99 << "Error: " << r.residual() << std::endl;
100
101 std::cout << prof << std::endl;
102}
Algebraic multigrid method.
Definition AMG.h:71
BiConjugate Gradient Stabilized (BiCGSTAB) method.
Result of a solving.
Definition AlinaUtils.h:52
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Alina::detail::empty_params params
block_crs backend definition.