OISEAU
A modern DGTD framework
Loading...
Searching...
No Matches
state.hpp
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
14namespace oiseau::dg::solver {
15
21struct DGState {
22 std::vector<xt::xarray<double>> groups;
23};
24
27inline void scale_add_in_place(DGState& target, double target_scale, const DGState& source,
28 double source_scale) {
29 for (std::size_t group = 0; group < target.groups.size(); ++group) {
30 auto* values = target.groups[group].data();
31 const auto* source_values = source.groups[group].data();
32 for (std::size_t index = 0; index < target.groups[group].size(); ++index) {
33 const auto old_value = values[index];
34 const auto added_value = source_values[index];
35 values[index] = target_scale * old_value + source_scale * added_value;
36 }
37 }
38}
39
40inline DGState add_scaled(const DGState& base, const DGState& increment, double scale) {
41 auto result = base;
42 for (std::size_t group = 0; group < result.groups.size(); ++group) {
43 auto* values = result.groups[group].data();
44 const auto* differences = increment.groups[group].data();
45 for (std::size_t index = 0; index < result.groups[group].size(); ++index) {
46 values[index] += scale * differences[index];
47 }
48 }
49 return result;
50}
51
52} // namespace oiseau::dg::solver
Definition state.hpp:21