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