Arcane  4.1.11.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 * 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#ifndef TESTS_SAMPLE_PROBLEM_HPP
20#define TESTS_SAMPLE_PROBLEM_HPP
21
22#include <complex>
23#include <type_traits>
24#include <cstddef>
25#include "arccore/alina/ValueTypeInterface.h"
26
27// Generates matrix for poisson problem in a unit cube.
28template <typename ValueType, typename ColType, typename PtrType, typename RhsType>
29int sample_problem(ptrdiff_t n,
30 std::vector<ValueType>& val,
31 std::vector<ColType>& col,
32 std::vector<PtrType>& ptr,
33 std::vector<RhsType>& rhs,
34 double anisotropy = 1.0)
35{
36 ptrdiff_t n3 = n * n * n;
37
38 ptr.clear();
39 col.clear();
40 val.clear();
41 rhs.clear();
42
43 ptr.reserve(n3 + 1);
44 col.reserve(n3 * 7);
45 val.reserve(n3 * 7);
46 rhs.reserve(n3);
47
48 const auto one = Arcane::Alina::math::identity<ValueType>();
49
50 double hx = 1;
51 double hy = hx * anisotropy;
52 double hz = hy * anisotropy;
53
54 ptr.push_back(0);
55 for (ptrdiff_t k = 0, idx = 0; k < n; ++k) {
56 for (ptrdiff_t j = 0; j < n; ++j) {
57 for (ptrdiff_t i = 0; i < n; ++i, ++idx) {
58 if (k > 0) {
59 col.push_back(idx - n * n);
60 val.push_back(-1.0 / (hz * hz) * one);
61 }
62
63 if (j > 0) {
64 col.push_back(idx - n);
65 val.push_back(-1.0 / (hy * hy) * one);
66 }
67
68 if (i > 0) {
69 col.push_back(idx - 1);
70 val.push_back(-1.0 / (hx * hx) * one);
71 }
72
73 col.push_back(idx);
74 val.push_back((2 / (hx * hx) + 2 / (hy * hy) + 2 / (hz * hz)) * one);
75
76 if (i + 1 < n) {
77 col.push_back(idx + 1);
78 val.push_back(-1.0 / (hx * hx) * one);
79 }
80
81 if (j + 1 < n) {
82 col.push_back(idx + n);
83 val.push_back(-1.0 / (hy * hy) * one);
84 }
85
86 if (k + 1 < n) {
87 col.push_back(idx + n * n);
88 val.push_back(-1.0 / (hz * hz) * one);
89 }
90
91 rhs.push_back(Arcane::Alina::math::constant<RhsType>(1.0));
92 ptr.push_back(static_cast<PtrType>(col.size()));
93 }
94 }
95 }
96
97 return n3;
98}
99
100#endif