MFEM  v3.3.2
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
pnonlinearform.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 #include "../config/config.hpp"
13 
14 #ifdef MFEM_USE_MPI
15 
16 #include "fem.hpp"
17 
18 namespace mfem
19 {
20 
21 void ParNonlinearForm::SetEssentialBC(const Array<int> &bdr_attr_is_ess,
22  Vector *rhs)
23 {
25 
26  NonlinearForm::SetEssentialBC(bdr_attr_is_ess);
27 
28  // ess_vdofs is a list of local vdofs
29  if (rhs)
30  {
31  for (int i = 0; i < ess_vdofs.Size(); i++)
32  {
33  int tdof = pfes->GetLocalTDofNumber(ess_vdofs[i]);
34  if (tdof >= 0)
35  {
36  (*rhs)(tdof) = 0.0;
37  }
38  }
39  }
40 }
41 
43 {
44  double loc_energy, glob_energy;
45 
46  loc_energy = NonlinearForm::GetEnergy(x);
47 
48  MPI_Allreduce(&loc_energy, &glob_energy, 1, MPI_DOUBLE, MPI_SUM,
49  ParFESpace()->GetComm());
50 
51  return glob_energy;
52 }
53 
54 double ParNonlinearForm::GetEnergy(const Vector &x) const
55 {
56  X.Distribute(&x);
57  return GetEnergy(X);
58 }
59 
60 void ParNonlinearForm::Mult(const Vector &x, Vector &y) const
61 {
63 
64  P->Mult(x, X);
65 
67 
68  if (fnfi.Size())
69  {
70  // Terms over shared interior faces in parallel.
72  ParMesh *pmesh = pfes->GetParMesh();
74  const FiniteElement *fe1, *fe2;
75  Array<int> vdofs1, vdofs2;
76  Vector el_x, el_y;
77 
79  const int n_shared_faces = pmesh->GetNSharedFaces();
80  for (int i = 0; i < n_shared_faces; i++)
81  {
82  tr = pmesh->GetSharedFaceTransformations(i, true);
83 
84  fe1 = pfes->GetFE(tr->Elem1No);
85  fe2 = pfes->GetFaceNbrFE(tr->Elem2No);
86 
87  pfes->GetElementVDofs(tr->Elem1No, vdofs1);
88  pfes->GetFaceNbrElementVDofs(tr->Elem2No, vdofs2);
89 
90  el_x.SetSize(vdofs1.Size() + vdofs2.Size());
91  X.GetSubVector(vdofs1, el_x.GetData());
92  X.FaceNbrData().GetSubVector(vdofs2, el_x.GetData() + vdofs1.Size());
93 
94  for (int k = 0; k < fnfi.Size(); k++)
95  {
96  fnfi[k]->AssembleFaceVector(*fe1, *fe2, *tr, el_x, el_y);
97  Y.AddElementVector(vdofs1, el_y.GetData());
98  }
99  }
100  }
101 
102  P->MultTranspose(Y, y);
103 }
104 
106 {
107  X.Distribute(&x);
108 
109  NonlinearForm::GetGradient(X); // (re)assemble Grad with b.c.
110 
111  return *Grad;
112 }
113 
115 {
117 
118  pGrad.Clear();
119 
120  X.Distribute(&x);
121 
122  NonlinearForm::GetGradient(X); // (re)assemble Grad with b.c.
123 
124  OperatorHandle dA(pGrad.Type()), Ph(pGrad.Type());
125 
126  if (fnfi.Size() == 0)
127  {
128  dA.MakeSquareBlockDiag(pfes->GetComm(), pfes->GlobalVSize(),
129  pfes->GetDofOffsets(), Grad);
130  }
131  else
132  {
133  MFEM_ABORT("TODO: assemble contributions from shared face terms");
134  }
135 
136  // TODO - construct Dof_TrueDof_Matrix directly in the pGrad format
137  Ph.ConvertFrom(pfes->Dof_TrueDof_Matrix());
138  pGrad.MakePtAP(dA, Ph);
139 
140  return *pGrad.Ptr();
141 }
142 
143 }
144 
145 #endif
Abstract class for Finite Elements.
Definition: fe.hpp:47
virtual const Operator * GetProlongationMatrix()
Definition: pfespace.cpp:632
int Size() const
Logical size of the array.
Definition: array.hpp:110
ParFiniteElementSpace * ParFESpace() const
HYPRE_Int * GetDofOffsets() const
Definition: pfespace.hpp:174
void SetSize(int s)
Resize the vector to size s.
Definition: vector.hpp:320
void GetElementVDofs(int i, Array< int > &vdofs) const
Returns indexes of degrees of freedom in array dofs for i&#39;th element.
Definition: fespace.cpp:133
int GetNSharedFaces() const
Return the number of shared faces (3D), edges (2D), vertices (1D)
Definition: pmesh.cpp:2009
Pointer to an Operator of a specified type.
Definition: handle.hpp:33
Operator::Type Type() const
Get the currently set operator type id.
Definition: handle.hpp:85
void GetSubVector(const Array< int > &dofs, Vector &elemvect) const
Definition: vector.cpp:462
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application: y=A(x).
Abstract parallel finite element space.
Definition: pfespace.hpp:31
int GetLocalTDofNumber(int ldof) const
Definition: pfespace.cpp:541
double * GetData() const
Definition: vector.hpp:121
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:52
void GetFaceNbrElementVDofs(int i, Array< int > &vdofs) const
Definition: pfespace.cpp:865
virtual double GetEnergy(const ParGridFunction &x) const
Compute the energy of a ParGridFunction.
const FiniteElement * GetFaceNbrFE(int i) const
Definition: pfespace.cpp:899
MPI_Comm GetComm() const
Definition: pfespace.hpp:166
Data type sparse matrix.
Definition: sparsemat.hpp:38
Array< NonlinearFormIntegrator * > fnfi
Set of interior face Integrators to be assembled (added).
FaceElementTransformations * GetSharedFaceTransformations(int sf, bool fill2=true)
Definition: pmesh.cpp:1924
HypreParMatrix * Dof_TrueDof_Matrix() const
The true dof-to-dof interpolation matrix.
Definition: pfespace.hpp:198
virtual void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
Array< int > ess_vdofs
void AddElementVector(const Array< int > &dofs, const Vector &elemvect)
Add (element) subvector to the vector.
Definition: vector.cpp:550
Operator * Ptr() const
Access the underlying Operator pointer.
Definition: handle.hpp:82
HYPRE_Int GlobalVSize() const
Definition: pfespace.hpp:176
Vector & FaceNbrData()
Definition: pgridfunc.hpp:169
virtual void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
const SparseMatrix & GetLocalGradient(const Vector &x) const
Return the local gradient matrix for the given true-dof vector x.
void Clear()
Clear the OperatorHandle, deleting the held Operator (if owned), while leaving the type id unchanged...
Definition: handle.hpp:110
void Distribute(const Vector *tv)
Definition: pgridfunc.cpp:116
virtual Operator & GetGradient(const Vector &x) const
Evaluate the gradient operator at the point x. The default behavior in class Operator is to generate ...
virtual void SetEssentialBC(const Array< int > &bdr_attr_is_ess, Vector *rhs=NULL)
void MakeSquareBlockDiag(MPI_Comm comm, HYPRE_Int glob_size, HYPRE_Int *row_starts, SparseMatrix *diag)
Reset the OperatorHandle to hold a parallel square block-diagonal matrix using the currently set type...
Definition: handle.cpp:59
virtual Operator & GetGradient(const Vector &x) const
Evaluate the gradient operator at the point x. The default behavior in class Operator is to generate ...
const FiniteElement * GetFE(int i) const
Returns pointer to the FiniteElement associated with i&#39;th element.
Definition: fespace.cpp:1171
virtual void SetEssentialBC(const Array< int > &bdr_attr_is_ess, Vector *rhs=NULL)
Vector data type.
Definition: vector.hpp:41
SparseMatrix * Grad
virtual double GetEnergy(const Vector &x) const
Class for parallel grid function.
Definition: pgridfunc.hpp:32
Abstract operator.
Definition: operator.hpp:21
Class for parallel meshes.
Definition: pmesh.hpp:29
void MakePtAP(OperatorHandle &A, OperatorHandle &P)
Reset the OperatorHandle to hold the product P^t A P.
Definition: handle.cpp:109