1 static char help[] = "Demonstrates PetscDataTypeFromString().\n\n";
2
3 #include <petscsys.h>
main(int argc,char ** argv)4 int main(int argc, char **argv)
5 {
6 PetscDataType dtype;
7 PetscBool found;
8
9 /*
10 Every PETSc routine should begin with the PetscInitialize() routine.
11 argc, argv - These command line arguments are taken to extract the options
12 supplied to PETSc and options supplied to MPI.
13 help - When PETSc executable is invoked with the option -help,
14 it prints the various options that can be applied at
15 runtime. The user can use the "help" variable place
16 additional help messages in this printout.
17 */
18 PetscFunctionBeginUser;
19 PetscCall(PetscInitialize(&argc, &argv, NULL, help));
20
21 PetscCall(PetscDataTypeFromString("Scalar", &dtype, &found));
22 PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Did not find scalar datatype");
23 PetscCheck(dtype == PETSC_SCALAR, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Found wrong datatype for scalar");
24
25 PetscCall(PetscDataTypeFromString("INT", &dtype, &found));
26 PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Did not find int datatype");
27 PetscCheck(dtype == PETSC_INT, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Found wrong datatype for int");
28
29 PetscCall(PetscDataTypeFromString("real", &dtype, &found));
30 PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Did not find real datatype");
31 PetscCheck(dtype == PETSC_REAL, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Found wrong datatype for real");
32
33 PetscCall(PetscDataTypeFromString("abogusdatatype", &dtype, &found));
34 PetscCheck(!found, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Found a bogus datatype");
35
36 PetscCall(PetscFinalize());
37 return 0;
38 }
39
40 /*TEST
41
42 test:
43 output_file: output/empty.out
44
45 TEST*/
46