8 {
10 "Compare saved solution vectors in order.\n");
11 try {
12 char left_file[PETSC_MAX_PATH_LEN] = "";
13 char right_file[PETSC_MAX_PATH_LEN] = "";
14 PetscInt count = 1;
15 PetscReal tolerance = 1.e-9;
17 sizeof(left_file), nullptr);
19 sizeof(right_file), nullptr);
21 nullptr);
23 &tolerance, nullptr);
24 if (!left_file[0] || !right_file[0] || count < 1 ||
25 !std::isfinite(tolerance) || tolerance <= 0.)
27 "Specify both vector files, a positive count and tolerance");
28 PetscViewer left_viewer, right_viewer;
29 CHKERR PetscViewerBinaryOpen(PETSC_COMM_WORLD, left_file, FILE_MODE_READ,
30 &left_viewer);
31 CHKERR PetscViewerBinaryOpen(PETSC_COMM_WORLD, right_file, FILE_MODE_READ,
32 &right_viewer);
33 for (PetscInt step = 0; step != count; ++step) {
34 Vec left_raw, right_raw;
35 CHKERR VecCreate(PETSC_COMM_WORLD, &left_raw);
36 CHKERR VecCreate(PETSC_COMM_WORLD, &right_raw);
38 CHKERR VecLoad(left, left_viewer);
39 CHKERR VecLoad(right, right_viewer);
40 PetscInt left_size, right_size;
41 CHKERR VecGetSize(left, &left_size);
42 CHKERR VecGetSize(right, &right_size);
43 if (left_size != right_size || !left_size)
45 "Solution vectors have different or empty layouts");
46 PetscReal
scale, difference;
48 CHKERR VecAXPY(right, -1., left);
49 CHKERR VecNorm(right, NORM_INFINITY, &difference);
50 if (!std::isfinite(
scale) || !std::isfinite(difference) ||
51 difference > tolerance * std::max(1.,
scale))
53 "Solution vector %" PetscInt_FMT
54 " differs by %.16e (scale %.16e)",
55 step, difference,
scale);
56 CHKERR PetscPrintf(PETSC_COMM_WORLD,
57 "Solution vector %" PetscInt_FMT ": %" PetscInt_FMT
58 " coefficients, maximum difference %.16e\n",
59 step, left_size, difference);
60 }
61 for (auto viewer : {left_viewer, right_viewer}) {
62 PetscInt extra, count_read;
63 CHKERR PetscViewerBinaryRead(viewer, &extra, 1, &count_read, PETSC_INT);
64 if (count_read)
66 "Vector file contains more than the expected number of states");
67 }
68 CHKERR PetscViewerDestroy(&left_viewer);
69 CHKERR PetscViewerDestroy(&right_viewer);
70 }
73 return 0;
74}
#define CATCH_ERRORS
Catch errors.
@ MOFEM_ATOM_TEST_INVALID
#define CHKERR
Inline error check.
const FTensor::Tensor2< T, Dim, Dim > Vec
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
PetscErrorCode PetscOptionsGetReal(PetscOptions *, const char pre[], const char name[], PetscReal *dval, PetscBool *set)
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
intrusive_ptr for managing petsc objects