MFEM  v3.0
 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.googlecode.com.
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  (*rhs)(tdof) = 0.0;
35  }
36 }
37 
39 {
40  double loc_energy, glob_energy;
41 
42  loc_energy = NonlinearForm::GetEnergy(x);
43 
44  MPI_Allreduce(&loc_energy, &glob_energy, 1, MPI_DOUBLE, MPI_SUM,
45  ParFESpace()->GetComm());
46 
47  return glob_energy;
48 }
49 
50 double ParNonlinearForm::GetEnergy(const Vector &x) const
51 {
52  X.Distribute(&x);
53  return GetEnergy(X);
54 }
55 
56 void ParNonlinearForm::Mult(const Vector &x, Vector &y) const
57 {
58  X.Distribute(&x);
59 
61 
63 
64  Y.GetTrueDofs(y);
65 }
66 
68 {
69  X.Distribute(&x);
70 
71  NonlinearForm::GetGradient(X); // (re)assemble Grad
72 
73  return *Grad;
74 }
75 
77 {
79 
80  delete pGrad;
81 
82  X.Distribute(&x);
83 
84  NonlinearForm::GetGradient(X); // (re)assemble Grad
85 
86  // construct a parallel block-diagonal wrapper matrix A based on Grad
87  HypreParMatrix *A =
88  new HypreParMatrix(pfes->GetComm(),
89  pfes->GlobalVSize(), pfes->GetDofOffsets(), Grad);
90 
91  pGrad = RAP(A, pfes->Dof_TrueDof_Matrix());
92 
93  delete A;
94 
95  return *pGrad;
96 }
97 
98 }
99 
100 #endif
int Size() const
Logical size of the array.
Definition: array.hpp:108
ParFiniteElementSpace * ParFESpace() const
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:781
virtual void Mult(const Vector &x, Vector &y) const
Operator application.
int GetLocalTDofNumber(int ldof)
Definition: pfespace.cpp:440
Array< int > ess_vdofs
HypreParMatrix * Dof_TrueDof_Matrix()
The true dof-to-dof interpolation matrix.
Definition: pfespace.cpp:303
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:134
void Distribute(const Vector *tv)
Definition: pgridfunc.cpp:78
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:29
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:103