Serac  0.1
Serac is an implicit thermal strucural mechanics simulation code.
finite_element_state.hpp
Go to the documentation of this file.
1 // Copyright (c) 2019-2024, Lawrence Livermore National Security, LLC and
2 // other Serac Project Developers. See the top-level LICENSE file for
3 // details.
4 //
5 // SPDX-License-Identifier: (BSD-3-Clause)
6 
14 #pragma once
15 
16 #include <functional>
17 #include <memory>
18 #include <optional>
19 
20 #include "mfem.hpp"
21 
24 
25 namespace serac {
26 
30 inline bool is_scalar_valued(const GeneralCoefficient& coef)
31 {
32  return holds_alternative<std::shared_ptr<mfem::Coefficient>>(coef);
33 }
34 
38 inline bool is_vector_valued(const GeneralCoefficient& coef)
39 {
40  return holds_alternative<std::shared_ptr<mfem::VectorCoefficient>>(coef);
41 }
42 
49 public:
51  using mfem::Vector::Print;
52 
59 
66 
74  {
76  return *this;
77  }
78 
86  {
88  return *this;
89  }
90 
97  FiniteElementState& operator=(const mfem::HypreParVector& rhs)
98  {
100  return *this;
101  }
102 
109  FiniteElementState& operator=(const mfem::Vector& rhs)
110  {
112  return *this;
113  }
114 
122  {
124  return *this;
125  }
126 
136  void fillGridFunction(mfem::ParGridFunction& grid_function) const { grid_function.SetFromTrueDofs(*this); }
137 
148  void setFromGridFunction(const mfem::ParGridFunction& grid_function) { grid_function.GetTrueDofs(*this); }
149 
159  void project(mfem::VectorCoefficient& coef, mfem::Array<int>& dof_list);
160 
171  void project(mfem::Coefficient& coef, mfem::Array<int>& dof_list, std::optional<int> component = {});
172 
180  void project(const GeneralCoefficient& coef);
181 
183  void project(mfem::Coefficient& coef);
184 
186  void project(mfem::VectorCoefficient& coef);
187 
197  void projectOnBoundary(mfem::Coefficient& coef, const mfem::Array<int>& markers);
198 
200  void projectOnBoundary(mfem::VectorCoefficient& coef, const mfem::Array<int>& markers);
201 
207  mfem::ParGridFunction& gridFunction() const;
208 
209 protected:
216  mutable std::unique_ptr<mfem::ParGridFunction> grid_func_;
217 };
218 
226 double norm(const FiniteElementState& state, const double p = 2);
227 
235 double computeL2Error(const FiniteElementState& state, mfem::VectorCoefficient& exact_solution);
236 
244 double computeL2Error(const FiniteElementState& state, mfem::Coefficient& exact_solution);
245 
246 } // namespace serac
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.
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.
FiniteElementVector(const mfem::ParFiniteElementSpace &space, const std::string &name="")
Minimal constructor for a FiniteElementVector given a finite element space.
This file contains the declaration of structure that manages vectors derived from an MFEM finite elem...
Accelerator functionality.
Definition: serac.cpp:38
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
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
This file contains the declaration of a two-element variant type.