35 lines
2.0 KiB
C++
35 lines
2.0 KiB
C++
|
|
#pragma once
|
||
|
|
|
||
|
|
#include <functional>
|
||
|
|
#include <span>
|
||
|
|
#include <vector>
|
||
|
|
#include "serif/backend/mfem/operators/linearized_block.hpp"
|
||
|
|
|
||
|
|
namespace serif::operators::backend::mfem {
|
||
|
|
using MatrixAction = std::function<void(const ::mfem::Vector&, ::mfem::Vector&)>;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Apply the forward action to several directions at once (zeroed outputs, as MatrixAction receives).
|
||
|
|
* @note Each output must equal what MatrixAction produces for its input; batching only shares traversals.
|
||
|
|
*/
|
||
|
|
using MatrixArrayAction = std::function<void(std::span<const ::mfem::Vector* const>, std::span<::mfem::Vector* const>)>;
|
||
|
|
|
||
|
|
/** @brief Wrap owned callbacks with checked dimensions, finite results, and overlap-safe application. */
|
||
|
|
[[nodiscard]] LinearizedBlock linearized_action(int rows, int columns, MatrixAction action, MatrixAction transpose);
|
||
|
|
|
||
|
|
/** @brief As above, with a batched forward action used by the operator's ArrayMult. */
|
||
|
|
[[nodiscard]] LinearizedBlock linearized_action(int rows, int columns, MatrixAction action, MatrixAction transpose, MatrixArrayAction batch);
|
||
|
|
|
||
|
|
/** @brief Apply an operator to several directions; ArrayMult for SERiF actions, otherwise one Mult per direction. */
|
||
|
|
void apply_many(const ::mfem::Operator& action, std::span<const ::mfem::Vector* const> inputs, std::span<::mfem::Vector* const> outputs);
|
||
|
|
|
||
|
|
/** @brief Transpose a linearized block without discarding efficient assembly and diagonal operations. */
|
||
|
|
[[nodiscard]] LinearizedBlock transpose_block(LinearizedBlock block);
|
||
|
|
|
||
|
|
/** @brief Compose linearized blocks in their written mathematical order. */
|
||
|
|
[[nodiscard]] LinearizedBlock compose_blocks(LinearizedBlock left, LinearizedBlock right);
|
||
|
|
|
||
|
|
/** @brief Sum compatible linearized blocks while retaining their native diagonal and sparse assembly operations. */
|
||
|
|
[[nodiscard]] LinearizedBlock sum_blocks(int rows, int columns, std::vector<LinearizedBlock> blocks);
|
||
|
|
} // namespace serif::operators::backend::mfem
|