Arcane  v4.1.10.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(
30ptrdiff_t n,
31std::vector<ValueType>& val,
32std::vector<ColType>& col,
33std::vector<PtrType>& ptr,
34std::vector<RhsType>& rhs,
35double anisotropy = 1.0)
36{
37 ptrdiff_t n3 = n * n * n;
38
39 ptr.clear();
40 col.clear();
41 val.clear();
42 rhs.clear();
43
44 ptr.reserve(n3 + 1);
45 col.reserve(n3 * 7);
46 val.reserve(n3 * 7);
47 rhs.reserve(n3);
48
49 const auto one = Arcane::Alina::math::identity<ValueType>();
50
51 double hx = 1;
52 double hy = hx * anisotropy;
53 double hz = hy * anisotropy;
54
55 ptr.push_back(0);
56 for (ptrdiff_t k = 0, idx = 0; k < n; ++k) {
57 for (ptrdiff_t j = 0; j < n; ++j) {
58 for (ptrdiff_t i = 0; i < n; ++i, ++idx) {
59 if (k > 0) {
60 col.push_back(idx - n * n);
61 val.push_back(-1.0 / (hz * hz) * one);
62 }
63
64 if (j > 0) {
65 col.push_back(idx - n);
66 val.push_back(-1.0 / (hy * hy) * one);
67 }
68
69 if (i > 0) {
70 col.push_back(idx - 1);
71 val.push_back(-1.0 / (hx * hx) * one);
72 }
73
74 col.push_back(idx);
75 val.push_back((2 / (hx * hx) + 2 / (hy * hy) + 2 / (hz * hz)) * one);
76
77 if (i + 1 < n) {
78 col.push_back(idx + 1);
79 val.push_back(-1.0 / (hx * hx) * one);
80 }
81
82 if (j + 1 < n) {
83 col.push_back(idx + n);
84 val.push_back(-1.0 / (hy * hy) * one);
85 }
86
87 if (k + 1 < n) {
88 col.push_back(idx + n * n);
89 val.push_back(-1.0 / (hz * hz) * one);
90 }
91
92 rhs.push_back(Arcane::Alina::math::constant<RhsType>(1.0));
93 ptr.push_back(static_cast<PtrType>(col.size()));
94 }
95 }
96 }
97
98 return n3;
99}
100
101#endif