8int main(
int argc,
char *argv[]) {
10 "Compare saved solution vectors in order.\n");
12 char left_file[PETSC_MAX_PATH_LEN] =
"";
13 char right_file[PETSC_MAX_PATH_LEN] =
"";
15 PetscReal tolerance = 1.e-9;
17 sizeof(left_file),
nullptr);
19 sizeof(right_file),
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,
31 CHKERR PetscViewerBinaryOpen(PETSC_COMM_WORLD, right_file, FILE_MODE_READ,
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);
61 for (
auto viewer : {left_viewer, right_viewer}) {
62 PetscInt extra, count_read;
63 CHKERR PetscViewerBinaryRead(viewer, &extra, 1, &count_read, PETSC_INT);
66 "Vector file contains more than the expected number of states");
68 CHKERR PetscViewerDestroy(&left_viewer);
69 CHKERR PetscViewerDestroy(&right_viewer);
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.