MFEM  v4.1.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
linearform.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_LINEARFORM
13 #define MFEM_LINEARFORM
14 
15 #include "../config/config.hpp"
16 #include "lininteg.hpp"
17 #include "gridfunc.hpp"
18 
19 namespace mfem
20 {
21 
22 /// Class for linear form - Vector with associated FE space and LFIntegrators.
23 class LinearForm : public Vector
24 {
25 protected:
26  /// FE space on which the LinearForm lives. Not owned.
28 
29  /** @brief Indicates the LinerFormIntegrator%s stored in #dlfi, #dlfi_delta,
30  #blfi, and #flfi are owned by another LinearForm. */
32 
33  /// Set of Domain Integrators to be applied.
35 
36  /// Separate array for integrators with delta function coefficients.
38 
39  /// Set of Boundary Integrators to be applied.
41  Array<Array<int>*> blfi_marker; ///< Entries are not owned.
42 
43  /// Set of Boundary Face Integrators to be applied.
45  Array<Array<int>*> flfi_marker; ///< Entries are not owned.
46 
47  /// The element ids where the centers of the delta functions lie
49 
50  /// The reference coordinates where the centers of the delta functions lie
52 
53  /// If true, the delta locations are not (re)computed during assembly.
54  bool HaveDeltaLocations() { return (dlfi_delta_elem_id.Size() != 0); }
55 
56  /// Force (re)computation of delta locations.
58 
59 private:
60  /// Copy construction is not supported; body is undefined.
61  LinearForm(const LinearForm &);
62 
63 public:
64  /// Creates linear form associated with FE space @a *f.
65  /** The pointer @a f is not owned by the newly constructed object. */
66  LinearForm(FiniteElementSpace *f) : Vector(f->GetVSize())
67  { fes = f; extern_lfs = 0; UseDevice(true); }
68 
69  /** @brief Create a LinearForm on the FiniteElementSpace @a f, using the
70  same integrators as the LinearForm @a lf.
71 
72  The pointer @a f is not owned by the newly constructed object.
73 
74  The integrators in @a lf are copied as pointers and they are not owned by
75  the newly constructed LinearForm. */
77 
78  /// Create an empty LinearForm without an associated FiniteElementSpace.
79  /** The associated FiniteElementSpace can be set later using one of the
80  methods: Update(FiniteElementSpace *) or
81  Update(FiniteElementSpace *, Vector &, int). */
82  LinearForm() { fes = NULL; extern_lfs = 0; UseDevice(true); }
83 
84  /// Construct a LinearForm using previously allocated array @a data.
85  /** The LinearForm does not assume ownership of @a data which is assumed to
86  be of size at least `f->GetVSize()`. Similar to the Vector constructor
87  for externally allocated array, the pointer @a data can be NULL. The data
88  array can be replaced later using the method SetData(). */
89  LinearForm(FiniteElementSpace *f, double *data) : Vector(data, f->GetVSize())
90  { fes = f; extern_lfs = 0; }
91 
92  /// Copy assignment. Only the data of the base class Vector is copied.
93  /** It is assumed that this object and @a rhs use FiniteElementSpace%s that
94  have the same size.
95 
96  @note Defining this method overwrites the implicitly defined copy
97  assignment operator. */
99  { return operator=((const Vector &)rhs); }
100 
101  /// (DEPRECATED) Return the FE space associated with the LinearForm.
102  /** @deprecated Use FESpace() instead. */
104 
105  /// Read+write access to the associated FiniteElementSpace.
107  /// Read-only access to the associated FiniteElementSpace.
108  const FiniteElementSpace *FESpace() const { return fes; }
109 
110  /// Adds new Domain Integrator. Assumes ownership of @a lfi.
112 
113  /// Adds new Boundary Integrator. Assumes ownership of @a lfi.
115 
116  /** @brief Add new Boundary Integrator, restricted to the given boundary
117  attributes.
118 
119  Assumes ownership of @a lfi. The array @a bdr_attr_marker is stored
120  internally as a pointer to the given Array<int> object. */
122  Array<int> &bdr_attr_marker);
123 
124  /// Adds new Boundary Face Integrator. Assumes ownership of @a lfi.
126 
127  /** @brief Add new Boundary Face Integrator, restricted to the given boundary
128  attributes.
129 
130  Assumes ownership of @a lfi. The array @a bdr_attr_marker is stored
131  internally as a pointer to the given Array<int> object. */
133  Array<int> &bdr_attr_marker);
134 
135  /** @brief Access all integrators added with AddDomainIntegrator() which are
136  not DeltaLFIntegrator%s or they are DeltaLFIntegrator%s with non-delta
137  coefficients. */
139 
140  /** @brief Access all integrators added with AddDomainIntegrator() which are
141  DeltaLFIntegrator%s with delta coefficients. */
143 
144  /// Access all integrators added with AddBoundaryIntegrator().
146 
147  /// Access all integrators added with AddBdrFaceIntegrator().
149 
150  /** @brief Access all boundary markers added with AddBdrFaceIntegrator().
151  If no marker was specified when the integrator was added, the
152  corresponding pointer (to Array<int>) will be NULL. */
154 
155  /// Assembles the linear form i.e. sums over all domain/bdr integrators.
156  void Assemble();
157 
158  /// Assembles delta functions of the linear form
159  void AssembleDelta();
160 
161  /// Update the object according to the associated FE space #fes.
162  /** This method should be called when the associated FE space #fes has been
163  updated, e.g. after its associated Mesh object has been refined.
164 
165  @note This method does not perform assembly. */
167 
168  /// Associate a new FE space, @a *f, with this object and Update() it. */
170  { fes = f; SetSize(f->GetVSize()); ResetDeltaLocations(); }
171 
172  /** @brief Associate a new FE space, @a *f, with this object and use the data
173  of @a v, offset by @a v_offset, to initialize this object's Vector::data.
174 
175  @note This method does not perform assembly. */
176  void Update(FiniteElementSpace *f, Vector &v, int v_offset);
177 
178  /// Return the action of the LinearForm as a linear mapping.
179  /** Linear forms are linear functionals which map GridFunctions to
180  the real numbers. This method performs this mapping which in
181  this case is equivalent as an inner product of the LinearForm
182  and GridFunction. */
183  double operator()(const GridFunction &gf) const { return (*this)*gf; }
184 
185  /// Redefine '=' for LinearForm = constant.
186  LinearForm &operator=(double value);
187 
188  /// Copy the data from @a v.
189  /** The size of @a v must be equal to the size of the associated
190  FiniteElementSpace #fes. */
191  LinearForm &operator=(const Vector &v);
192 
193  /// Destroys linear form.
194  ~LinearForm();
195 };
196 
197 }
198 
199 #endif
Array< LinearFormIntegrator * > blfi
Set of Boundary Integrators to be applied.
Definition: linearform.hpp:40
int Size() const
Logical size of the array.
Definition: array.hpp:124
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
Definition: fespace.hpp:381
Class for grid function - Vector with associated FE space.
Definition: gridfunc.hpp:27
Memory< double > data
Definition: vector.hpp:52
LinearForm(FiniteElementSpace *f)
Creates linear form associated with FE space *f.
Definition: linearform.hpp:66
void SetSize(int s)
Resize the vector to size s.
Definition: vector.hpp:407
void Assemble()
Assembles the linear form i.e. sums over all domain/bdr integrators.
Definition: linearform.cpp:79
int extern_lfs
Indicates the LinerFormIntegrators stored in dlfi, dlfi_delta, blfi, and flfi are owned by another Li...
Definition: linearform.hpp:31
LinearForm & operator=(const LinearForm &rhs)
Copy assignment. Only the data of the base class Vector is copied.
Definition: linearform.hpp:98
Array< Array< int > * > blfi_marker
Entries are not owned.
Definition: linearform.hpp:41
void ResetDeltaLocations()
Force (re)computation of delta locations.
Definition: linearform.hpp:57
Array< DeltaLFIntegrator * > dlfi_delta
Separate array for integrators with delta function coefficients.
Definition: linearform.hpp:37
Array< IntegrationPoint > dlfi_delta_ip
The reference coordinates where the centers of the delta functions lie.
Definition: linearform.hpp:51
Abstract base class LinearFormIntegrator.
Definition: lininteg.hpp:22
double operator()(const GridFunction &gf) const
Return the action of the LinearForm as a linear mapping.
Definition: linearform.hpp:183
FiniteElementSpace * FESpace()
Read+write access to the associated FiniteElementSpace.
Definition: linearform.hpp:106
Array< LinearFormIntegrator * > * GetFLFI()
Access all integrators added with AddBdrFaceIntegrator().
Definition: linearform.hpp:148
void Update(FiniteElementSpace *f)
Associate a new FE space, *f, with this object and Update() it. */.
Definition: linearform.hpp:169
bool UseDevice() const
Return the device flag of the Memory object used by the Vector.
Definition: vector.hpp:89
Array< LinearFormIntegrator * > dlfi
Set of Domain Integrators to be applied.
Definition: linearform.hpp:34
FiniteElementSpace * fes
FE space on which the LinearForm lives. Not owned.
Definition: linearform.hpp:27
void AddBdrFaceIntegrator(LinearFormIntegrator *lfi)
Adds new Boundary Face Integrator. Assumes ownership of lfi.
Definition: linearform.cpp:66
void AddBoundaryIntegrator(LinearFormIntegrator *lfi)
Adds new Boundary Integrator. Assumes ownership of lfi.
Definition: linearform.cpp:53
const FiniteElementSpace * FESpace() const
Read-only access to the associated FiniteElementSpace.
Definition: linearform.hpp:108
Array< DeltaLFIntegrator * > * GetDLFI_Delta()
Access all integrators added with AddDomainIntegrator() which are DeltaLFIntegrators with delta coeff...
Definition: linearform.hpp:142
LinearForm()
Create an empty LinearForm without an associated FiniteElementSpace.
Definition: linearform.hpp:82
void AddDomainIntegrator(LinearFormIntegrator *lfi)
Adds new Domain Integrator. Assumes ownership of lfi.
Definition: linearform.cpp:39
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition: fespace.hpp:87
Array< Array< int > * > * GetFLFI_Marker()
Access all boundary markers added with AddBdrFaceIntegrator(). If no marker was specified when the in...
Definition: linearform.hpp:153
void SetSize(int nsize)
Change logical size of the array, keep existing entries.
Definition: array.hpp:635
void AssembleDelta()
Assembles delta functions of the linear form.
Definition: linearform.cpp:206
void Update()
Update the object according to the associated FE space fes.
Definition: linearform.hpp:166
Array< LinearFormIntegrator * > * GetBLFI()
Access all integrators added with AddBoundaryIntegrator().
Definition: linearform.hpp:145
~LinearForm()
Destroys linear form.
Definition: linearform.cpp:259
Array< int > dlfi_delta_elem_id
The element ids where the centers of the delta functions lie.
Definition: linearform.hpp:48
bool HaveDeltaLocations()
If true, the delta locations are not (re)computed during assembly.
Definition: linearform.hpp:54
Vector data type.
Definition: vector.hpp:48
LinearForm(FiniteElementSpace *f, double *data)
Construct a LinearForm using previously allocated array data.
Definition: linearform.hpp:89
Class for linear form - Vector with associated FE space and LFIntegrators.
Definition: linearform.hpp:23
Array< LinearFormIntegrator * > flfi
Set of Boundary Face Integrators to be applied.
Definition: linearform.hpp:44
Array< Array< int > * > flfi_marker
Entries are not owned.
Definition: linearform.hpp:45
FiniteElementSpace * GetFES()
(DEPRECATED) Return the FE space associated with the LinearForm.
Definition: linearform.hpp:103
Array< LinearFormIntegrator * > * GetDLFI()
Access all integrators added with AddDomainIntegrator() which are not DeltaLFIntegrators or they are ...
Definition: linearform.hpp:138