Arcane  4.2.1.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
SampleProblemCommon.h
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 * Ce fichier est basé sur le travail sur la bibliothèque AMGCL (version mars 2026)
11 * qui peut être trouvé à 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#ifndef TESTS_SAMPLE_PROBLEM_HPP
20#define TESTS_SAMPLE_PROBLEM_HPP
21
22#include "arccore/alina/ValueTypeInterface.h"
23
24#include <vector>
25
26// Génère la matrice pour le problème de Poisson dans un cube unitaire.
27template <typename ValueType, typename ColType, typename PtrType, typename RhsType>
28int sample_problem(ptrdiff_t n,
29 std::vector<ValueType>& val,
30 std::vector<ColType>& col,
31 std::vector<PtrType>& ptr,
32 std::vector<RhsType>& rhs,
33 double anisotropy = 1.0)
34{
35 ptrdiff_t n3 = n * n * n;
36
37 ptr.clear();
38 col.clear();
39 val.clear();
40 rhs.clear();
41
42 ptr.reserve(n3 + 1);
43 col.reserve(n3 * 7);
44 val.reserve(n3 * 7);
45 rhs.reserve(n3);
46
47 const auto one = Arcane::Alina::math::identity<ValueType>();
48
49 double hx = 1;
50 double hy = hx * anisotropy;
51 double hz = hy * anisotropy;
52
53 ptr.push_back(0);
54 for (ptrdiff_t k = 0, idx = 0; k < n; ++k) {
55 for (ptrdiff_t j = 0; j < n; ++j) {
56 for (ptrdiff_t i = 0; i < n; ++i, ++idx) {
57 if (k > 0) {
58 col.push_back(idx - n * n);
59 val.push_back(-1.0 / (hz * hz) * one);
60 }
61
62 if (j > 0) {
63 col.push_back(idx - n);
64 val.push_back(-1.0 / (hy * hy) * one);
65 }
66
67 if (i > 0) {
68 col.push_back(idx - 1);
69 val.push_back(-1.0 / (hx * hx) * one);
70 }
71
72 col.push_back(idx);
73 val.push_back((2 / (hx * hx) + 2 / (hy * hy) + 2 / (hz * hz)) * one);
74
75 if (i + 1 < n) {
76 col.push_back(idx + 1);
77 val.push_back(-1.0 / (hx * hx) * one);
78 }
79
80 if (j + 1 < n) {
81 col.push_back(idx + n);
82 val.push_back(-1.0 / (hy * hy) * one);
83 }
84
85 if (k + 1 < n) {
86 col.push_back(idx + n * n);
87 val.push_back(-1.0 / (hz * hz) * one);
88 }
89
90 rhs.push_back(Arcane::Alina::math::constant<RhsType>(1.0));
91 ptr.push_back(static_cast<PtrType>(col.size()));
92 }
93 }
94 }
95
96 return n3;
97}
98
99#endif