46 template <
typename ValueType,
typename ColType,
typename PtrType,
typename RhsType>
48 createSequentialMatrix(
Int32 n,
49 std::vector<ValueType>& val,
50 std::vector<ColType>& col,
51 std::vector<PtrType>& ptr,
52 std::vector<RhsType>& rhs,
53 double anisotropy = 1.0)
56 PtrType n3 = n * n * n;
68 const auto one = Arcane::Alina::math::identity<ValueType>();
71 double hy = hx * anisotropy;
72 double hz = hy * anisotropy;
75 for (ColType k = 0, idx = 0; k < n; ++k) {
76 for (
int j = 0; j < n; ++j) {
77 for (
int i = 0; i < n; ++i, ++idx) {
79 col.push_back(idx - n * n);
80 val.push_back(-1.0 / (hz * hz) * one);
84 col.push_back(idx - n);
85 val.push_back(-1.0 / (hy * hy) * one);
89 col.push_back(idx - 1);
90 val.push_back(-1.0 / (hx * hx) * one);
94 val.push_back((2 / (hx * hx) + 2 / (hy * hy) + 2 / (hz * hz)) * one);
97 col.push_back(idx + 1);
98 val.push_back(-1.0 / (hx * hx) * one);
102 col.push_back(idx + n);
103 val.push_back(-1.0 / (hy * hy) * one);
107 col.push_back(idx + n * n);
108 val.push_back(-1.0 / (hz * hz) * one);
111 rhs.push_back(Arcane::Alina::math::constant<RhsType>(1.0));
112 ptr.push_back(
static_cast<PtrType
>(col.size()));
122 template <
typename ValueType,
typename ColType,
typename PtrType,
typename RhsType>
124 createDistributedMatrix(
int comm_rank,
int comm_size,
126 std::vector<PtrType>& ptr,
127 std::vector<ColType>& col,
128 std::vector<ValueType>& val,
129 std::vector<RhsType>& rhs)
134 PtrType n3 = nx * nx * nx;
136 PtrType chunk = (n3 + comm_size - 1) / comm_size;
137 if (chunk % block_size != 0) {
138 chunk += block_size - chunk % block_size;
140 PtrType row_beg = std::min(n3, chunk * comm_rank);
141 PtrType row_end = std::min(n3, row_beg + chunk);
142 chunk = row_end - row_beg;
145 ptr.reserve(chunk + 1);
147 col.reserve(chunk * 7);
149 val.reserve(chunk * 7);
152 std::fill(rhs.begin(), rhs.end(), 1.0);
154 const double h2i = (n - 1) * (n - 1);
157 for (PtrType idx = row_beg; idx < row_end; ++idx) {
158 PtrType k = idx / (n * n);
159 PtrType j = (idx / n) % n;
163 col.push_back(idx - n * n);
168 col.push_back(idx - n);
173 col.push_back(idx - 1);
178 val.push_back(6 * h2i);
181 col.push_back(idx + 1);
186 col.push_back(idx + n);
191 col.push_back(idx + n * n);
195 ptr.push_back(col.size());