feat(FieldDofMap): Completed FieldDofMap migration
also removed legacy BarotropicPolytrope implementation
This commit is contained in:
@@ -5,6 +5,7 @@ module;
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
#include <mfem.hpp>
|
||||
|
||||
@@ -887,6 +888,110 @@ export namespace mean_field::field {
|
||||
mfem::Array<int> m_trueToReduced;
|
||||
};
|
||||
|
||||
/*
|
||||
* Canonical adapter between an MFEM GridFunction and a reduced field
|
||||
* vector.
|
||||
*
|
||||
* FieldDofMap deliberately contains only indexing information. This
|
||||
* adapter binds that indexing to the exact finite-element space whose true
|
||||
* DOFs the map describes. Consequently, a grid function from another
|
||||
* finite-element space is rejected even when it happens to have the same
|
||||
* vector size.
|
||||
*
|
||||
* The finite-element space must outlive the adapter.
|
||||
*/
|
||||
class FieldDofGridFunctionAdapter {
|
||||
public:
|
||||
FieldDofGridFunctionAdapter(
|
||||
FieldDofMap dofMap,
|
||||
const mfem::FiniteElementSpace &finiteElementSpace
|
||||
)
|
||||
: m_dofMap(std::move(dofMap)),
|
||||
m_finiteElementSpace(&finiteElementSpace) {
|
||||
if (m_dofMap.full_size() != finiteElementSpace.GetTrueVSize()) {
|
||||
throw std::invalid_argument(
|
||||
"FieldDofGridFunctionAdapter map and finite-element "
|
||||
"space have incompatible true-DOF sizes."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
const FieldDofMap &dof_map() const noexcept {
|
||||
return m_dofMap;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
const mfem::FiniteElementSpace &finite_element_space() const noexcept {
|
||||
return *m_finiteElementSpace;
|
||||
}
|
||||
|
||||
/*
|
||||
* Gather the grid function's true DOFs into reduced field ordering.
|
||||
* The output vector is not resized so MFEM vector views remain valid.
|
||||
*/
|
||||
void gather(
|
||||
const mfem::GridFunction &gridFunction,
|
||||
mfem::Vector &reduced
|
||||
) const {
|
||||
validate_grid_function(gridFunction);
|
||||
|
||||
mfem::Vector full;
|
||||
gridFunction.GetTrueDofs(full);
|
||||
m_dofMap.gather(full, reduced);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
mfem::Vector gather(const mfem::GridFunction &gridFunction) const {
|
||||
mfem::Vector reduced(m_dofMap.reduced_size());
|
||||
gather(gridFunction, reduced);
|
||||
return reduced;
|
||||
}
|
||||
|
||||
/*
|
||||
* Scatter with projection semantics. Unsupported true DOFs are zeroed
|
||||
* before the complete true vector is distributed to the grid function.
|
||||
*/
|
||||
void scatter(
|
||||
const mfem::Vector &reduced,
|
||||
mfem::GridFunction &gridFunction
|
||||
) const {
|
||||
validate_grid_function(gridFunction);
|
||||
|
||||
const mfem::Vector full = m_dofMap.scatter(reduced);
|
||||
gridFunction.SetFromTrueDofs(full);
|
||||
}
|
||||
|
||||
/*
|
||||
* Scatter while preserving the grid function's existing unsupported
|
||||
* true DOFs.
|
||||
*/
|
||||
void scatter_into(
|
||||
const mfem::Vector &reduced,
|
||||
mfem::GridFunction &gridFunction
|
||||
) const {
|
||||
validate_grid_function(gridFunction);
|
||||
|
||||
mfem::Vector full;
|
||||
gridFunction.GetTrueDofs(full);
|
||||
m_dofMap.scatter_into(reduced, full);
|
||||
gridFunction.SetFromTrueDofs(full);
|
||||
}
|
||||
|
||||
private:
|
||||
void validate_grid_function(const mfem::GridFunction &gridFunction) const {
|
||||
if (gridFunction.FESpace() != m_finiteElementSpace) {
|
||||
throw std::invalid_argument(
|
||||
"FieldDofGridFunctionAdapter received a grid function "
|
||||
"from a different finite-element space."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
FieldDofMap m_dofMap;
|
||||
const mfem::FiniteElementSpace *m_finiteElementSpace;
|
||||
};
|
||||
|
||||
/*
|
||||
* Construct the canonical solver map for a registered spatial field.
|
||||
*
|
||||
@@ -903,4 +1008,16 @@ export namespace mean_field::field {
|
||||
|
||||
return FieldDofMap(support);
|
||||
}
|
||||
|
||||
template <
|
||||
MfemDomainField FieldT,
|
||||
utils::domain::IsSchema SchemaT>
|
||||
[[nodiscard]]
|
||||
FieldDofGridFunctionAdapter
|
||||
make_field_dof_grid_function_adapter(const mfem::ParFiniteElementSpace &finiteElementSpace) {
|
||||
return FieldDofGridFunctionAdapter(
|
||||
make_field_dof_map<FieldT, SchemaT>(finiteElementSpace),
|
||||
finiteElementSpace
|
||||
);
|
||||
}
|
||||
} // namespace mean_field::field
|
||||
|
||||
Reference in New Issue
Block a user