MFEM  v4.6.0
Finite element discretization library
plinearform.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2023, 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  /// Assembles the ParLinearForm i.e. sums over all domain/bdr integrators.
117  /** When @ref LinearForm::UseFastAssembly "UseFastAssembly(true)" has been
118  called and the linear form assembly is compatible with device execution,
119  the assembly will be executed on the device. */
120  void Assemble();
121 
122  /// Return true if assembly on device is supported, false otherwise.
123  virtual bool SupportsDevice() const;
124 
125  void AssembleSharedFaces();
126 
127  /// Assemble the vector on the true dofs, i.e. P^t v.
128  void ParallelAssemble(Vector &tv);
129 
130  /// Returns the vector assembled on the true dofs, i.e. P^t v.
132 
133  /// Return the action of the ParLinearForm as a linear mapping.
134  /** Linear forms are linear functionals which map ParGridFunction%s to the
135  real numbers. This method performs this mapping which in this case is
136  equivalent as an inner product of the ParLinearForm and
137  ParGridFunction. */
138  double operator()(const ParGridFunction &gf) const
139  {
140  return InnerProduct(pfes->GetComm(), *this, gf);
141  }
142 
143  /// Assign constant values to the ParLinearForm data.
144  ParLinearForm &operator=(double value)
145  { LinearForm::operator=(value); return *this; }
146 
147  /// Copy the data from a Vector to the ParLinearForm data.
149  { LinearForm::operator=(v); return *this; }
150 };
151 
152 }
153 
154 #endif // MFEM_USE_MPI
155 
156 #endif
Memory< double > data
Definition: vector.hpp:62
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:121
virtual bool SupportsDevice() const
Return true if assembly on device is supported, false otherwise.
Definition: plinearform.cpp:57
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
double operator()(const ParGridFunction &gf) const
Return the action of the ParLinearForm as a linear mapping.
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
std::function< double(const Vector &)> f(double mass_coeff)
Definition: lor_mms.hpp:30
Class for parallel linear form.
Definition: plinearform.hpp:26
void Assemble()
Assembles the ParLinearForm i.e. sums over all domain/bdr integrators.
Definition: plinearform.cpp:46
Wrapper for hypre&#39;s parallel vector class.
Definition: hypre.hpp:161
ParFiniteElementSpace * ParFESpace() const
Definition: plinearform.hpp:76
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition: fespace.hpp:219
HypreParVector * ParallelAssemble()
Returns the vector assembled on the true dofs, i.e. P^t v.
void Update()
Update the object according to the associated FE space fes.
Definition: linearform.cpp:344
double InnerProduct(HypreParVector *x, HypreParVector *y)
Definition: hypre.cpp:414
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
MPI_Comm GetComm() const
Definition: pfespace.hpp:269
Vector data type.
Definition: vector.hpp:58
Vector with associated FE space and LinearFormIntegrators.
Definition: linearform.hpp:24
Class for parallel grid function.
Definition: pgridfunc.hpp:32
ParLinearForm & operator=(double value)
Assign constant values to the ParLinearForm data.