MFEM  v3.3
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 {
62  X.Distribute(&x);
63 
65 
67 
68  Y.GetTrueDofs(y);
69 }
70 
72 {
73  X.Distribute(&x);
74 
75  NonlinearForm::GetGradient(X); // (re)assemble Grad with b.c.
76 
77  return *Grad;
78 }
79 
81 {
83 
84  pGrad.Clear();
85 
86  X.Distribute(&x);
87 
88  NonlinearForm::GetGradient(X); // (re)assemble Grad with b.c.
89 
90  OperatorHandle dA(pGrad.Type()), Ph(pGrad.Type());
91  dA.MakeSquareBlockDiag(pfes->GetComm(), pfes->GlobalVSize(),
92  pfes->GetDofOffsets(), Grad);
93  // TODO - construct Dof_TrueDof_Matrix directly in the pGrad format
94  Ph.ConvertFrom(pfes->Dof_TrueDof_Matrix());
95  pGrad.MakePtAP(dA, Ph);
96 
97  return *pGrad.Ptr();
98 }
99 
100 }
101 
102 #endif
int Size() const
Logical size of the array.
Definition: array.hpp:109
ParFiniteElementSpace * ParFESpace() const
Pointer to an Operator of a specified type.
Definition: handle.hpp:34
Operator::Type Type() const
Get the currently set operator type id.
Definition: handle.hpp:86
HYPRE_Int * GetDofOffsets()
Definition: pfespace.hpp:169
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
virtual void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
int GetLocalTDofNumber(int ldof)
Definition: pfespace.cpp:531
Array< int > ess_vdofs
Operator * Ptr() const
Access the underlying Operator pointer.
Definition: handle.hpp:83
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.
GroupCommunicator & GroupComm()
Return a reference to the internal GroupCommunicator (on VDofs)
Definition: pfespace.hpp:210
void Clear()
Clear the OperatorHandle, deleting the held Operator (if owned), while leaving the type id unchanged...
Definition: handle.hpp:111
void Distribute(const Vector *tv)
Definition: pgridfunc.cpp:92
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:48
virtual Operator & GetGradient(const Vector &x) const
Evaluate the gradient operator at the point x. The default behavior in class Operator is to generate ...
void Reduce(T *ldata, void(*Op)(OpData< T >))
Reduce within each group where the master is the root.
virtual void SetEssentialBC(const Array< int > &bdr_attr_is_ess, Vector *rhs=NULL)
Vector data type.
Definition: vector.hpp:36
SparseMatrix * Grad
virtual double GetEnergy(const Vector &x) const
Class for parallel grid function.
Definition: pgridfunc.hpp:31
Abstract operator.
Definition: operator.hpp:21
HypreParMatrix * Dof_TrueDof_Matrix()
The true dof-to-dof interpolation matrix.
Definition: pfespace.hpp:193
void MakePtAP(OperatorHandle &A, OperatorHandle &P)
Reset the OperatorHandle to hold the product P^t A P.
Definition: handle.cpp:98