| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (C) 2026 Tiago V. L. Amorim (@tiagovla) | ||
| 2 | // | ||
| 3 | // This file is part of oiseau (https://github.com/tiagovla/oiseau) | ||
| 4 | // | ||
| 5 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 6 | |||
| 7 | #pragma once | ||
| 8 | |||
| 9 | #include <cstddef> | ||
| 10 | #include <vector> | ||
| 11 | #include <xtensor/containers/xarray.hpp> | ||
| 12 | #include <xtensor/core/xtensor_forward.hpp> | ||
| 13 | |||
| 14 | namespace oiseau::dg::solver { | ||
| 15 | |||
| 16 | /// Nodal values for an equation system, grouped by DGSpace element group. | ||
| 17 | /// | ||
| 18 | /// Each array has shape [group cells, group nodes, number of fields]. The | ||
| 19 | /// component order matches `EquationSystem::fields()`. Arrays use contiguous | ||
| 20 | /// row-major storage so the solver can evaluate cell-local operators directly. | ||
| 21 | struct DGState { | ||
| 22 | std::vector<xt::xarray<double>> groups; | ||
| 23 | }; | ||
| 24 | |||
| 25 | /// Updates target = target_scale * target + source_scale * source. | ||
| 26 | /// Target and source may be the same state. | ||
| 27 | 100 | inline void scale_add_in_place(DGState& target, double target_scale, const DGState& source, | |
| 28 | double source_scale) { | ||
| 29 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 2 taken 100 times.
|
200 | for (std::size_t group = 0; group < target.groups.size(); ++group) { |
| 30 | 100 | auto* values = target.groups[group].data(); | |
| 31 | 100 | const auto* source_values = source.groups[group].data(); | |
| 32 |
2/2✓ Branch 2 taken 100 times.
✓ Branch 3 taken 100 times.
|
200 | for (std::size_t index = 0; index < target.groups[group].size(); ++index) { |
| 33 | 100 | const auto old_value = values[index]; | |
| 34 | 100 | const auto added_value = source_values[index]; | |
| 35 | 100 | values[index] = target_scale * old_value + source_scale * added_value; | |
| 36 | } | ||
| 37 | } | ||
| 38 | 100 | } | |
| 39 | |||
| 40 | 5446 | inline DGState add_scaled(const DGState& base, const DGState& increment, double scale) { | |
| 41 | 5446 | auto result = base; | |
| 42 |
2/2✓ Branch 1 taken 5446 times.
✓ Branch 2 taken 5446 times.
|
10892 | for (std::size_t group = 0; group < result.groups.size(); ++group) { |
| 43 | 5446 | auto* values = result.groups[group].data(); | |
| 44 | 5446 | const auto* differences = increment.groups[group].data(); | |
| 45 |
2/2✓ Branch 2 taken 1204294 times.
✓ Branch 3 taken 5446 times.
|
1209740 | for (std::size_t index = 0; index < result.groups[group].size(); ++index) { |
| 46 | 1204294 | values[index] += scale * differences[index]; | |
| 47 | } | ||
| 48 | } | ||
| 49 | 5446 | return result; | |
| 50 | } | ||
| 51 | |||
| 52 | } // namespace oiseau::dg::solver | ||
| 53 |