MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
pnonlinearform.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, 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
22namespace mfem
23{
24
25/// Parallel non-linear operator on the true dofs
27{
28protected:
31
32 void GradientSharedFaces(const Vector &x, int skip_zeros = 1) const;
33
34public:
36
39
40 /// Compute the energy corresponding to the state @a x.
41 /** In general, @a x may have non-homogeneous essential boundary values.
42
43 The state @a x must be a "GridFunction size" vector, i.e. its size must
44 be fes->GetVSize(). */
46
47 /// Compute the energy of a ParGridFunction
49 { return GetParGridFunctionEnergy(x); }
50
51 real_t GetEnergy(const Vector &x) const override
53
54 void Mult(const Vector &x, Vector &y) const override;
55
56 /// Return the local gradient matrix for the given true-dof vector x.
57 /** The returned matrix does NOT have any boundary conditions imposed. */
58 const SparseMatrix &GetLocalGradient(const Vector &x) const;
59
60 Operator &GetGradient(const Vector &x) const override;
61
62 /// Set the operator type id for the parallel gradient matrix/operator.
64
65 /** @brief Update the ParNonlinearForm to propagate updates of the associated
66 parallel FE space. */
67 /** After calling this method, the essential boundary conditions need to be
68 set again. */
69 void Update() override;
70
71 virtual ~ParNonlinearForm() { }
72};
73
74
75/** @brief A class representing a general parallel block nonlinear operator
76 defined on the Cartesian product of multiple ParFiniteElementSpace%s. */
77/** The ParBlockNonlinearForm takes as input, and returns as output, vectors on
78 the true dofs. */
80{
81protected:
85
86 void GradientSharedFaces(const BlockVector &xs, int skip_zeros) const;
87
88public:
89 /// Computes the energy of the system
90 real_t GetEnergy(const Vector &x) const override;
91
92 /// Construct an empty ParBlockNonlinearForm. Initialize with SetParSpaces().
94
95 /** @brief Construct a ParBlockNonlinearForm on the given set of
96 ParFiniteElementSpace%s. */
98
99 /// Return the @a k-th parallel FE space of the ParBlockNonlinearForm.
101 /** @brief Return the @a k-th parallel FE space of the ParBlockNonlinearForm
102 (const version). */
103 const ParFiniteElementSpace *ParFESpace(int k) const;
104
105 /** @brief After a call to SetParSpaces(), the essential b.c. and the
106 gradient-type (if different from the default) must be set again. */
108
109 /** @brief Set essential boundary conditions to each finite element space
110 using boundary attribute markers.
111
112 This method calls `FiniteElementSpace::GetEssentialTrueDofs()` for each
113 space and stores ess_tdof_lists internally.
114
115 If `rhs` vectors are non-null, the entries corresponding to these
116 essential DoFs are set to zero. This ensures compatibility with the
117 output of the `Mult()` method, which also zeroes out these entries.
118
119 @param[in] bdr_attr_is_ess A list of boundary attribute markers for each
120 space.
121 @param[in,out] rhs An array of optional right-hand side vectors.
122 If a vector at `rhs[i]` is non-null, its essential DoFs will be set
123 to zero. */
124 virtual void SetEssentialBC(const Array<Array<int>*> &bdr_attr_is_ess,
125 Array<Vector*> &rhs) override;
126
127 /** @brief Set essential boundary conditions to each finite element space
128 using essential true dof lists.
129
130 This method stores a copy of the provided essential true dof lists.
131
132 If `rhs` vectors are non-null, the entries corresponding to these
133 essential DoFs are set to zero. This ensures compatibility with the
134 output of the `Mult()` method, which also zeroes out these entries.
135
136 @param[in] ess_tdof_list A list of essential true dofs for each space.
137 @param[in,out] rhs An array of optional right-hand side vectors.
138 If a vector at `rhs[i]` is non-null, its essential DoFs will be set
139 to zero. */
140 virtual void SetEssentialTrueDofs(const Array<Array<int>*> &ess_tdof_list,
141 Array<Vector*> &rhs) override;
142
143 /// Block T-Vector to Block T-Vector
144 void Mult(const Vector &x, Vector &y) const override;
145
146 /// Return the local block gradient matrix for the given true-dof vector x
147 const BlockOperator &GetLocalGradient(const Vector &x) const;
148
149 BlockOperator &GetGradient(const Vector &x) const override;
150
151 /** @brief Set the operator type id for the blocks of the parallel gradient
152 matrix/operator. The default type is Operator::Hypre_ParCSR. */
154
155 /// Destructor.
156 virtual ~ParBlockNonlinearForm();
157};
158
159}
160
161#endif // MFEM_USE_MPI
162
163#endif
Dynamic 2D array using row-major layout.
Definition array.hpp:430
A class representing a general block nonlinear operator defined on the Cartesian product of multiple ...
A class to handle Block systems in a matrix-free implementation.
A class to handle Vectors in a block fashion.
FiniteElementSpace * fes
FE space on which the form lives.
const Vector & Prolongate(const Vector &x) const
Pointer to an Operator of a specified type.
Definition handle.hpp:34
void SetType(Operator::Type tid)
Invoke Clear() and set a new type id.
Definition handle.hpp:132
Abstract operator.
Definition operator.hpp:25
Type
Enumeration defining IDs for some classes derived from Operator.
Definition operator.hpp:296
A class representing a general parallel block nonlinear operator defined on the Cartesian product of ...
const BlockOperator & GetLocalGradient(const Vector &x) const
Return the local block gradient matrix for the given true-dof vector x.
void Mult(const Vector &x, Vector &y) const override
Block T-Vector to Block T-Vector.
virtual void SetEssentialTrueDofs(const Array< Array< int > * > &ess_tdof_list, Array< Vector * > &rhs) override
Set essential boundary conditions to each finite element space using essential true dof lists.
Array2D< OperatorHandle * > phBlockGrad
void GradientSharedFaces(const BlockVector &xs, int skip_zeros) const
ParFiniteElementSpace * ParFESpace(int k)
Return the k-th parallel FE space of the ParBlockNonlinearForm.
ParBlockNonlinearForm()
Construct an empty ParBlockNonlinearForm. Initialize with SetParSpaces().
real_t GetEnergy(const Vector &x) const override
Computes the energy of the system.
virtual ~ParBlockNonlinearForm()
Destructor.
void SetParSpaces(Array< ParFiniteElementSpace * > &pf)
After a call to SetParSpaces(), the essential b.c. and the gradient-type (if different from the defau...
BlockOperator & GetGradient(const Vector &x) const override
virtual void SetEssentialBC(const Array< Array< int > * > &bdr_attr_is_ess, Array< Vector * > &rhs) override
Set essential boundary conditions to each finite element space using boundary attribute markers.
void SetGradientType(Operator::Type tid)
Set the operator type id for the blocks of the parallel gradient matrix/operator. The default type is...
Abstract parallel finite element space.
Definition pfespace.hpp:31
Class for parallel grid function.
Definition pgridfunc.hpp:50
Parallel non-linear operator on the true dofs.
const SparseMatrix & GetLocalGradient(const Vector &x) const
Return the local gradient matrix for the given true-dof vector x.
ParNonlinearForm(ParFiniteElementSpace *pf)
real_t GetEnergy(const Vector &x) const override
Compute the energy corresponding to the state x.
void SetGradientType(Operator::Type tid)
Set the operator type id for the parallel gradient matrix/operator.
real_t GetParGridFunctionEnergy(const Vector &x) const
Compute the energy corresponding to the state x.
Operator & GetGradient(const Vector &x) const override
Compute the gradient Operator of the NonlinearForm corresponding to the state x.
real_t GetEnergy(const ParGridFunction &x) const
Compute the energy of a ParGridFunction.
ParFiniteElementSpace * ParFESpace() const
void GradientSharedFaces(const Vector &x, int skip_zeros=1) const
void Update() override
Update the ParNonlinearForm to propagate updates of the associated parallel FE space.
void Mult(const Vector &x, Vector &y) const override
Evaluate the action of the NonlinearForm.
Data type sparse matrix.
Definition sparsemat.hpp:51
Vector data type.
Definition vector.hpp:82
float real_t
Definition config.hpp:46