MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
block_fespace_operator.cpp
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
13
14namespace mfem
15{
16
18 Operator(GetHeight(fespaces)),
19 offsets(GetBlockOffsets(fespaces)),
20 prolongColOffsets(GetProColBlockOffsets(fespaces)),
21 restrictRowOffsets(GetResRowBlockOffsets(fespaces)),
22 A(offsets),
23 prolongation(offsets, prolongColOffsets),
24 restriction(restrictRowOffsets, offsets)
25{
26 for (size_t i = 0; i <fespaces.size(); i++)
27 {
28 // Since const_cast is required here, be sure to avoid using
29 // BlockOperator::GetBlock on restriction or prolongation.
30 auto prolongation_matrix = fespaces[i]->GetProlongationMatrix();
31 auto restriction_matrix = fespaces[i]->GetRestrictionOperator();
32 prolongation.SetDiagonalBlock(i, const_cast<Operator *>(prolongation_matrix));
33 restriction.SetDiagonalBlock(i, const_cast<Operator *>(restriction_matrix));
34 }
35}
36
37int BlockFESpaceOperator::GetHeight(const FESVector &fespaces)
38{
39 int height = 0;
40 for (size_t i = 0; i < fespaces.size(); i++)
41 {
42 height += fespaces[i]->GetVSize();
43 }
44 return height;
45}
46
47Array<int> BlockFESpaceOperator::GetBlockOffsets(const FESVector &fespaces)
48{
49 Array<int> offsets(fespaces.size()+1);
50 offsets[0] = 0;
51 for (size_t i = 1; i <=fespaces.size(); i++)
52 {
53 offsets[i] = fespaces[i-1]->GetVSize();
54 }
55 offsets.PartialSum();
56 offsets.Print();
57 return offsets;
58}
59
60Array<int> BlockFESpaceOperator::GetProColBlockOffsets(const FESVector
61 &fespaces)
62{
63 Array<int> offsets(fespaces.size()+1);
64 offsets[0] = 0;
65 for (size_t i = 1; i <=fespaces.size(); i++)
66 {
67 const auto *prolong = fespaces[i-1]->GetProlongationMatrix();
68 if (prolong)
69 {
70 offsets[i] = prolong->Width();
71 }
72 else
73 {
74 offsets[i] = fespaces[i-1]->GetVSize();
75 }
76 offsets[i] = fespaces[i-1]->GetTrueVSize();
77 }
78 offsets.PartialSum();
79 offsets.Print();
80 return offsets;
81}
82
83Array<int> BlockFESpaceOperator::GetResRowBlockOffsets(const FESVector
84 &fespaces)
85{
86 Array<int> offsets(fespaces.size()+1);
87 std::cout << "fespaces.size() = " << fespaces.size() << std::endl;
88 offsets[0] = 0;
89 for (size_t i = 1; i <=fespaces.size(); i++)
90 {
91 const auto *restriction = fespaces[i-1]->GetRestrictionOperator();
92 if (restriction)
93 {
94 offsets[i] = restriction->Height();
95 }
96 else
97 {
98 offsets[i] = fespaces[i-1]->GetVSize();
99 }
100 offsets[i] = fespaces[i-1]->GetTrueVSize();
101 }
102 offsets.PartialSum();
103 offsets.Print();
104 return offsets;
105}
106
108{
109 return &prolongation;
110}
111
113{
114 return &restriction;
115}
116
117} // namespace mfem
void PartialSum()
Fill the entries of the array with the cumulative sum of the entries.
Definition array.cpp:104
void Print(std::ostream &out=mfem::out, int width=4) const
Prints array to stream with width elements per row.
Definition array.cpp:24
const Operator * GetProlongation() const override
Prolongation operator from linear algebra (linear system) vectors, to input vectors for the operator....
BlockFESpaceOperator(const FESVector &fespaces)
Constructor for BlockFESpaceOperator.
const Operator * GetRestriction() const override
Restriction operator from input vectors for the operator to linear algebra (linear system) vectors....
void SetDiagonalBlock(int iblock, Operator *op, real_t c=1.0)
Add block op in the block-entry (iblock, iblock).
Abstract operator.
Definition operator.hpp:25
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
Definition operator.hpp:66
int height
Dimension of the output / number of rows in the matrix.
Definition operator.hpp:27