MFEM  v4.3.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-2021, 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 /// Vector with associated FE space and LinearFormIntegrators.
23 class LinearForm : public Vector
24 {
25 protected:
26  /// FE space on which the LinearForm lives. Not owned.
28 
29  /** @brief Indicates the LinearFormIntegrator%s stored in #domain_integs,
30  #domain_delta_integs, #boundary_integs, and #boundary_face_integs are
31  owned by another LinearForm. */
33 
34  /// Set of Domain Integrators to be applied.
36  /// Element attribute marker (should be of length mesh->attributes)
37  /// Includes all by default.
38  /// 0 - ignore attribute
39  /// 1 - include attribute
41 
42  /// Separate array for integrators with delta function coefficients.
44 
45  /// Set of Boundary Integrators to be applied.
47  /// Entries are not owned.
49 
50  /// Set of Boundary Face Integrators to be applied.
52  Array<Array<int>*> boundary_face_integs_marker; ///< Entries not owned.
53 
54  /// Set of Internal Face Integrators to be applied.
56 
57  /// The element ids where the centers of the delta functions lie
59 
60  /// The reference coordinates where the centers of the delta functions lie
62 
63  /// If true, the delta locations are not (re)computed during assembly.
65  { return (domain_delta_integs_elem_id.Size() != 0); }
66 
67  /// Force (re)computation of delta locations.
69 
70 private:
71  /// Copy construction is not supported; body is undefined.
72  LinearForm(const LinearForm &);
73 
74 public:
75  /// Creates linear form associated with FE space @a *f.
76  /** The pointer @a f is not owned by the newly constructed object. */
78  { fes = f; extern_lfs = 0; UseDevice(true); }
79 
80  /** @brief Create a LinearForm on the FiniteElementSpace @a f, using the
81  same integrators as the LinearForm @a lf.
82 
83  The pointer @a f is not owned by the newly constructed object.
84 
85  The integrators in @a lf are copied as pointers and they are not owned by
86  the newly constructed LinearForm. */
88 
89  /// Create an empty LinearForm without an associated FiniteElementSpace.
90  /** The associated FiniteElementSpace can be set later using one of the
91  methods: Update(FiniteElementSpace *) or
92  Update(FiniteElementSpace *, Vector &, int). */
93  LinearForm() { fes = NULL; extern_lfs = 0; UseDevice(true); }
94 
95  /// Construct a LinearForm using previously allocated array @a data.
96  /** The LinearForm does not assume ownership of @a data which is assumed to
97  be of size at least `f->GetVSize()`. Similar to the Vector constructor
98  for externally allocated array, the pointer @a data can be NULL. The data
99  array can be replaced later using the method SetData(). */
100  LinearForm(FiniteElementSpace *f, double *data) : Vector(data, f->GetVSize())
101  { fes = f; extern_lfs = 0; }
102 
103  /// Copy assignment. Only the data of the base class Vector is copied.
104  /** It is assumed that this object and @a rhs use FiniteElementSpace%s that
105  have the same size.
106 
107  @note Defining this method overwrites the implicitly defined copy
108  assignment operator. */
110  { return operator=((const Vector &)rhs); }
111 
112  /// (DEPRECATED) Return the FE space associated with the LinearForm.
113  /** @deprecated Use FESpace() instead. */
114  MFEM_DEPRECATED FiniteElementSpace *GetFES() { return fes; }
115 
116  /// Read+write access to the associated FiniteElementSpace.
118  /// Read-only access to the associated FiniteElementSpace.
119  const FiniteElementSpace *FESpace() const { return fes; }
120 
121  /// Adds new Domain Integrator. Assumes ownership of @a lfi.
123  /// Adds new Domain Integrator restricted to certain elements specified by
124  /// the @a elem_attr_marker.
126  Array<int> &elem_marker);
127 
128  /// Adds new Boundary Integrator. Assumes ownership of @a lfi.
130 
131  /** @brief Add new Boundary Integrator, restricted to the given boundary
132  attributes.
133 
134  Assumes ownership of @a lfi. The array @a bdr_attr_marker is stored
135  internally as a pointer to the given Array<int> object. */
137  Array<int> &bdr_attr_marker);
138 
139  /// Adds new Boundary Face Integrator. Assumes ownership of @a lfi.
141 
142  /** @brief Add new Boundary Face Integrator, restricted to the given boundary
143  attributes.
144 
145  Assumes ownership of @a lfi. The array @a bdr_attr_marker is stored
146  internally as a pointer to the given Array<int> object. */
148  Array<int> &bdr_attr_marker);
149 
150  /// Adds new Interior Face Integrator. Assumes ownership of @a lfi.
152 
153  /** @brief Access all integrators added with AddDomainIntegrator() which are
154  not DeltaLFIntegrator%s or they are DeltaLFIntegrator%s with non-delta
155  coefficients. */
157 
158  /** @brief Access all integrators added with AddDomainIntegrator() which are
159  DeltaLFIntegrator%s with delta coefficients. */
161 
162  /// Access all integrators added with AddBoundaryIntegrator().
164 
165  /// Access all integrators added with AddBdrFaceIntegrator().
167 
168  /// Access all integrators added with AddInteriorFaceIntegrator().
170 
171  /** @brief Access all boundary markers added with AddBdrFaceIntegrator().
172  If no marker was specified when the integrator was added, the
173  corresponding pointer (to Array<int>) will be NULL. */
175 
176  /// Assembles the linear form i.e. sums over all domain/bdr integrators.
177  void Assemble();
178 
179  /// Assembles delta functions of the linear form
180  void AssembleDelta();
181 
182  /// Update the object according to the associated FE space #fes.
183  /** This method should be called when the associated FE space #fes has been
184  updated, e.g. after its associated Mesh object has been refined.
185 
186  @note This method does not perform assembly. */
188 
189  /// Associate a new FE space, @a *f, with this object and Update() it. */
191  { fes = f; SetSize(f->GetVSize()); ResetDeltaLocations(); }
192 
193  /** @brief Associate a new FE space, @a *f, with this object and use the data
194  of @a v, offset by @a v_offset, to initialize this object's Vector::data.
195 
196  @note This method does not perform assembly. */
197  void Update(FiniteElementSpace *f, Vector &v, int v_offset);
198 
199  /** @brief Make the LinearForm reference external data on a new
200  FiniteElementSpace. */
201  /** This method changes the FiniteElementSpace associated with the LinearForm
202  @a *f and sets the data of the Vector @a v (plus the @a v_offset) as
203  external data in the LinearForm.
204 
205  @note This version of the method will also perform bounds checks when the
206  build option MFEM_DEBUG is enabled. */
207  virtual void MakeRef(FiniteElementSpace *f, Vector &v, int v_offset);
208 
209  /// Return the action of the LinearForm as a linear mapping.
210  /** Linear forms are linear functionals which map GridFunctions to
211  the real numbers. This method performs this mapping which in
212  this case is equivalent as an inner product of the LinearForm
213  and GridFunction. */
214  double operator()(const GridFunction &gf) const { return (*this)*gf; }
215 
216  /// Redefine '=' for LinearForm = constant.
217  LinearForm &operator=(double value);
218 
219  /// Copy the data from @a v.
220  /** The size of @a v must be equal to the size of the associated
221  FiniteElementSpace #fes. */
222  LinearForm &operator=(const Vector &v);
223 
224  /// Destroys linear form.
225  ~LinearForm();
226 };
227 
228 }
229 
230 #endif
int Size() const
Return the logical size of the array.
Definition: array.hpp:134
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
Definition: fespace.hpp:540
Class for grid function - Vector with associated FE space.
Definition: gridfunc.hpp:30
Memory< double > data
Definition: vector.hpp:64
LinearForm(FiniteElementSpace *f)
Creates linear form associated with FE space *f.
Definition: linearform.hpp:77
void SetSize(int s)
Resize the vector to size s.
Definition: vector.hpp:513
virtual void MakeRef(FiniteElementSpace *f, Vector &v, int v_offset)
Make the LinearForm reference external data on a new FiniteElementSpace.
Definition: linearform.cpp:277
Array< Array< int > * > boundary_face_integs_marker
Entries not owned.
Definition: linearform.hpp:52
void Assemble()
Assembles the linear form i.e. sums over all domain/bdr integrators.
Definition: linearform.cpp:102
int extern_lfs
Indicates the LinearFormIntegrators stored in domain_integs, domain_delta_integs, boundary_integs...
Definition: linearform.hpp:32
LinearForm & operator=(const LinearForm &rhs)
Copy assignment. Only the data of the base class Vector is copied.
Definition: linearform.hpp:109
Array< IntegrationPoint > domain_delta_integs_ip
The reference coordinates where the centers of the delta functions lie.
Definition: linearform.hpp:61
void ResetDeltaLocations()
Force (re)computation of delta locations.
Definition: linearform.hpp:68
void AddInteriorFaceIntegrator(LinearFormIntegrator *lfi)
Adds new Interior Face Integrator. Assumes ownership of lfi.
Definition: linearform.cpp:97
Array< int > domain_delta_integs_elem_id
The element ids where the centers of the delta functions lie.
Definition: linearform.hpp:58
Array< LinearFormIntegrator * > boundary_face_integs
Set of Boundary Face Integrators to be applied.
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:214
FiniteElementSpace * FESpace()
Read+write access to the associated FiniteElementSpace.
Definition: linearform.hpp:117
Array< LinearFormIntegrator * > * GetFLFI()
Access all integrators added with AddBdrFaceIntegrator().
Definition: linearform.hpp:166
Array< LinearFormIntegrator * > interior_face_integs
Set of Internal Face Integrators to be applied.
Definition: linearform.hpp:55
void Update(FiniteElementSpace *f)
Associate a new FE space, *f, with this object and Update() it. */.
Definition: linearform.hpp:190
double f(const Vector &xvec)
Definition: lor_mms.hpp:32
Array< LinearFormIntegrator * > domain_integs
Set of Domain Integrators to be applied.
Definition: linearform.hpp:35
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:83
void AddBoundaryIntegrator(LinearFormIntegrator *lfi)
Adds new Boundary Integrator. Assumes ownership of lfi.
Definition: linearform.cpp:70
const FiniteElementSpace * FESpace() const
Read-only access to the associated FiniteElementSpace.
Definition: linearform.hpp:119
Array< DeltaLFIntegrator * > * GetDLFI_Delta()
Access all integrators added with AddDomainIntegrator() which are DeltaLFIntegrators with delta coeff...
Definition: linearform.hpp:160
Array< LinearFormIntegrator * > * GetIFLFI()
Access all integrators added with AddInteriorFaceIntegrator().
Definition: linearform.hpp:169
LinearForm()
Create an empty LinearForm without an associated FiniteElementSpace.
Definition: linearform.hpp:93
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:174
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
Definition: array.hpp:674
void AssembleDelta()
Assembles delta functions of the linear form.
Definition: linearform.cpp:282
Array< DeltaLFIntegrator * > domain_delta_integs
Separate array for integrators with delta function coefficients.
Definition: linearform.hpp:43
void Update()
Update the object according to the associated FE space fes.
Definition: linearform.hpp:187
Array< LinearFormIntegrator * > * GetBLFI()
Access all integrators added with AddBoundaryIntegrator().
Definition: linearform.hpp:163
~LinearForm()
Destroys linear form.
Definition: linearform.cpp:336
MFEM_DEPRECATED FiniteElementSpace * GetFES()
(DEPRECATED) Return the FE space associated with the LinearForm.
Definition: linearform.hpp:114
bool HaveDeltaLocations()
If true, the delta locations are not (re)computed during assembly.
Definition: linearform.hpp:64
Array< LinearFormIntegrator * > boundary_integs
Set of Boundary Integrators to be applied.
Definition: linearform.hpp:46
Vector data type.
Definition: vector.hpp:60
LinearForm(FiniteElementSpace *f, double *data)
Construct a LinearForm using previously allocated array data.
Definition: linearform.hpp:100
virtual bool UseDevice() const
Return the device flag of the Memory object used by the Vector.
Definition: vector.hpp:111
Vector with associated FE space and LinearFormIntegrators.
Definition: linearform.hpp:23
Array< Array< int > * > boundary_integs_marker
Entries are not owned.
Definition: linearform.hpp:48
Array< Array< int > * > domain_integs_marker
Definition: linearform.hpp:40
Array< LinearFormIntegrator * > * GetDLFI()
Access all integrators added with AddDomainIntegrator() which are not DeltaLFIntegrators or they are ...
Definition: linearform.hpp:156