1 static char help[] = "Example for PetscOptionsInsertFileYAML\n"; 2 3 #include <petscsys.h> 4 #include <petscviewer.h> 5 6 int main(int argc, char **argv) 7 { 8 char filename[PETSC_MAX_PATH_LEN]; 9 PetscBool flg; 10 11 PetscFunctionBeginUser; 12 PetscCall(PetscInitialize(&argc, &argv, NULL, help)); 13 14 PetscCall(PetscOptionsGetString(NULL, NULL, "-f", filename, sizeof(filename), &flg)); 15 if (flg) PetscCall(PetscOptionsInsertFileYAML(PETSC_COMM_WORLD, NULL, filename, PETSC_TRUE)); 16 17 PetscCall(PetscOptionsGetString(NULL, NULL, "-yaml", filename, sizeof(filename), &flg)); 18 if (flg) { 19 PetscBool monitor = PETSC_FALSE; 20 21 PetscCall(PetscOptionsGetBool(NULL, NULL, "-monitor", &monitor, NULL)); 22 if (monitor) PetscCall(PetscOptionsMonitorSet(PetscOptionsMonitorDefault, PETSC_VIEWER_STDOUT_WORLD, NULL)); 23 PetscCall(PetscOptionsClear(NULL)); 24 PetscCall(PetscOptionsInsertFileYAML(PETSC_COMM_WORLD, NULL, filename, PETSC_TRUE)); 25 } 26 27 PetscCall(PetscOptionsGetString(NULL, NULL, "-yamlstr", filename, sizeof(filename), &flg)); 28 if (flg) { 29 PetscBool monitor = PETSC_FALSE; 30 31 PetscCall(PetscOptionsGetBool(NULL, NULL, "-monitor", &monitor, NULL)); 32 if (monitor) PetscCall(PetscOptionsMonitorSet(PetscOptionsMonitorDefault, NULL, NULL)); 33 PetscCall(PetscOptionsClear(NULL)); 34 PetscCall(PetscOptionsInsertStringYAML(NULL, filename)); 35 } 36 37 PetscCall(PetscOptionsView(NULL, PETSC_VIEWER_STDOUT_WORLD)); 38 PetscCall(PetscOptionsClear(NULL)); 39 PetscCall(PetscFinalize()); 40 return 0; 41 } 42 43 /*TEST 44 45 testset: 46 args: -options_left false 47 filter: grep -E -v "(options_left|options_monitor)" 48 localrunfiles: petsc.yml 49 50 test: 51 suffix: 1 52 args: -f petsc.yml 53 54 test: 55 suffix: 2_file 56 output_file: output/ex47_2.out 57 args: -options_file_yaml petsc.yml 58 59 test: 60 suffix: 2_string 61 args: -options_string_yaml "`cat petsc.yml`" 62 63 test: 64 suffix: 2_auto 65 args: -options_monitor 66 args: -options_file ex47-yaml_tag 67 args: -options_file ex47-yaml_doc 68 localrunfiles: ex47-yaml_tag ex47-yaml_doc 69 70 test: 71 suffix: 2_prefix 72 args: -options_monitor 73 args: -options_file ex47-opt.txt 74 args: -prefix_push p5_ -options_file ex47-opt.yml -prefix_pop 75 args: -prefix_push p5_ -options_file ex47-opt.yml:yaml -prefix_pop 76 args: -prefix_push p6_ -options_file_yaml ex47-opt.yml -prefix_pop 77 args: -prefix_push p7_ -options_string_yaml "`cat ex47-opt.yml`" -prefix_pop 78 args: -prefix_push p7_ -options_string_yaml "`cat ex47-opt.yml`" -prefix_pop 79 args: -prefix_push p8_ -options_string_yaml "`cat ex47-opt.yml`" -prefix_pop 80 args: -prefix_push p9_ -options_file ex47-opt.json -prefix_pop 81 localrunfiles: ex47-opt.txt ex47-opt.yml ex47-opt.json 82 83 testset: 84 nsize: {{1 2}} 85 86 test: 87 suffix: 3_empty 88 args: -yaml ex47-empty.yaml 89 localrunfiles: ex47-empty.yaml 90 91 test: 92 suffix: 3_merge 93 args: -yaml ex47-merge.yaml -monitor 94 localrunfiles: ex47-merge.yaml 95 96 test: 97 suffix: 3_env 98 env: PETSC_OPTIONS_YAML='"name: value"' 99 filter: grep -E -v -e "(options_left)" 100 args: -monitor 101 102 test: 103 suffix: 3_str 104 args: -yamlstr "name: value" -monitor 105 106 test: 107 suffix: 3_options 108 args: -yaml ex47-options.yaml 109 localrunfiles: ex47-options.yaml 110 111 test: 112 suffix: 3_include 113 args: -yaml ex47-include.yaml 114 localrunfiles: ex47-include.yaml ex47-empty.yaml ex47-options.yaml 115 116 test: 117 suffix: 3_prefix 118 args: -yaml ex47-prefix.yaml 119 localrunfiles: ex47-prefix.yaml 120 121 test: 122 suffix: 3_multidoc 123 args: -yaml ex47-multidoc.yaml 124 localrunfiles: ex47-multidoc.yaml 125 126 TEST*/ 127