Files
MeanField_SERiF/src/include/serif/backend/mfem/discretization/resources.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

44 lines
1.8 KiB
C++

#pragma once
#include <memory>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
#include "mfem/fem/gridfunc.hpp"
#include "serif/backend/mfem/mapping/domain_mapper.hpp"
#include "serif/utils/dependencies/dependency_context.hpp"
#include "serif/utils/dependencies/key_list_operations.hpp"
namespace serif::discretization::backend::mfem {
/** @brief Own meshes and finite-element resources in reverse dependency order, for creation and archive restoration. */
struct Resources {
std::vector<std::unique_ptr<::mfem::Mesh>> meshes;
std::vector<std::unique_ptr<::mfem::FiniteElementCollection>> collections;
std::vector<std::unique_ptr<::mfem::FiniteElementSpace>> spaces;
std::unique_ptr<::mfem::GridFunction> compactification;
std::unique_ptr<mapping::DomainMapper> mapper;
};
template <typename Context, typename Keys = typename Context::Keys>
struct OwnedBindings;
/** @brief Keep typed bindings alive beside the resources they borrow; neither copying a configuration nor restoring it copies these resources. */
template <typename Context, typename... Keys>
struct OwnedBindings<Context, utils::dependencies::KeyList<Keys...>> {
template <typename Key>
using Binding = std::remove_cvref_t<decltype(std::declval<Context>().template get<Key>())>;
Resources resources;
std::tuple<std::unique_ptr<Binding<Keys>>...> bindings;
/** @brief Borrow each stable binding through the existing computational-graph input vocabulary. */
[[nodiscard]] auto context() const {
using namespace utils::dependencies;
return make_dependency_context(borrow<Keys>(*std::get<key_index<Keys, KeyList<Keys...>>()>(bindings))...);
}
};
}