Files
MeanField_SERiF/src/include/serif/backend/mfem/operators/actions.hpp
Emily Boudreaux 811bbd9694 feat(backend): Added backend FEM code (specifically MFEM backend)
Much of the code to do actual finite element computations lives in this backend. The idea here is that the physics is all seperate and more descriptive than the backend. Further, we could, in principal swap out to another finite element backend (e.g. deal.II) without messing up stuff outside of this backend. Note LLM's made signifigant contributions to this module

LLMs (ChatGPT6 astra max and Claude Opus 5.5 medium) made signifigant contributions to this module. All LLM written code has been read over and verified.
2026-11-09 13:48:09 -05:00

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