MFEM  v3.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  for (int i = 0; i < ess_vdofs.Size(); i++)
31  {
32  int tdof = pfes->GetLocalTDofNumber(ess_vdofs[i]);
33  if (tdof >= 0)
34  {
35  (*rhs)(tdof) = 0.0;
36  }
37  }
38 }
39 
41 {
42  double loc_energy, glob_energy;
43 
44  loc_energy = NonlinearForm::GetEnergy(x);
45 
46  MPI_Allreduce(&loc_energy, &glob_energy, 1, MPI_DOUBLE, MPI_SUM,
47  ParFESpace()->GetComm());
48 
49  return glob_energy;
50 }
51 
52 double ParNonlinearForm::GetEnergy(const Vector &x) const
53 {
54  X.Distribute(&x);
55  return GetEnergy(X);
56 }
57 
58 void ParNonlinearForm::Mult(const Vector &x, Vector &y) const
59 {
60  X.Distribute(&x);
61 
63 
65 
66  Y.GetTrueDofs(y);
67 }
68 
70 {
71  X.Distribute(&x);
72 
73  NonlinearForm::GetGradient(X); // (re)assemble Grad
74 
75  return *Grad;
76 }
77 
79 {
81 
82  delete pGrad;
83 
84  X.Distribute(&x);
85 
86  NonlinearForm::GetGradient(X); // (re)assemble Grad
87 
88  // construct a parallel block-diagonal wrapper matrix A based on Grad
89  HypreParMatrix *A =
90  new HypreParMatrix(pfes->GetComm(),
91  pfes->GlobalVSize(), pfes->GetDofOffsets(), Grad);
92 
93  pGrad = RAP(A, pfes->Dof_TrueDof_Matrix());
94 
95  delete A;
96 
97  return *pGrad;
98 }
99 
100 }
101 
102 #endif
int Size() const
Logical size of the array.
Definition: array.hpp:109
ParFiniteElementSpace * ParFESpace() const
HYPRE_Int * GetDofOffsets()
Definition: pfespace.hpp:166
Abstract parallel finite element space.
Definition: pfespace.hpp:28
virtual double GetEnergy(const ParGridFunction &x) const
Compute the energy of a ParGridFunction.
static void Sum(OpData< T >)
Reduce operation Sum, instantiated for int and double.
Data type sparse matrix.
Definition: sparsemat.hpp:38
HypreParMatrix * pGrad
HypreParMatrix * RAP(HypreParMatrix *A, HypreParMatrix *P)
Returns the matrix P^t * A * P.
Definition: hypre.cpp:1365
virtual void Mult(const Vector &x, Vector &y) const
Operator application.
int GetLocalTDofNumber(int ldof)
Definition: pfespace.cpp:489
Array< int > ess_vdofs
HypreParMatrix * Dof_TrueDof_Matrix()
The true dof-to-dof interpolation matrix.
Definition: pfespace.cpp:345
virtual void Mult(const Vector &x, Vector &y) const
Operator application.
const SparseMatrix & GetLocalGradient(const Vector &x) const
Return the local gradient matrix for the given true-dof vector x.
GroupCommunicator & GroupComm()
Return a reference to the internal GroupCommunicator (on VDofs)
Definition: pfespace.hpp:203
void Distribute(const Vector *tv)
Definition: pgridfunc.cpp:85
virtual Operator & GetGradient(const Vector &x) const
Evaluate the gradient operator at the point x.
virtual void SetEssentialBC(const Array< int > &bdr_attr_is_ess, Vector *rhs=NULL)
virtual Operator & GetGradient(const Vector &x) const
Evaluate the gradient operator at the point x.
void Reduce(T *ldata, void(*Op)(OpData< T >))
virtual void SetEssentialBC(const Array< int > &bdr_attr_is_ess, Vector *rhs=NULL)
Vector data type.
Definition: vector.hpp:33
SparseMatrix * Grad
virtual double GetEnergy(const Vector &x) const
Class for parallel grid function.
Definition: pgridfunc.hpp:31
Abstract operator.
Definition: operator.hpp:21
Wrapper for hypre&#39;s ParCSR matrix class.
Definition: hypre.hpp:150