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