PolyDiM
C++ library for POLYtopal DIscretization Methods
Loading...
Searching...
No Matches
VEM_DF_PCC_PerformanceAnalysis.hpp
Go to the documentation of this file.
1// _LICENSE_HEADER_
2//
3// Copyright (C) 2019 - 2025.
4// Terms register on the GPL-3.0 license.
5//
6// This file can be redistributed and/or modified under the license terms.
7//
8// See top level LICENSE file for more details.
9//
10// This file can be used citing references in CITATION.cff file.
11
12#ifndef __VEM_DF_PCC_PerformanceAnalysis_HPP
13#define __VEM_DF_PCC_PerformanceAnalysis_HPP
14
15#include "Eigen/Eigen"
16#include <vector>
17
18#include "LAPACK_utilities.hpp"
20
21namespace Polydim
22{
23namespace VEM
24{
25namespace DF_PCC
26{
28{
29 std::vector<double> PiNablaConditioning;
30 std::vector<double> Pi0km2Conditioning;
31 std::vector<double> Pi0kConditioning;
32 std::vector<double> ErrorPiNabla;
33 std::vector<double> ErrorPi0km2;
34 std::vector<double> ErrorPi0k;
35 std::vector<double> ErrorPi0km1Grad;
36 double StabNorm = -1.0;
37 double ErrorStabilization = -1.0;
38 std::vector<double> ErrorHCD;
39 std::vector<double> ErrorGBD;
40 std::vector<double> ErrorHED;
41
48};
49
51{
52 template <typename VEM_Monomials_Type, typename VEM_Monomials_Data_Type, typename VEM_vem_local_space_data_Type, typename VEM_vem_local_space_dataData_Type>
53 VEM_DF_PCC_PerformanceAnalysis_Data Compute(const VEM_Monomials_Type &vem_monomials,
54 const VEM_Monomials_Data_Type &vem_monomials_data,
55 const VEM_vem_local_space_data_Type &vem_local_space,
56 const VEM_vem_local_space_dataData_Type &vem_local_space_data) const
57 {
59
60 const double invDiameter = 1.0 / vem_local_space_data.Diameter;
61
62 const std::vector<Eigen::MatrixXd> &piNabla = vem_local_space_data.PiNabla;
63 const std::vector<Eigen::MatrixXd> &pi0km2 = vem_local_space_data.Pi0km2;
64 const std::vector<Eigen::MatrixXd> &pi0k = vem_local_space_data.Pi0k;
65 const std::vector<Eigen::MatrixXd> &Dmatrix = vem_local_space_data.Dmatrix;
66
67 result.PiNablaConditioning.resize(vem_local_space_data.Dimension, -1.0);
68 result.Pi0kConditioning.resize(vem_local_space_data.Dimension, -1.0);
69 result.Pi0km2Conditioning.resize(vem_local_space_data.Dimension, -1.0);
70 for (unsigned int d = 0; d < vem_local_space_data.Dimension; d++)
71 {
75 }
76
77 const Eigen::MatrixXd identity = Eigen::MatrixXd::Identity(vem_local_space_data.Nk, vem_local_space_data.Nk);
78
79 result.ErrorPiNabla.resize(vem_local_space_data.Dimension, 1.0);
80 result.ErrorPi0km2.resize(vem_local_space_data.Dimension, 1.0);
81 result.ErrorPi0k.resize(vem_local_space_data.Dimension, 1.0);
82 result.ErrorPi0km1Grad.resize(vem_local_space_data.Dimension * vem_local_space_data.Dimension, 1.0);
83 for (unsigned int d1 = 0; d1 < vem_local_space_data.Dimension; d1++)
84 {
85 result.ErrorPiNabla[d1] = (piNabla[d1] * Dmatrix[d1] - identity).norm() / identity.norm();
86 result.ErrorPi0km2[d1] = (pi0km2[d1] * Dmatrix[d1].leftCols(vem_local_space_data.Nkm2) -
87 identity.topLeftCorner(vem_local_space_data.Nkm2, vem_local_space_data.Nkm2))
88 .norm() /
89 identity.topLeftCorner(vem_local_space_data.Nkm2, vem_local_space_data.Nkm2).norm();
90
91 result.ErrorPi0k[d1] = (pi0k[d1] * Dmatrix[d1] - identity).norm() / identity.norm();
92
93 for (unsigned int d2 = 0; d2 < vem_local_space_data.Dimension; d2++)
94 {
95 const Eigen::MatrixXd derMatrix =
96 invDiameter * vem_monomials.DerivativeMatrix(vem_monomials_data, d2)
97 .topLeftCorner(vem_local_space_data.Nk, vem_local_space_data.Nkm1);
98
99 result.ErrorPi0km1Grad[vem_local_space_data.Dimension * d1 + d2] =
100 (vem_local_space_data.Pi0km1Der[vem_local_space_data.Dimension * d1 + d2] * vem_local_space_data.Dmatrix[d1] -
101 derMatrix.transpose())
102 .norm() /
103 derMatrix.norm();
104 }
105 }
106
107 const Eigen::MatrixXd StabMatrix =
108 vem_local_space.ComputeDofiDofiStabilizationMatrix(vem_local_space_data, ProjectionTypes::PiNabla);
109
110 const Eigen::MatrixXd &stabilizationMatrix = StabMatrix;
111 result.StabNorm = StabMatrix.norm();
112
113 Eigen::MatrixXd polynomialBasisDofs =
114 Eigen::MatrixXd::Zero(vem_local_space_data.NumBasisFunctions,
115 vem_local_space_data.Dimension * vem_local_space_data.Nk);
116 for (unsigned int d = 0; d < vem_local_space_data.Dimension; d++)
117 polynomialBasisDofs.middleCols(d * vem_local_space_data.Nk, vem_local_space_data.Nk) =
118 vem_local_space_data.Dmatrix[d];
119
120 result.ErrorStabilization = (stabilizationMatrix * polynomialBasisDofs).norm();
121
122 result.ErrorHCD.resize(vem_local_space_data.Dimension, 1.0);
123 result.ErrorGBD.resize(vem_local_space_data.Dimension, 1.0);
124 result.ErrorHED.resize(vem_local_space_data.Dimension * vem_local_space_data.Dimension, 1.0);
125
126 if (vem_local_space_data.Hmatrix.size() > 0 && vem_local_space_data.Cmatrix.size() > 0)
127 {
128 const double HMatrixInvNorm = 1.0 / vem_local_space_data.Hmatrix.norm();
129 for (unsigned int d1 = 0; d1 < vem_local_space_data.Dimension; d1++)
130 result.ErrorHCD[d1] =
131 (vem_local_space_data.Hmatrix - vem_local_space_data.Cmatrix[d1] * vem_local_space_data.Dmatrix[d1]).norm() * HMatrixInvNorm;
132 }
133
134 if (vem_local_space_data.Gmatrix.size() > 0 && vem_local_space_data.Bmatrix.size() > 0)
135 {
136 const double GMatrixInvNorm = 1.0 / vem_local_space_data.Gmatrix.norm();
137 for (unsigned int d1 = 0; d1 < vem_local_space_data.Dimension; d1++)
138 result.ErrorGBD[d1] =
139 (vem_local_space_data.Gmatrix - vem_local_space_data.Bmatrix[d1] * vem_local_space_data.Dmatrix[d1]).norm() * GMatrixInvNorm;
140 }
141
142 if (vem_local_space_data.Hmatrix.size() > 0 && vem_local_space_data.Ematrix.size() > 0)
143 {
144 for (unsigned int d1 = 0; d1 < vem_local_space_data.Dimension; d1++)
145 {
146 for (unsigned int d2 = 0; d2 < vem_local_space_data.Dimension; d2++)
147 {
148 const Eigen::MatrixXd derMatrix =
149 invDiameter *
150 vem_monomials.DerivativeMatrix(vem_monomials_data, d2)
151 .topLeftCorner(vem_local_space_data.Nk, vem_local_space_data.Nkm1) *
152 vem_local_space_data.Hmatrix.topLeftCorner(vem_local_space_data.Nkm1, vem_local_space_data.Nkm1);
153
154 result.ErrorHED[vem_local_space_data.Dimension * d1 + d2] =
155 (vem_local_space_data.Ematrix[vem_local_space_data.Dimension * d1 + d2] * vem_local_space_data.Dmatrix[d1] -
156 derMatrix.transpose())
157 .norm() /
158 derMatrix.norm();
159 }
160 }
161 }
162
163 result.maxErrorGBD = *std::max_element(result.ErrorGBD.begin(), result.ErrorGBD.end());
164 result.maxErrorHCD = *std::max_element(result.ErrorHCD.begin(), result.ErrorHCD.end());
165 result.maxErrorPiNabla = *std::max_element(result.ErrorPiNabla.begin(), result.ErrorPiNabla.end());
166 result.maxErrorPi0k = *std::max_element(result.ErrorPi0k.begin(), result.ErrorPi0k.end());
167 result.maxPiNablaConditioning = *std::max_element(result.PiNablaConditioning.begin(), result.PiNablaConditioning.end());
168 result.maxPi0kConditioning = *std::max_element(result.Pi0kConditioning.begin(), result.Pi0kConditioning.end());
169
170 return result;
171 }
172};
173
174} // namespace DF_PCC
175} // namespace VEM
176} // namespace Polydim
177
178#endif
double cond(const Eigen::VectorXd &s)
Compute condition number in norm 2 given singular values.
Definition LAPACK_utilities.hpp:38
void svd(Eigen::MatrixXd A, Eigen::MatrixXd &V, Eigen::VectorXd &S)
Given A = U * S * V' returns only S and V'.
Definition LAPACK_utilities.cpp:166
Definition FEM_MCC_2D_LocalSpace.cpp:17
Definition VEM_DF_PCC_PerformanceAnalysis.hpp:28
double maxErrorPi0k
Definition VEM_DF_PCC_PerformanceAnalysis.hpp:45
double ErrorStabilization
Definition VEM_DF_PCC_PerformanceAnalysis.hpp:37
double StabNorm
Definition VEM_DF_PCC_PerformanceAnalysis.hpp:36
std::vector< double > ErrorHED
Definition VEM_DF_PCC_PerformanceAnalysis.hpp:40
double maxErrorGBD
Definition VEM_DF_PCC_PerformanceAnalysis.hpp:47
std::vector< double > Pi0kConditioning
Definition VEM_DF_PCC_PerformanceAnalysis.hpp:31
std::vector< double > ErrorPiNabla
Definition VEM_DF_PCC_PerformanceAnalysis.hpp:32
double maxErrorPiNabla
Definition VEM_DF_PCC_PerformanceAnalysis.hpp:44
std::vector< double > ErrorPi0k
Definition VEM_DF_PCC_PerformanceAnalysis.hpp:34
double maxPiNablaConditioning
Definition VEM_DF_PCC_PerformanceAnalysis.hpp:42
double maxPi0kConditioning
Definition VEM_DF_PCC_PerformanceAnalysis.hpp:43
std::vector< double > ErrorHCD
Definition VEM_DF_PCC_PerformanceAnalysis.hpp:38
double maxErrorHCD
Definition VEM_DF_PCC_PerformanceAnalysis.hpp:46
std::vector< double > PiNablaConditioning
Definition VEM_DF_PCC_PerformanceAnalysis.hpp:29
std::vector< double > Pi0km2Conditioning
Definition VEM_DF_PCC_PerformanceAnalysis.hpp:30
std::vector< double > ErrorGBD
Definition VEM_DF_PCC_PerformanceAnalysis.hpp:39
std::vector< double > ErrorPi0km1Grad
Definition VEM_DF_PCC_PerformanceAnalysis.hpp:35
std::vector< double > ErrorPi0km2
Definition VEM_DF_PCC_PerformanceAnalysis.hpp:33
Definition VEM_DF_PCC_PerformanceAnalysis.hpp:51
VEM_DF_PCC_PerformanceAnalysis_Data Compute(const VEM_Monomials_Type &vem_monomials, const VEM_Monomials_Data_Type &vem_monomials_data, const VEM_vem_local_space_data_Type &vem_local_space, const VEM_vem_local_space_dataData_Type &vem_local_space_data) const
Definition VEM_DF_PCC_PerformanceAnalysis.hpp:53