19 #include <type_traits>
37 SLIC_ERROR_IF(v_mfem.Size() != dim,
"Cannot copy tensor into an MFEM Vector with incompatible size.");
38 for (
int i = 0; i < dim; i++) v_mfem(i) = v[i];
46 SLIC_ERROR_IF(v_mfem.Size() != 1,
"Mfem Vector is not a singleton.");
53 template <
typename Ret,
typename Arg,
typename... Rest>
59 template <
typename Ret,
typename F,
typename Arg,
typename... Rest>
65 template <
typename Ret,
typename F,
typename Arg,
typename... Rest>
78 using
first_argument = std::decay_t<decltype(first_argument_helper(std::declval<T>()))>;
83 template <typename Callable>
84 auto evaluateTensorFunctionOnMfemVector(const mfem::Vector& X_mfem, Callable&& f)
87 SLIC_ERROR_IF(X_mfem.Size() !=
size(X),
88 "Size of tensor in callable does not match spatial dimension of MFEM Vector.");
89 for (
int i = 0; i < X_mfem.Size(); i++) X[i] = X_mfem[i];
100 return holds_alternative<std::shared_ptr<mfem::Coefficient>>(coef);
108 return holds_alternative<std::shared_ptr<mfem::VectorCoefficient>>(coef);
119 using mfem::Vector::Print;
204 void fillGridFunction(mfem::ParGridFunction& grid_function)
const { grid_function.SetFromTrueDofs(*
this); }
216 void setFromGridFunction(
const mfem::ParGridFunction& grid_function) { grid_function.GetTrueDofs(*
this); }
227 void project(mfem::VectorCoefficient& coef, mfem::Array<int>& dof_list);
239 void project(mfem::Coefficient& coef, mfem::Array<int>& dof_list, std::optional<int> component = {});
251 void project(mfem::Coefficient& coef);
254 void project(mfem::VectorCoefficient& coef);
265 void projectOnBoundary(mfem::Coefficient& coef,
const mfem::Array<int>& markers);
268 void projectOnBoundary(mfem::VectorCoefficient& coef,
const mfem::Array<int>& markers);
271 void project(mfem::Coefficient& coef,
const Domain& d);
274 void project(mfem::VectorCoefficient& coef,
const Domain& d);
298 template <
typename FieldFunction>
301 auto evaluate_mfem = [&field_function](
const mfem::Vector& X_mfem, mfem::Vector& u_mfem) {
302 auto u = detail::evaluateTensorFunctionOnMfemVector(X_mfem, field_function);
303 detail::setMfemVectorFromTensorOrDouble(u_mfem, u);
306 mfem::VectorFunctionCoefficient coef(
space_->GetVDim(), evaluate_mfem);
Class for encapsulating the critical MFEM components of a primal finite element field.
FiniteElementState & operator=(FiniteElementState &&rhs)
Move assignment.
void projectOnBoundary(mfem::Coefficient &coef, const mfem::Array< int > &markers)
Project a coefficient on a specific set of marked boundaries.
FiniteElementState(FiniteElementState &&rhs)
Move construct a new Finite Element State object.
std::unique_ptr< mfem::ParGridFunction > grid_func_
An optional container for a grid function (L-vector) view of the finite element state.
void setFromGridFunction(const mfem::ParGridFunction &grid_function)
Initialize the true vector in the FiniteElementState based on an input grid function.
FiniteElementState(const FiniteElementState &rhs)
Copy constructor.
void setFromFieldFunction(FieldFunction &&field_function)
Set state as interpolant of an analytical function.
FiniteElementState & operator=(const mfem::HypreParVector &rhs)
Copy assignment with HypreParVector.
void fillGridFunction(mfem::ParGridFunction &grid_function) const
Fill a user-provided grid function based on the underlying true vector.
mfem::ParGridFunction & gridFunction() const
Construct a grid function from the finite element state true vector.
FiniteElementState & operator=(const FiniteElementState &rhs)
Copy assignment.
FiniteElementState & operator=(double rhs)
Copy assignment with double.
void project(mfem::VectorCoefficient &coef, mfem::Array< int > &dof_list)
Project a vector coefficient onto a set of dofs.
FiniteElementState & operator=(const mfem::Vector &rhs)
Copy assignment with mfem::Vector.
Class for encapsulating the data associated with a vector derived from a MFEM finite element space....
FiniteElementVector & operator=(const FiniteElementVector &rhs)
Copy assignment.
std::unique_ptr< mfem::ParFiniteElementSpace > space_
Handle to the mfem::ParFiniteElementSpace, which is owned by MFEMSidreDataCollection.
FiniteElementVector(const mfem::ParFiniteElementSpace &space, const std::string &name="")
Minimal constructor for a FiniteElementVector given a finite element space.
many of the functions in this file amount to extracting element indices from an mesh_t like
std::decay_t< decltype(first_argument_helper(std::declval< T >()))> first_argument
void setMfemVectorFromTensorOrDouble(mfem::Vector &v_mfem, const tensor< double, dim > &v)
Helper function to copy a tensor into an mfem Vector.
decltype(first_argument_helper(&F::operator())) first_argument_helper(F)
This file contains the declaration of structure that manages vectors derived from an MFEM finite elem...
Accelerator functionality.
variant< std::shared_ptr< mfem::Coefficient >, std::shared_ptr< mfem::VectorCoefficient > > GeneralCoefficient
A sum type for encapsulating either a scalar or vector coeffient.
bool is_vector_valued(const GeneralCoefficient &coef)
convenience function for querying the type stored in a GeneralCoefficient
constexpr SERAC_HOST_DEVICE int size(const tensor< T, n... > &)
returns the total number of stored values in a tensor
bool is_scalar_valued(const GeneralCoefficient &coef)
convenience function for querying the type stored in a GeneralCoefficient
double computeL2Error(const FiniteElementState &state, mfem::VectorCoefficient &exact_solution)
Find the L2 norm of the error of a vector-valued finite element state with respect to an exact soluti...
constexpr SERAC_HOST_DEVICE auto norm(const isotropic_tensor< T, m, m > &I)
compute the Frobenius norm (sqrt(tr(dot(transpose(I), I)))) of an isotropic tensor
Implementation of the tensor class used by Functional.
This file contains the declaration of a two-element variant type.