44 lines
1.8 KiB
C++
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))...);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
}
|