MFEM  v4.4.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
plinearform.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2022, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-806117.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability visit https://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11 
12 #ifndef MFEM_PLINEARFORM
13 #define MFEM_PLINEARFORM
14 
15 #include "../config/config.hpp"
16 
17 #ifdef MFEM_USE_MPI
18 
19 #include "pgridfunc.hpp"
20 #include "linearform.hpp"
21 
22 namespace mfem
23 {
24 
25 /// Class for parallel linear form
26 class ParLinearForm : public LinearForm
27 {
28 protected:
29  ParFiniteElementSpace *pfes; ///< Points to the same object as #fes
30 
31 private:
32  /// Copy construction is not supported; body is undefined.
34 
35 public:
36  /** @brief Create an empty ParLinearForm without an associated
37  ParFiniteElementSpace.
38 
39  The associated ParFiniteElementSpace can be set later using one of the
40  methods: Update(ParFiniteElementSpace *) or
41  Update(ParFiniteElementSpace *, Vector &, int). */
42  ParLinearForm() : LinearForm() { pfes = NULL; }
43 
44  /// Create a ParLinearForm on the FE space @a *pf.
45  /** The pointer @a pf is not owned by the newly constructed object. */
47 
48  /// Construct a ParLinearForm using previously allocated array @a data.
49  /** The ParLinearForm does not assume ownership of @a data which is assumed
50  to be of size at least `pf->GetVSize()`. Similar to the LinearForm and
51  Vector constructors for externally allocated array, the pointer @a data
52  can be NULL. The data array can be replaced later using the method
53  SetData(). */
55  LinearForm(pf, data), pfes(pf) { }
56 
57  /** @brief Create a ParLinearForm on the ParFiniteElementSpace @a *pf, using
58  the same integrators as the ParLinearForm @a *plf.
59 
60  The pointer @a pf is not owned by the newly constructed object.
61 
62  The integrators in @a plf are copied as pointers and they are not owned
63  by the newly constructed LinearForm. */
65  : LinearForm(pf, plf) { pfes = pf; }
66 
67  /// Copy assignment. Only the data of the base class Vector is copied.
68  /** It is assumed that this object and @a rhs use ParFiniteElementSpace%s
69  that have the same size.
70 
71  @note Defining this method overwrites the implicitly defined copy
72  assignment operator. */
74  { return operator=((const Vector &)rhs); }
75 
76  ParFiniteElementSpace *ParFESpace() const { return pfes; }
77 
78  /// Update the object according to the given new FE space @a *pf.
79  /** If the pointer @a pf is NULL (this is the default value), the FE space
80  already associated with this object is used.
81 
82  This method should be called when the associated FE space #fes has been
83  updated, e.g. after its associated Mesh object has been refined.
84 
85  @note This method does not perform assembly. */
86  void Update(ParFiniteElementSpace *pf = NULL);
87 
88  /** @brief Associate a new FE space, @a *pf, with this object and use the
89  data of @a v, offset by @a v_offset, to initialize this object's
90  Vector::data.
91 
92  @note This method does not perform assembly. */
93  void Update(ParFiniteElementSpace *pf, Vector &v, int v_offset);
94 
95 
96  /** @brief Make the ParLinearForm reference external data on a new
97  FiniteElementSpace. */
98  /** This method changes the FiniteElementSpace associated with the
99  ParLinearForm to @a *f and sets the data of the Vector @a v (plus the @a
100  v_offset) as external data in the ParLinearForm.
101 
102  @note This version of the method will also perform bounds checks when the
103  build option MFEM_DEBUG is enabled. */
104  virtual void MakeRef(FiniteElementSpace *f, Vector &v, int v_offset);
105 
106  /** @brief Make the ParLinearForm reference external data on a new
107  ParFiniteElementSpace. */
108  /** This method changes the ParFiniteElementSpace associated with the
109  ParLinearForm to @a *pf and sets the data of the Vector @a v (plus the @a
110  v_offset) as external data in the ParLinearForm.
111 
112  @note This version of the method will also perform bounds checks when the
113  build option MFEM_DEBUG is enabled. */
114  void MakeRef(ParFiniteElementSpace *pf, Vector &v, int v_offset);
115 
116  void Assemble();
117 
118  void AssembleSharedFaces();
119 
120  /// Assemble the vector on the true dofs, i.e. P^t v.
121  void ParallelAssemble(Vector &tv);
122 
123  /// Returns the vector assembled on the true dofs, i.e. P^t v.
125 
126  /// Return the action of the ParLinearForm as a linear mapping.
127  /** Linear forms are linear functionals which map ParGridFunction%s to the
128  real numbers. This method performs this mapping which in this case is
129  equivalent as an inner product of the ParLinearForm and
130  ParGridFunction. */
131  double operator()(const ParGridFunction &gf) const
132  {
133  return InnerProduct(pfes->GetComm(), *this, gf);
134  }
135 
136  /// Assign constant values to the ParLinearForm data.
137  ParLinearForm &operator=(double value)
138  { LinearForm::operator=(value); return *this; }
139 
140  /// Copy the data from a Vector to the ParLinearForm data.
142  { LinearForm::operator=(v); return *this; }
143 };
144 
145 }
146 
147 #endif // MFEM_USE_MPI
148 
149 #endif
Memory< double > data
Definition: vector.hpp:64
virtual void MakeRef(FiniteElementSpace *f, Vector &v, int v_offset)
Make the ParLinearForm reference external data on a new FiniteElementSpace.
Definition: plinearform.cpp:33
LinearForm & operator=(const LinearForm &rhs)
Copy assignment. Only the data of the base class Vector is copied.
Definition: linearform.hpp:110
ParLinearForm & operator=(const ParLinearForm &rhs)
Copy assignment. Only the data of the base class Vector is copied.
Definition: plinearform.hpp:73
Abstract parallel finite element space.
Definition: pfespace.hpp:28
ParLinearForm(ParFiniteElementSpace *pf, double *data)
Construct a ParLinearForm using previously allocated array data.
Definition: plinearform.hpp:54
ParLinearForm()
Create an empty ParLinearForm without an associated ParFiniteElementSpace.
Definition: plinearform.hpp:42
Class for parallel linear form.
Definition: plinearform.hpp:26
MPI_Comm GetComm() const
Definition: pfespace.hpp:273
double f(const Vector &xvec)
Definition: lor_mms.hpp:32
ParFiniteElementSpace * ParFESpace() const
Definition: plinearform.hpp:76
double operator()(const ParGridFunction &gf) const
Return the action of the ParLinearForm as a linear mapping.
Wrapper for hypre&#39;s parallel vector class.
Definition: hypre.hpp:148
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition: fespace.hpp:88
HypreParVector * ParallelAssemble()
Returns the vector assembled on the true dofs, i.e. P^t v.
Definition: plinearform.cpp:93
void Update()
Update the object according to the associated FE space fes.
Definition: linearform.hpp:188
double InnerProduct(HypreParVector *x, HypreParVector *y)
Definition: hypre.cpp:426
ParLinearForm & operator=(const Vector &v)
Copy the data from a Vector to the ParLinearForm data.
ParLinearForm(ParFiniteElementSpace *pf)
Create a ParLinearForm on the FE space *pf.
Definition: plinearform.hpp:46
ParLinearForm(ParFiniteElementSpace *pf, ParLinearForm *plf)
Create a ParLinearForm on the ParFiniteElementSpace *pf, using the same integrators as the ParLinearF...
Definition: plinearform.hpp:64
ParFiniteElementSpace * pfes
Points to the same object as fes.
Definition: plinearform.hpp:29
Vector data type.
Definition: vector.hpp:60
Vector with associated FE space and LinearFormIntegrators.
Definition: linearform.hpp:23
Class for parallel grid function.
Definition: pgridfunc.hpp:32
ParLinearForm & operator=(double value)
Assign constant values to the ParLinearForm data.