MFEM  v4.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, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
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  /// Copy assignment. Only the data of the base class Vector is copied.
85  /** It is assumed that this object and @a rhs use FiniteElementSpace%s that
86  have the same size.
87 
88  @note Defining this method overwrites the implicitly defined copy
89  assignemnt operator. */
91  { return operator=((const Vector &)rhs); }
92 
93  /// (DEPRECATED) Return the FE space associated with the LinearForm.
94  /** @deprecated Use FESpace() instead. */
95  FiniteElementSpace *GetFES() { return fes; }
96 
97  /// Read+write access to the associated FiniteElementSpace.
99  /// Read-only access to the associated FiniteElementSpace.
100  const FiniteElementSpace *FESpace() const { return fes; }
101 
102  /// Adds new Domain Integrator. Assumes ownership of @a lfi.
104 
105  /// Adds new Boundary Integrator. Assumes ownership of @a lfi.
107 
108  /** @brief Add new Boundary Integrator, restricted to the given boundary
109  attributes.
110 
111  Assumes ownership of @a lfi. The array @a bdr_attr_marker is stored
112  internally as a pointer to the given Array<int> object. */
114  Array<int> &bdr_attr_marker);
115 
116  /// Adds new Boundary Face Integrator. Assumes ownership of @a lfi.
118 
119  /** @brief Add new Boundary Face Integrator, restricted to the given boundary
120  attributes.
121 
122  Assumes ownership of @a lfi. The array @a bdr_attr_marker is stored
123  internally as a pointer to the given Array<int> object. */
125  Array<int> &bdr_attr_marker);
126 
127  /** @brief Access all integrators added with AddDomainIntegrator() which are
128  not DeltaLFIntegrator%s or they are DeltaLFIntegrator%s with non-delta
129  coefficients. */
131 
132  /** @brief Access all integrators added with AddDomainIntegrator() which are
133  DeltaLFIntegrator%s with delta coefficients. */
135 
136  /// Access all integrators added with AddBoundaryIntegrator().
138 
139  /// Access all integrators added with AddBdrFaceIntegrator().
141 
142  /** @brief Access all boundary markers added with AddBdrFaceIntegrator().
143  If no marker was specified when the integrator was added, the
144  corresponding pointer (to Array<int>) will be NULL. */
146 
147  /// Assembles the linear form i.e. sums over all domain/bdr integrators.
148  void Assemble();
149 
150  /// Assembles delta functions of the linear form
151  void AssembleDelta();
152 
153  /// Update the object according to the associated FE space #fes.
154  /** This method should be called when the asscociated FE space #fes has been
155  updated, e.g. after its associated Mesh object has been refined.
156 
157  @note This method does not perform assembly. */
159 
160  /// Associate a new FE space, @a *f, with this object and Update() it. */
162  { fes = f; SetSize(f->GetVSize()); ResetDeltaLocations(); }
163 
164  /** @brief Associate a new FE space, @a *f, with this object and use the data
165  of @a v, offset by @a v_offset, to initialize this object's Vector::data.
166 
167  @note This method does not perform assembly. */
168  void Update(FiniteElementSpace *f, Vector &v, int v_offset);
169 
170  /// Return the action of the LinearForm as a linear mapping.
171  /** Linear forms are linear functionals which map GridFunctions to
172  the real numbers. This method performs this mapping which in
173  this case is equivalent as an inner product of the LinearForm
174  and GridFunction. */
175  double operator()(const GridFunction &gf) const { return (*this)*gf; }
176 
177  /// Redefine '=' for LinearForm = constant.
178  LinearForm &operator=(double value);
179 
180  /// Copy the data from @a v.
181  /** The size of @a v must be equal to the size of the associated
182  FiniteElementSpace #fes. */
183  LinearForm &operator=(const Vector &v);
184 
185  /// Destroys linear form.
186  ~LinearForm();
187 };
188 
189 }
190 
191 #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:118
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
Definition: fespace.hpp:347
Class for grid function - Vector with associated FE space.
Definition: gridfunc.hpp:27
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:400
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:90
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:175
FiniteElementSpace * FESpace()
Read+write access to the associated FiniteElementSpace.
Definition: linearform.hpp:98
Array< LinearFormIntegrator * > * GetFLFI()
Access all integrators added with AddBdrFaceIntegrator().
Definition: linearform.hpp:140
void Update(FiniteElementSpace *f)
Associate a new FE space, *f, with this object and Update() it. */.
Definition: linearform.hpp:161
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:100
Array< DeltaLFIntegrator * > * GetDLFI_Delta()
Access all integrators added with AddDomainIntegrator() which are DeltaLFIntegrators with delta coeff...
Definition: linearform.hpp:134
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:85
Array< Array< int > * > * GetFLFI_Marker()
Access all boundary markers added with AddBdrFaceIntegrator(). If no marker was specified when the in...
Definition: linearform.hpp:145
void SetSize(int nsize)
Change logical size of the array, keep existing entries.
Definition: array.hpp:618
void AssembleDelta()
Assembles delta functions of the linear form.
Definition: linearform.cpp:202
void Update()
Update the object according to the associated FE space fes.
Definition: linearform.hpp:158
Array< LinearFormIntegrator * > * GetBLFI()
Access all integrators added with AddBoundaryIntegrator().
Definition: linearform.hpp:137
~LinearForm()
Destroys linear form.
Definition: linearform.cpp:255
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
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:95
Array< LinearFormIntegrator * > * GetDLFI()
Access all integrators added with AddDomainIntegrator() which are not DeltaLFIntegrators or they are ...
Definition: linearform.hpp:130