MFEM  v4.1.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-2020, 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  /// Assemble the vector on the true dofs, i.e. P^t v.
96  void ParallelAssemble(Vector &tv);
97 
98  /// Returns the vector assembled on the true dofs, i.e. P^t v.
100 
101  /// Return the action of the ParLinearForm as a linear mapping.
102  /** Linear forms are linear functionals which map ParGridFunction%s to
103  the real numbers. This method performs this mapping which in
104  this case is equivalent as an inner product of the ParLinearForm
105  and ParGridFunction. */
106  double operator()(const ParGridFunction &gf) const
107  {
108  return InnerProduct(pfes->GetComm(), *this, gf);
109  }
110 
111  /// Assign constant values to the ParLinearForm data.
112  ParLinearForm &operator=(double value)
113  { LinearForm::operator=(value); return *this; }
114 
115  /// Copy the data from a Vector to the ParLinearForm data.
117  { LinearForm::operator=(v); return *this; }
118 };
119 
120 }
121 
122 #endif // MFEM_USE_MPI
123 
124 #endif
Memory< double > data
Definition: vector.hpp:52
LinearForm & operator=(const LinearForm &rhs)
Copy assignment. Only the data of the base class Vector is copied.
Definition: linearform.hpp:98
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:239
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:73
HypreParVector * ParallelAssemble()
Returns the vector assembled on the true dofs, i.e. P^t v.
Definition: plinearform.cpp:40
void Update()
Update the object according to the associated FE space fes.
Definition: linearform.hpp:166
double InnerProduct(HypreParVector *x, HypreParVector *y)
Definition: hypre.cpp:246
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:48
Class for linear form - Vector with associated FE space and LFIntegrators.
Definition: linearform.hpp:23
Class for parallel grid function.
Definition: pgridfunc.hpp:32
ParLinearForm & operator=(double value)
Assign constant values to the ParLinearForm data.