MFEM  v4.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
bilinearform_ext.cpp
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 // Implementations of classes FABilinearFormExtension, EABilinearFormExtension,
13 // PABilinearFormExtension and MFBilinearFormExtension.
14 
15 #include "../general/forall.hpp"
16 #include "bilinearform.hpp"
17 
18 namespace mfem
19 {
20 
22  : Operator(form->Size()), a(form)
23 {
24  // empty
25 }
26 
28 {
29  return a->GetProlongation();
30 }
31 
33 {
34  return a->GetRestriction();
35 }
36 
37 
38 // Data and methods for partially-assembled bilinear forms
40  : BilinearFormExtension(form),
41  trialFes(a->FESpace()), testFes(a->FESpace())
42 {
46  {
49  localY.UseDevice(true); // ensure 'localY = 0.0' is done on device
50  }
51 }
52 
54 {
55  Array<BilinearFormIntegrator*> &integrators = *a->GetDBFI();
56  const int integratorCount = integrators.Size();
57  for (int i = 0; i < integratorCount; ++i)
58  {
59  integrators[i]->AssemblePA(*a->FESpace());
60  }
61 }
62 
64 {
65  FiniteElementSpace *fes = a->FESpace();
66  height = width = fes->GetVSize();
67  trialFes = fes;
68  testFes = fes;
72  {
75  }
76 }
77 
79  OperatorHandle &A)
80 {
81  const Operator* trialP = trialFes->GetProlongationMatrix();
82  const Operator* testP = testFes->GetProlongationMatrix();
83  Operator *rap = this;
84  if (trialP) { rap = new RAPOperator(*testP, *this, *trialP); }
85  const bool own_A = (rap!=this);
86  A.Reset(new ConstrainedOperator(rap, ess_tdof_list, own_A));
87 }
88 
90  Vector &x, Vector &b,
91  OperatorHandle &A,
92  Vector &X, Vector &B,
93  int copy_interior)
94 {
95  Operator *oper;
96  Operator::FormLinearSystem(ess_tdof_list, x, b, oper, X, B, copy_interior);
97  A.Reset(oper); // A will own oper
98 }
99 
101 {
102  Array<BilinearFormIntegrator*> &integrators = *a->GetDBFI();
103 
104  const int iSz = integrators.Size();
105  if (elem_restrict_lex)
106  {
108  localY = 0.0;
109  for (int i = 0; i < iSz; ++i)
110  {
111  integrators[i]->AddMultPA(localX, localY);
112  }
114  }
115  else
116  {
117  y.UseDevice(true); // typically this is a large vector, so store on device
118  y = 0.0;
119  for (int i = 0; i < iSz; ++i)
120  {
121  integrators[i]->AddMultPA(x, y);
122  }
123  }
124 }
125 
127 {
128  Array<BilinearFormIntegrator*> &integrators = *a->GetDBFI();
129  const int iSz = integrators.Size();
130  if (elem_restrict_lex)
131  {
133  localY = 0.0;
134  for (int i = 0; i < iSz; ++i)
135  {
136  integrators[i]->AddMultTransposePA(localX, localY);
137  }
139  }
140  else
141  {
142  y.UseDevice(true);
143  y = 0.0;
144  for (int i = 0; i < iSz; ++i)
145  {
146  integrators[i]->AddMultTransposePA(x, y);
147  }
148  }
149 }
150 
151 } // namespace mfem
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
void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
FiniteElementSpace * FESpace()
Return the FE space associated with the BilinearForm.
Array< BilinearFormIntegrator * > * GetDBFI()
Access all integrators added with AddDomainIntegrator().
void SetSize(int s)
Resize the vector to size s.
Definition: vector.hpp:400
Pointer to an Operator of a specified type.
Definition: handle.hpp:33
void UseDevice(bool use_dev) const
Enable execution of Vector operations using the mfem::Device.
Definition: vector.hpp:86
virtual const Operator * GetRestriction() const
Get the finite element space restriction matrix.
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application: y=A(x).
virtual const Operator * GetProlongation() const
Get the finite element space prolongation matrix.
BilinearFormExtension(BilinearForm *form)
virtual void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
Definition: operator.hpp:63
const Operator * GetElementRestriction(ElementDofOrdering e_ordering) const
Return an Operator that converts L-vectors to E-vectors.
Definition: fespace.cpp:789
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
Definition: operator.hpp:36
const FiniteElementSpace * trialFes
static MemoryType GetMemoryType()
Get the current Device MemoryType. This is the MemoryType used by most MFEM classes when allocating m...
Definition: device.hpp:210
BilinearForm * a
Not owned.
virtual const Operator * GetProlongationMatrix() const
The returned Operator is owned by the FiniteElementSpace.
Definition: fespace.hpp:288
The operator x -&gt; R*A*P*x constructed through the actions of R^T, A and P.
Definition: operator.hpp:363
Class extending the BilinearForm class to support the different AssemblyLevels.
virtual const Operator * GetProlongation() const
Get the finite element space prolongation matrix.
virtual const Operator * GetRestriction() const
Get the finite element space restriction matrix.
void FormLinearSystem(const Array< int > &ess_tdof_list, Vector &x, Vector &b, OperatorHandle &A, Vector &X, Vector &B, int copy_interior=0)
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition: fespace.hpp:85
void FormLinearSystem(const Array< int > &ess_tdof_list, Vector &x, Vector &b, Operator *&A, Vector &X, Vector &B, int copy_interior=0)
Form a constrained linear system using a matrix-free approach.
Definition: operator.cpp:23
int height
Dimension of the output / number of rows in the matrix.
Definition: operator.hpp:24
Lexicographic ordering for tensor-product FiniteElements.
void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
Vector data type.
Definition: vector.hpp:48
const FiniteElementSpace * testFes
Square Operator for imposing essential boundary conditions using only the action, Mult()...
Definition: operator.hpp:421
Abstract operator.
Definition: operator.hpp:21
void FormSystemMatrix(const Array< int > &ess_tdof_list, OperatorHandle &A)
int width
Dimension of the input / number of columns in the matrix.
Definition: operator.hpp:25
void Reset(OpType *A, bool own_A=true)
Reset the OperatorHandle to the given OpType pointer, A.
Definition: handle.hpp:137