Actual source code: ex47.c

  1: static char help[] = "Example for PetscOptionsInsertFileYAML\n";

  3: #include <petscsys.h>

  5: int main(int argc, char **argv)
  6: {
  7:   char      filename[PETSC_MAX_PATH_LEN];
  8:   PetscBool flg;

 10:   PetscFunctionBeginUser;
 11:   PetscCall(PetscInitialize(&argc, &argv, NULL, help));

 13:   PetscCall(PetscOptionsGetString(NULL, NULL, "-f", filename, sizeof(filename), &flg));
 14:   if (flg) PetscCall(PetscOptionsInsertFileYAML(PETSC_COMM_WORLD, NULL, filename, PETSC_TRUE));

 16:   PetscCall(PetscOptionsGetString(NULL, NULL, "-yaml", filename, sizeof(filename), &flg));
 17:   if (flg) {
 18:     PetscBool monitor = PETSC_FALSE;

 20:     PetscCall(PetscOptionsGetBool(NULL, NULL, "-monitor", &monitor, NULL));
 21:     if (monitor) PetscCall(PetscOptionsMonitorSet(PetscOptionsMonitorDefault, PETSC_VIEWER_STDOUT_WORLD, NULL));
 22:     PetscCall(PetscOptionsClear(NULL));
 23:     PetscCall(PetscOptionsInsertFileYAML(PETSC_COMM_WORLD, NULL, filename, PETSC_TRUE));
 24:   }

 26:   PetscCall(PetscOptionsGetString(NULL, NULL, "-yamlstr", filename, sizeof(filename), &flg));
 27:   if (flg) {
 28:     PetscBool monitor = PETSC_FALSE;

 30:     PetscCall(PetscOptionsGetBool(NULL, NULL, "-monitor", &monitor, NULL));
 31:     if (monitor) PetscCall(PetscOptionsMonitorSet(PetscOptionsMonitorDefault, NULL, NULL));
 32:     PetscCall(PetscOptionsClear(NULL));
 33:     PetscCall(PetscOptionsInsertStringYAML(NULL, filename));
 34:   }

 36:   PetscCall(PetscOptionsView(NULL, PETSC_VIEWER_STDOUT_WORLD));
 37:   PetscCall(PetscOptionsClear(NULL));
 38:   PetscCall(PetscFinalize());
 39:   return 0;
 40: }

 42: /*TEST

 44:    testset:
 45:      args: -options_left false
 46:      filter:  grep -E -v "(options_monitor)"
 47:      localrunfiles: petsc.yml

 49:      test:
 50:         suffix: 1
 51:         args: -f petsc.yml

 53:      test:
 54:         suffix: 2_file
 55:         output_file: output/ex47_2.out
 56:         args: -options_file_yaml petsc.yml

 58:      test:
 59:         suffix: 2_string
 60:         args: -options_string_yaml "`cat petsc.yml`"

 62:      test:
 63:         suffix: 2_auto
 64:         args: -options_monitor
 65:         args: -options_file ex47-yaml_tag
 66:         args: -options_file ex47-yaml_doc
 67:         localrunfiles: ex47-yaml_tag ex47-yaml_doc

 69:      test:
 70:         suffix: 2_prefix
 71:         args: -options_monitor
 72:         args: -options_file ex47-opt.txt
 73:         args: -prefix_push p5_ -options_file ex47-opt.yml -prefix_pop
 74:         args: -prefix_push p5_ -options_file ex47-opt.yml:yaml -prefix_pop
 75:         args: -prefix_push p6_ -options_file_yaml ex47-opt.yml -prefix_pop
 76:         args: -prefix_push p7_ -options_string_yaml "`cat ex47-opt.yml`" -prefix_pop
 77:         args: -prefix_push p7_ -options_string_yaml "`cat ex47-opt.yml`" -prefix_pop
 78:         args: -prefix_push p8_ -options_string_yaml "`cat ex47-opt.yml`" -prefix_pop
 79:         args: -prefix_push p9_ -options_file ex47-opt.json -prefix_pop
 80:         localrunfiles: ex47-opt.txt ex47-opt.yml ex47-opt.json

 82:    testset:
 83:      nsize: {{1 2}}

 85:      test:
 86:         suffix: 3_empty
 87:         args: -yaml ex47-empty.yaml
 88:         localrunfiles: ex47-empty.yaml

 90:      test:
 91:         suffix: 3_merge
 92:         args: -yaml ex47-merge.yaml -monitor
 93:         localrunfiles: ex47-merge.yaml

 95:      test:
 96:         suffix: 3_env
 97:         env: PETSC_OPTIONS_YAML='"name: value"'
 98:         args: -monitor

100:      test:
101:         suffix: 3_str
102:         args: -yamlstr "name: value" -monitor

104:      test:
105:         suffix: 3_options
106:         args: -yaml ex47-options.yaml
107:         localrunfiles: ex47-options.yaml

109:      test:
110:         suffix: 3_include
111:         args: -yaml ex47-include.yaml
112:         localrunfiles: ex47-include.yaml ex47-empty.yaml ex47-options.yaml

114:      test:
115:         suffix: 3_prefix
116:         args: -yaml ex47-prefix.yaml
117:         localrunfiles: ex47-prefix.yaml

119:      test:
120:         suffix: 3_multidoc
121:         args: -yaml ex47-multidoc.yaml
122:         localrunfiles: ex47-multidoc.yaml

124: TEST*/