MFEM  v4.6.0
Finite element discretization library
pnonlinearform.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2023, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-806117.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability visit https://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11 
12 #ifndef MFEM_PNONLINEARFORM
13 #define MFEM_PNONLINEARFORM
14 
15 #include "../config/config.hpp"
16 
17 #ifdef MFEM_USE_MPI
18 
19 #include "pgridfunc.hpp"
20 #include "nonlinearform.hpp"
21 
22 namespace mfem
23 {
24 
25 /// Parallel non-linear operator on the true dofs
27 {
28 protected:
29  mutable ParGridFunction X, Y;
31 
32 public:
34 
36  { return (ParFiniteElementSpace *)fes; }
37 
38  /// Compute the energy corresponding to the state @a x.
39  /** In general, @a x may have non-homogeneous essential boundary values.
40 
41  The state @a x must be a "GridFunction size" vector, i.e. its size must
42  be fes->GetVSize(). */
43  double GetParGridFunctionEnergy(const Vector &x) const;
44 
45  /// Compute the energy of a ParGridFunction
46  double GetEnergy(const ParGridFunction &x) const
47  { return GetParGridFunctionEnergy(x); }
48 
49  virtual double GetEnergy(const Vector &x) const
50  { return GetParGridFunctionEnergy(Prolongate(x)); }
51 
52  virtual void Mult(const Vector &x, Vector &y) const;
53 
54  /// Return the local gradient matrix for the given true-dof vector x.
55  /** The returned matrix does NOT have any boundary conditions imposed. */
56  const SparseMatrix &GetLocalGradient(const Vector &x) const;
57 
58  virtual Operator &GetGradient(const Vector &x) const;
59 
60  /// Set the operator type id for the parallel gradient matrix/operator.
62 
63  /** @brief Update the ParNonlinearForm to propagate updates of the associated
64  parallel FE space. */
65  /** After calling this method, the essential boundary conditions need to be
66  set again. */
67  virtual void Update();
68 
69  virtual ~ParNonlinearForm() { }
70 };
71 
72 
73 /** @brief A class representing a general parallel block nonlinear operator
74  defined on the Cartesian product of multiple ParFiniteElementSpace%s. */
75 /** The ParBlockNonlinearForm takes as input, and returns as output, vectors on
76  the true dofs. */
78 {
79 protected:
83 
84 public:
85  /// Computes the energy of the system
86  virtual double GetEnergy(const Vector &x) const;
87 
88  /// Construct an empty ParBlockNonlinearForm. Initialize with SetParSpaces().
90 
91  /** @brief Construct a ParBlockNonlinearForm on the given set of
92  ParFiniteElementSpace%s. */
94 
95  /// Return the @a k-th parallel FE space of the ParBlockNonlinearForm.
97  /** @brief Return the @a k-th parallel FE space of the ParBlockNonlinearForm
98  (const version). */
99  const ParFiniteElementSpace *ParFESpace(int k) const;
100 
101  /** @brief After a call to SetParSpaces(), the essential b.c. and the
102  gradient-type (if different from the default) must be set again. */
104 
105  // Here, rhs is a true dof vector
106  virtual void SetEssentialBC(const Array<Array<int> *>&bdr_attr_is_ess,
107  Array<Vector *> &rhs);
108 
109  /// Block T-Vector to Block T-Vector
110  virtual void Mult(const Vector &x, Vector &y) const;
111 
112  /// Return the local block gradient matrix for the given true-dof vector x
113  const BlockOperator &GetLocalGradient(const Vector &x) const;
114 
115  virtual BlockOperator &GetGradient(const Vector &x) const;
116 
117  /** @brief Set the operator type id for the blocks of the parallel gradient
118  matrix/operator. The default type is Operator::Hypre_ParCSR. */
120 
121  /// Destructor.
122  virtual ~ParBlockNonlinearForm();
123 };
124 
125 }
126 
127 #endif // MFEM_USE_MPI
128 
129 #endif
void SetGradientType(Operator::Type tid)
Set the operator type id for the parallel gradient matrix/operator.
const Vector & Prolongate(const Vector &x) const
A class to handle Vectors in a block fashion.
Definition: blockvector.hpp:30
Pointer to an Operator of a specified type.
Definition: handle.hpp:33
virtual void Mult(const Vector &x, Vector &y) const
Evaluate the action of the NonlinearForm.
Parallel non-linear operator on the true dofs.
A class representing a general block nonlinear operator defined on the Cartesian product of multiple ...
virtual void Update()
Update the ParNonlinearForm to propagate updates of the associated parallel FE space.
const BlockOperator & GetLocalGradient(const Vector &x) const
Return the local block gradient matrix for the given true-dof vector x.
virtual BlockOperator & GetGradient(const Vector &x) const
Abstract parallel finite element space.
Definition: pfespace.hpp:28
FiniteElementSpace * fes
FE space on which the form lives.
virtual double GetEnergy(const Vector &x) const
Compute the energy corresponding to the state x.
ParBlockNonlinearForm()
Construct an empty ParBlockNonlinearForm. Initialize with SetParSpaces().
void SetGradientType(Operator::Type tid)
Set the operator type id for the blocks of the parallel gradient matrix/operator. The default type is...
ParNonlinearForm(ParFiniteElementSpace *pf)
Data type sparse matrix.
Definition: sparsemat.hpp:50
virtual void SetEssentialBC(const Array< Array< int > *> &bdr_attr_is_ess, Array< Vector *> &rhs)
double GetParGridFunctionEnergy(const Vector &x) const
Compute the energy corresponding to the state x.
Dynamic 2D array using row-major layout.
Definition: array.hpp:354
Type
Enumeration defining IDs for some classes derived from Operator.
Definition: operator.hpp:283
const SparseMatrix & GetLocalGradient(const Vector &x) const
Return the local gradient matrix for the given true-dof vector x.
ParFiniteElementSpace * ParFESpace() const
virtual void Mult(const Vector &x, Vector &y) const
Block T-Vector to Block T-Vector.
A class representing a general parallel block nonlinear operator defined on the Cartesian product of ...
Array2D< OperatorHandle * > phBlockGrad
virtual double GetEnergy(const Vector &x) const
Computes the energy of the system.
Vector data type.
Definition: vector.hpp:58
virtual ~ParBlockNonlinearForm()
Destructor.
double GetEnergy(const ParGridFunction &x) const
Compute the energy of a ParGridFunction.
Class for parallel grid function.
Definition: pgridfunc.hpp:32
ParFiniteElementSpace * ParFESpace(int k)
Return the k-th parallel FE space of the ParBlockNonlinearForm.
Abstract operator.
Definition: operator.hpp:24
A class to handle Block systems in a matrix-free implementation.
void SetType(Operator::Type tid)
Invoke Clear() and set a new type id.
Definition: handle.hpp:132
virtual Operator & GetGradient(const Vector &x) const
Compute the gradient Operator of the NonlinearForm corresponding to the state x.
void SetParSpaces(Array< ParFiniteElementSpace *> &pf)
After a call to SetParSpaces(), the essential b.c. and the gradient-type (if different from the defau...