12#include <gtest/gtest.h>
17TEST(operatorsCreateBnHeadTest, testBNHatDiagonalOp)
25 PetscReal ans = nx * ny * dt;
27 MatCreate(PETSC_COMM_WORLD, &Op);
28 MatSetSizes(Op, PETSC_DECIDE, PETSC_DECIDE, nx * ny, nx * ny);
29 MatSetType(Op, MATAIJ);
31 for (PetscInt i = 0; i < nx * ny; i++)
32 MatSetValues(Op, 1, &i, 1, &i, &val, INSERT_VALUES);
33 MatAssemblyBegin(Op, MAT_FINAL_ASSEMBLY);
34 MatAssemblyEnd(Op, MAT_FINAL_ASSEMBLY);
35 for (PetscInt N = 1; N <= 10; N++)
42 PetscInt nrows, ncols;
43 MatGetSize(BNHat, &nrows, &ncols);
44 ASSERT_EQ(nx * ny, nrows);
45 ASSERT_EQ(nx * ny, ncols);
48 if (N > 1) ans += dt * nx * ny * std::pow(c * dt * val, N - 1);
52 MatCreateVecs(Op, &
v,
nullptr);
53 MatGetRowSum(BNHat,
v);
55 ASSERT_TRUE(std::abs(sum - ans) <= 1.0E-11);
64int main(
int argc,
char **argv)
66 PetscErrorCode ierr, status;
68 ::testing::InitGoogleTest(&argc, argv);
69 ierr = PetscInitialize(&argc, &argv,
nullptr,
nullptr); CHKERRQ(ierr);
70 status = RUN_ALL_TESTS();
71 ierr = PetscFinalize(); CHKERRQ(ierr);
int main(int argc, char **argv)
TEST(operatorsCreateBnHeadTest, testBNHatDiagonalOp)
PetscErrorCode createBnHead(const Mat &Op, const PetscReal &dt, const PetscReal &coeff, const PetscInt &n, Mat &BnHead)
Create non-normalized matrix of approximated , .
Prototypes of factory functions for operators.