MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
darcy_solver.cpp
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#include "darcy_solver.hpp"
13
14using namespace std;
15
16namespace mfem
17{
18namespace blocksolvers
19{
21{
22 solver.SetPrintLevel(param.print_level);
23 solver.SetMaxIter(param.max_iter);
24 solver.SetAbsTol(param.abs_tol);
25 solver.SetRelTol(param.rel_tol);
26}
27
28/// Wrapper Block Diagonal Preconditioned MINRES (ex5p)
29/** Wrapper for assembling the discrete Darcy problem (ex5p)
30 [ M B^T ] [u] = [f]
31 [ B 0 ] [p] = [g]
32*/
34 const HypreParMatrix& B,
36 : DarcySolver(M.NumRows(), B.NumRows()), op_(offsets_), prec_(offsets_),
37 BT_(B.Transpose()), solver_(M.GetComm())
38{
39 op_.SetBlock(0,0, const_cast<HypreParMatrix*>(&M));
40 op_.SetBlock(0,1, BT_.As<HypreParMatrix>());
41 op_.SetBlock(1,0, const_cast<HypreParMatrix*>(&B));
42
43 Vector Md;
44 M.GetDiag(Md);
45 BT_.As<HypreParMatrix>()->InvScaleRows(Md);
46 S_.Reset(ParMult(&B, BT_.As<HypreParMatrix>()));
47 BT_.As<HypreParMatrix>()->ScaleRows(Md);
48
49 prec_.SetDiagonalBlock(0, new HypreDiagScale(M));
51 static_cast<HypreBoomerAMG&>(prec_.GetDiagonalBlock(1)).SetPrintLevel(0);
52 prec_.owns_blocks = true;
53
54 SetOptions(solver_, param);
55 solver_.SetOperator(op_);
56 solver_.SetPreconditioner(prec_);
57}
58
59void BDPMinresSolver::Mult(const Vector & x, Vector & y) const
60{
61 solver_.Mult(x, y);
62 for (int dof : ess_zero_dofs_) { y[dof] = 0.0; }
63}
64} // namespace blocksolvers
65} // namespace mfem
Operator & GetDiagonalBlock(int iblock)
Return a reference to block i,i.
void SetDiagonalBlock(int iblock, Operator *op)
Add a square block op in the block-entry (iblock, iblock).
void SetBlock(int iRow, int iCol, Operator *op, real_t c=1.0)
Add a block op in the block-entry (iblock, jblock).
The BoomerAMG solver in hypre.
Definition hypre.hpp:1691
Jacobi preconditioner in hypre.
Definition hypre.hpp:1481
Wrapper for hypre's ParCSR matrix class.
Definition hypre.hpp:388
void GetDiag(Vector &diag) const
Get the local diagonal of the matrix.
Definition hypre.cpp:1557
Abstract base class for iterative solver.
Definition solvers.hpp:67
void SetRelTol(real_t rtol)
Definition solvers.hpp:209
virtual void SetPrintLevel(int print_lvl)
Legacy method to set the level of verbosity of the solver output.
Definition solvers.cpp:71
void SetMaxIter(int max_it)
Definition solvers.hpp:211
void SetAbsTol(real_t atol)
Definition solvers.hpp:210
virtual void Mult(const Vector &b, Vector &x) const
Iterative solution of the linear system using the MINRES method.
Definition solvers.cpp:1616
virtual void SetOperator(const Operator &op)
Also calls SetOperator for the preconditioner if there is one.
Definition solvers.cpp:1595
virtual void SetPreconditioner(Solver &pr)
This should be called before SetOperator.
Definition solvers.hpp:640
OpType * As() const
Return the Operator pointer statically cast to a specified OpType. Similar to the method Get().
Definition handle.hpp:104
void Reset(OpType *A, bool own_A=true)
Reset the OperatorHandle to the given OpType pointer, A.
Definition handle.hpp:145
Vector data type.
Definition vector.hpp:80
virtual void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
BDPMinresSolver(const HypreParMatrix &M, const HypreParMatrix &B, IterSolveParameters param)
Wrapper Block Diagonal Preconditioned MINRES (ex5p)
Abstract solver class for Darcy's flow.
void SetOptions(IterativeSolver &solver, const IterSolveParameters &param)
void Transpose(const Table &A, Table &At, int ncols_A_)
Transpose a Table.
Definition table.cpp:414
HypreParMatrix * ParMult(const HypreParMatrix *A, const HypreParMatrix *B, bool own_matrix)
Definition hypre.cpp:2949