MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
paramnonlinearform.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2024, 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_PRMNONLINEARFORM
13#define MFEM_PRMNONLINEARFORM
14
15#include "mfem.hpp"
16
17namespace mfem
18{
19
20/** The abstract base class ParametricBNLFormIntegrator is a generalization of
21 the BlockNonlinearFormIntegrator class suitable for block state and
22 parameter vectors. */
24{
25public:
26 /// Compute the local energy
30 const Array<const Vector *>&elfun,
31 const Array<const Vector *>&pelfun);
32
33 /// Perform the local action of the BlockNonlinearFormIntegrator
37 const Array<const Vector *> &elfun,
38 const Array<const Vector *>&pelfun,
39 const Array<Vector *> &elvec);
40
41 /// Perform the local action of the BlockNonlinearFormIntegrator on element
42 /// faces
48 const Array<const Vector *> &elfun,
49 const Array<const Vector *>&pelfun,
50 const Array<Vector *> &elvect);
51
52 /// Perform the local action on the parameters of the BNLFormIntegrator
56 const Array<const Vector *> &elfun,
57 const Array<const Vector *> &alfun,
58 const Array<const Vector *>&pelfun,
59 const Array<Vector *> &pelvec);
60
61 /// Perform the local action on the parameters of the BNLFormIntegrator on
62 /// faces
68 const Array<const Vector *> &elfun,
69 const Array<const Vector *> &alfun,
70 const Array<const Vector *>&pelfun,
71 const Array<Vector *> &pelvect);
72
73 /// Assemble the local gradient matrix
77 const Array<const Vector *> &elfun,
78 const Array<const Vector *>&pelfun,
79 const Array2D<DenseMatrix *> &elmats);
80
81 /// Assemble the local gradient matrix on faces of the elements
87 const Array<const Vector *> &elfun,
88 const Array<const Vector *>&pelfun,
89 const Array2D<DenseMatrix *> &elmats);
90
91
93};
94
95
96/** @brief A class representing a general parametric block nonlinear operator
97 defined on the Cartesian product of multiple FiniteElementSpace%s. */
99{
100protected:
101 /// FE spaces on which the form lives.
103
104 /// FE spaces for the parametric fields
106
109
110 /// Set of Domain Integrators to be assembled (added).
112
113 /// Set of interior face Integrators to be assembled (added).
115
116 /// Set of Boundary Face Integrators to be assembled (added).
119
120 /** Auxiliary block-vectors for wrapping input and output vectors or holding
121 GridFunction-like block-vector data (e.g. in parallel). */
122 mutable BlockVector xs, ys;
124
125 /** Auxiliary block-vectors for holding GridFunction-like block-vector data
126 (e.g. in parallel). */
128
129 /** Auxiliary block-vectors for holding GridFunction-like block-vector data
130 for the parameter fields (e.g. in parallel). */
132 /** Auxiliary block-vectors for holding GridFunction-like block-vector data
133 for the adjoint fields (e.g. in parallel). */
135
138
139 // A list of the offsets
142 // A list with the offsets for the parametric fields
145
146 // Array of Arrays of tdofs for each space in 'fes'
148
149 // Array of Arrays of tdofs for each space in 'paramfes'
151
152 /// Array of pointers to the prolongation matrix of fes, may be NULL
154
155 /// Array of pointers to the prolongation matrix of paramfes, may be NULL
157
158 /// Array of results of dynamic-casting P to SparseMatrix pointer
160
161 /// Array of results of dynamic-casting Pparam to SparseMatrix pointer
163
164 /// Indicator if the Operator is part of a parallel run
165 bool is_serial = true;
166
167 /// Indicator if the Operator needs prolongation on assembly
168 bool needs_prolongation = false;
169
170 /// Indicator if the Operator needs prolongation on assembly
172
174
176
177 const BlockVector &Prolongate(const BlockVector &bx) const;
178
179 const BlockVector &ParamProlongate(const BlockVector &bx) const;
180
181 real_t GetEnergyBlocked(const BlockVector &bx, const BlockVector &dx) const;
182
183
184 /// Specialized version of Mult() for BlockVector%s
185 /// Block L-Vector to Block L-Vector
186 void MultBlocked(const BlockVector &bx, const BlockVector &dx,
187 BlockVector &by) const;
188
189 /// Specialized version of Mult() for BlockVector%s
190 /// Block L-Vector to Block L-Vector
191 /// bx - state vector, ax - adjoint vector, dx - parametric fields
192 /// dy = ax' d(residual(bx))/d(dx)
193 void MultParamBlocked(const BlockVector &bx, const BlockVector & ax,
194 const BlockVector &dx, BlockVector &dy) const;
195
196
197 /// Specialized version of GetGradient() for BlockVector
198 void ComputeGradientBlocked(const BlockVector &bx, const BlockVector &dx) const;
199
200public:
201 /// Construct an empty BlockNonlinearForm. Initialize with SetSpaces().
203
204 /// Construct a BlockNonlinearForm on the given set of FiniteElementSpace%s.
207
208 /// Return the @a k-th FE space of the ParametricBNLForm.
209 FiniteElementSpace *FESpace(int k) { return fes[k]; }
210
211 /// Return the @a k-th parametric FE space of the ParametricBNLForm.
213
214
215 /// Return the @a k-th FE space of the BlockNonlinearForm (const version).
216 const FiniteElementSpace *FESpace(int k) const { return fes[k]; }
217
218 /// Return the @a k-th parametric FE space of the BlockNonlinearForm (const
219 /// version).
220 const FiniteElementSpace *ParamFESpace(int k) const { return paramfes[k]; }
221
222 /// Return the integrators
224
225
226 /// (Re)initialize the ParametricBNLForm.
227 /** After a call to SetSpaces(), the essential b.c. must be set again. */
230
231 /// Return the regular dof offsets.
232 const Array<int> &GetBlockOffsets() const { return block_offsets; }
233
234 /// Return the true-dof offsets.
236
237 /// Return the regular dof offsets for the parameters.
239
240 /// Return the true-dof offsets for the parameters.
242
243 /// Adds new Domain Integrator.
245 { dnfi.Append(nlfi); }
246
247 /// Adds new Interior Face Integrator.
250
251 /// Adds new Boundary Face Integrator.
253 { bfnfi.Append(nlfi); bfnfi_marker.Append(NULL); }
254
255 /** @brief Adds new Boundary Face Integrator, restricted to specific boundary
256 attributes. */
258 Array<int> &bdr_marker);
259
260 /// Set the essential boundary conditions.
261 virtual void SetEssentialBC(const Array<Array<int> *>&bdr_attr_is_ess,
262 Array<Vector *> &rhs);
263
264 /// Set the essential boundary conditions on the parametric fields.
265 virtual void SetParamEssentialBC(const Array<Array<int> *>&bdr_attr_is_ess,
266 Array<Vector *> &rhs);
267
268
269 /// Computes the energy for a state vector x.
270 virtual real_t GetEnergy(const Vector &x) const;
271
272 /// Method is only called in serial, the parallel version calls MultBlocked
273 /// directly.
274 virtual void Mult(const Vector &x, Vector &y) const;
275
276 /// Method is only called in serial, the parallel version calls MultBlocked
277 /// directly.
278 virtual void ParamMult(const Vector &x, Vector &y) const;
279
280 /// Method is only called in serial, the parallel version calls
281 /// GetGradientBlocked directly.
282 virtual BlockOperator &GetGradient(const Vector &x) const;
283
284 /// Set the state fields
285 virtual void SetStateFields(const Vector &xv) const;
286
287 /// Set the adjoint fields
288 virtual void SetAdjointFields(const Vector &av) const;
289
290 /// Set the parameters/design fields
291 virtual void SetParamFields(const Vector &dv) const;
292
293 /// Destructor.
294 virtual ~ParametricBNLForm();
295
296};
297
298}
299
300#endif
Dynamic 2D array using row-major layout.
Definition array.hpp:372
A class to handle Block systems in a matrix-free implementation.
A class to handle Vectors in a block fashion.
A specialized ElementTransformation class representing a face and its two neighboring elements.
Definition eltrans.hpp:484
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition fespace.hpp:220
Abstract operator.
Definition operator.hpp:25
virtual void AssembleFaceVector(const Array< const FiniteElement * > &el1, const Array< const FiniteElement * > &el2, const Array< const FiniteElement * > &pel1, const Array< const FiniteElement * > &pel2, FaceElementTransformations &Tr, const Array< const Vector * > &elfun, const Array< const Vector * > &pelfun, const Array< Vector * > &elvect)
virtual real_t GetElementEnergy(const Array< const FiniteElement * > &el, const Array< const FiniteElement * > &pel, ElementTransformation &Tr, const Array< const Vector * > &elfun, const Array< const Vector * > &pelfun)
Compute the local energy.
virtual void AssemblePrmFaceVector(const Array< const FiniteElement * > &el1, const Array< const FiniteElement * > &el2, const Array< const FiniteElement * > &pel1, const Array< const FiniteElement * > &pel2, FaceElementTransformations &Tr, const Array< const Vector * > &elfun, const Array< const Vector * > &alfun, const Array< const Vector * > &pelfun, const Array< Vector * > &pelvect)
virtual void AssembleFaceGrad(const Array< const FiniteElement * > &el1, const Array< const FiniteElement * > &el2, const Array< const FiniteElement * > &pel1, const Array< const FiniteElement * > &pel2, FaceElementTransformations &Tr, const Array< const Vector * > &elfun, const Array< const Vector * > &pelfun, const Array2D< DenseMatrix * > &elmats)
Assemble the local gradient matrix on faces of the elements.
virtual void AssemblePrmElementVector(const Array< const FiniteElement * > &el, const Array< const FiniteElement * > &pel, ElementTransformation &Tr, const Array< const Vector * > &elfun, const Array< const Vector * > &alfun, const Array< const Vector * > &pelfun, const Array< Vector * > &pelvec)
Perform the local action on the parameters of the BNLFormIntegrator.
virtual void AssembleElementVector(const Array< const FiniteElement * > &el, const Array< const FiniteElement * > &pel, ElementTransformation &Tr, const Array< const Vector * > &elfun, const Array< const Vector * > &pelfun, const Array< Vector * > &elvec)
Perform the local action of the BlockNonlinearFormIntegrator.
virtual void AssembleElementGrad(const Array< const FiniteElement * > &el, const Array< const FiniteElement * > &pel, ElementTransformation &Tr, const Array< const Vector * > &elfun, const Array< const Vector * > &pelfun, const Array2D< DenseMatrix * > &elmats)
Assemble the local gradient matrix.
A class representing a general parametric block nonlinear operator defined on the Cartesian product o...
virtual void ParamMult(const Vector &x, Vector &y) const
real_t GetEnergyBlocked(const BlockVector &bx, const BlockVector &dx) const
FiniteElementSpace * ParamFESpace(int k)
Return the k-th parametric FE space of the ParametricBNLForm.
bool needs_prolongation
Indicator if the Operator needs prolongation on assembly.
const FiniteElementSpace * FESpace(int k) const
Return the k-th FE space of the BlockNonlinearForm (const version).
const BlockVector & ParamProlongate(const BlockVector &bx) const
virtual void SetStateFields(const Vector &xv) const
Set the state fields.
virtual void SetParamEssentialBC(const Array< Array< int > * > &bdr_attr_is_ess, Array< Vector * > &rhs)
Set the essential boundary conditions on the parametric fields.
Array< FiniteElementSpace * > paramfes
FE spaces for the parametric fields.
void AddInteriorFaceIntegrator(ParametricBNLFormIntegrator *nlfi)
Adds new Interior Face Integrator.
FiniteElementSpace * FESpace(int k)
Return the k-th FE space of the ParametricBNLForm.
Array< const Operator * > P
Array of pointers to the prolongation matrix of fes, may be NULL.
bool is_serial
Indicator if the Operator is part of a parallel run.
void MultParamBlocked(const BlockVector &bx, const BlockVector &ax, const BlockVector &dx, BlockVector &dy) const
void MultBlocked(const BlockVector &bx, const BlockVector &dx, BlockVector &by) const
void AddBdrFaceIntegrator(ParametricBNLFormIntegrator *nlfi)
Adds new Boundary Face Integrator.
const BlockVector & Prolongate(const BlockVector &bx) const
const Array< int > & GetBlockTrueOffsets() const
Return the true-dof offsets.
void ComputeGradientBlocked(const BlockVector &bx, const BlockVector &dx) const
Specialized version of GetGradient() for BlockVector.
ParametricBNLForm()
Construct an empty BlockNonlinearForm. Initialize with SetSpaces().
const FiniteElementSpace * ParamFESpace(int k) const
Array2D< SparseMatrix * > Grads
virtual ~ParametricBNLForm()
Destructor.
Array< Array< int > * > ess_tdofs
virtual real_t GetEnergy(const Vector &x) const
Computes the energy for a state vector x.
virtual BlockOperator & GetGradient(const Vector &x) const
Array< FiniteElementSpace * > fes
FE spaces on which the form lives.
const Array< int > & GetBlockOffsets() const
Return the regular dof offsets.
virtual void SetAdjointFields(const Vector &av) const
Set the adjoint fields.
Array< const SparseMatrix * > cP
Array of results of dynamic-casting P to SparseMatrix pointer.
Array< ParametricBNLFormIntegrator * > & GetDNFI()
Return the integrators.
const Array< int > & ParamGetBlockOffsets() const
Return the regular dof offsets for the parameters.
virtual void Mult(const Vector &x, Vector &y) const
bool prmneeds_prolongation
Indicator if the Operator needs prolongation on assembly.
const Array< int > & ParamGetBlockTrueOffsets() const
Return the true-dof offsets for the parameters.
virtual void SetEssentialBC(const Array< Array< int > * > &bdr_attr_is_ess, Array< Vector * > &rhs)
Set the essential boundary conditions.
virtual void SetParamFields(const Vector &dv) const
Set the parameters/design fields.
Array< ParametricBNLFormIntegrator * > bfnfi
Set of Boundary Face Integrators to be assembled (added).
Array2D< SparseMatrix * > cGrads
Array< const Operator * > Pparam
Array of pointers to the prolongation matrix of paramfes, may be NULL.
Array< ParametricBNLFormIntegrator * > dnfi
Set of Domain Integrators to be assembled (added).
Array< Array< int > * > paramess_tdofs
void AddDomainIntegrator(ParametricBNLFormIntegrator *nlfi)
Adds new Domain Integrator.
Array< const SparseMatrix * > cPparam
Array of results of dynamic-casting Pparam to SparseMatrix pointer.
Array< ParametricBNLFormIntegrator * > fnfi
Set of interior face Integrators to be assembled (added).
Array< Array< int > * > bfnfi_marker
void SetSpaces(Array< FiniteElementSpace * > &statef, Array< FiniteElementSpace * > &paramf)
(Re)initialize the ParametricBNLForm.
Vector data type.
Definition vector.hpp:80
float real_t
Definition config.hpp:43