Serac  0.1
Serac is an implicit thermal strucural mechanics simulation code.
finite_element_vector.hpp
Go to the documentation of this file.
1 // Copyright (c) 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 <string>
19 #include <tuple>
20 
21 #include "mpi.h"
22 #include "mfem.hpp"
23 
24 #include "serac/serac_config.hpp"
27 
28 namespace serac {
29 
33 using GeneralCoefficient = variant<std::shared_ptr<mfem::Coefficient>, std::shared_ptr<mfem::VectorCoefficient>>;
34 
38 enum class ElementType
39 {
40  H1,
41  HCURL,
42  HDIV,
43  L2
44 };
45 
54 class FiniteElementVector : public mfem::HypreParVector {
55  public:
61  FiniteElementVector(const mfem::ParFiniteElementSpace& space, const std::string& name = "");
62 
71  template <typename FunctionSpace>
72  FiniteElementVector(mfem::ParMesh& mesh, [[maybe_unused]] FunctionSpace f, const std::string& name = "")
73  : mesh_(mesh), name_(name)
74  {
75  std::tie(space_, coll_) = serac::generateParFiniteElementSpace<FunctionSpace>(&mesh);
76 
77  // Construct a hypre par vector based on the new finite element space
78  HypreParVector new_vector(space_.get());
79 
80  // Move the data from this new hypre vector into this object without doubly allocating the data
81  auto* parallel_vec = new_vector.StealParVector();
82  WrapHypreParVector(parallel_vec);
83 
84  // Initialize the vector to zero
85  HypreParVector::operator=(0.0);
86  }
87 
94  {
95  HypreParVector::operator=(rhs);
96  }
97 
104 
112 
120 
127  FiniteElementVector& operator=(const mfem::HypreParVector& rhs);
128 
135  FiniteElementVector& operator=(const mfem::Vector& rhs);
136 
141  MPI_Comm comm() const { return space_->GetComm(); }
142 
147  mfem::ParMesh& mesh() { return mesh_; }
149  const mfem::ParMesh& mesh() const { return mesh_; }
150 
155  mfem::ParFiniteElementSpace& space() { return *space_; }
157  const mfem::ParFiniteElementSpace& space() const { return *space_; }
158 
163  std::string name() const { return name_; }
164 
173  FiniteElementVector& operator=(const double value);
174 
178  virtual ~FiniteElementVector() {}
179 
180  protected:
184  std::reference_wrapper<mfem::ParMesh> mesh_;
185 
190  std::unique_ptr<mfem::FiniteElementCollection> coll_;
191 
195  std::unique_ptr<mfem::ParFiniteElementSpace> space_;
196 
200  std::string name_ = "";
201 };
202 
211 double avg(const FiniteElementVector& fe_vector);
212 
221 double max(const FiniteElementVector& fe_vector);
222 
231 double min(const FiniteElementVector& fe_vector);
232 
240 double innerProduct(const FiniteElementVector& vec1, const FiniteElementVector& vec2);
241 
242 } // namespace serac
Class for encapsulating the data associated with a vector derived from a MFEM finite element space....
std::string name_
The name of the finite element vector.
std::unique_ptr< mfem::FiniteElementCollection > coll_
Handle to the FiniteElementCollection, which is owned by MFEMSidreDataCollection.
FiniteElementVector(const FiniteElementVector &rhs)
Copy constructor.
MPI_Comm comm() const
Returns the MPI communicator for the state.
mfem::ParFiniteElementSpace & space()
Returns a non-owning reference to the internal FESpace.
virtual ~FiniteElementVector()
Destroy the Finite Element Vector object.
const mfem::ParMesh & mesh() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
const mfem::ParFiniteElementSpace & space() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
FiniteElementVector & operator=(const FiniteElementVector &rhs)
Copy assignment.
std::reference_wrapper< mfem::ParMesh > mesh_
A reference to the mesh object on which the field is defined.
std::unique_ptr< mfem::ParFiniteElementSpace > space_
Handle to the mfem::ParFiniteElementSpace, which is owned by MFEMSidreDataCollection.
FiniteElementVector(mfem::ParMesh &mesh, [[maybe_unused]] FunctionSpace f, const std::string &name="")
Construct a new Finite Element Vector object given a templated function space.
std::string name() const
Returns the name of the FEState (field)
FiniteElementVector(const mfem::ParFiniteElementSpace &space, const std::string &name="")
Minimal constructor for a FiniteElementVector given a finite element space.
mfem::ParMesh & mesh()
Returns a non-owning reference to the internal mesh object.
Implementation of the quadrature-function-based functional enabling rapid development of FEM formulat...
Accelerator functionality.
Definition: serac.cpp:36
double innerProduct(const FiniteElementVector &v1, const FiniteElementVector &v2)
Find the inner prodcut between two finite element vectors across all dofs.
SERAC_HOST_DEVICE auto max(dual< gradient_type > a, double b)
Implementation of max for dual numbers.
Definition: dual.hpp:229
SERAC_HOST_DEVICE auto min(dual< gradient_type > a, double b)
Implementation of min for dual numbers.
Definition: dual.hpp:255
double avg(const FiniteElementVector &fe_vector)
Find the average value of a finite element vector across all dofs.
ElementType
The type of a finite element basis function.
@ H1
Nodal scalar-valued basis functions.
@ HDIV
Raviart-Thomas (continuous normal) vector-valued basis functions.
@ HCURL
Nedelec (continuous tangent) vector-valued basis functions.
a small POD class for tracking function space metadata
Discontinuous elements of order p.
Arbitrary-rank tensor class.
Definition: tensor.hpp:28
This file contains the declaration of a two-element variant type.