forked from UBCHREST/ablate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
95 lines (82 loc) · 3.43 KB
/
main.cpp
File metadata and controls
95 lines (82 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <fstream>
#include <iostream>
#include <memory>
#include <parameters/petscPrefixOptions.hpp>
#include <utilities/demangler.hpp>
#include <utilities/fileUtility.hpp>
#include <utilities/mpiError.hpp>
#include "builder.hpp"
#include "environment/runEnvironment.hpp"
#include "parser/listing.h"
#include "parser/yamlParser.hpp"
#include "utilities/petscError.hpp"
using namespace ablate;
const char* replacementInputPrefix = "-yaml::";
int main(int argc, char** args) {
// initialize petsc and mpi
PetscInitialize(&argc, &args, NULL, NULL) >> checkError;
// check to see if we should print version
PetscBool printInfo = PETSC_FALSE;
PetscOptionsGetBool(NULL, NULL, "-version", &printInfo, NULL) >> checkError;
if (!printInfo) {
PetscOptionsGetBool(NULL, NULL, "--info", &printInfo, NULL) >> checkError;
}
if (printInfo) {
Builder::PrintInfo(std::cout);
std::cout << "----------------------------------------" << std::endl;
}
PetscBool printVersion = PETSC_FALSE;
PetscOptionsGetBool(NULL, NULL, "--version", &printVersion, NULL) >> checkError;
if (printVersion) {
Builder::PrintVersion(std::cout);
return 0;
}
// check to see if we should print options
PetscBool printParserOptions = PETSC_FALSE;
PetscOptionsGetBool(NULL, NULL, "--help", &printParserOptions, NULL) >> checkError;
if (printParserOptions) {
std::cout << parser::Listing::Get() << std::endl;
return 0;
}
// check to see if we should print options
char filename[PETSC_MAX_PATH_LEN] = "";
PetscBool fileSpecified = PETSC_FALSE;
PetscOptionsGetString(NULL, NULL, "--input", filename, PETSC_MAX_PATH_LEN, &fileSpecified) >> checkError;
if (!fileSpecified) {
throw std::invalid_argument("the --input must be specified");
}
// locate or download the file
auto filePath = ablate::utilities::FileUtility::LocateFile(filename, PETSC_COMM_WORLD);
if (!std::filesystem::exists(filePath)) {
throw std::invalid_argument("unable to locate input file: " + filePath.string());
}
{
// build options from the command line
auto yamlOptions = std::make_shared<ablate::parameters::PetscPrefixOptions>(replacementInputPrefix);
// create the yaml parser
std::shared_ptr<parser::YamlParser> parser = std::make_shared<parser::YamlParser>(filePath, true, yamlOptions);
// setup the monitor
auto setupEnvironmentParameters = parser->GetByName<ablate::parameters::Parameters>("environment");
environment::RunEnvironment::Setup(*setupEnvironmentParameters, filePath);
// Copy over the input file
int rank;
MPI_Comm_rank(PETSC_COMM_WORLD, &rank) >> checkMpiError;
if (rank == 0) {
std::filesystem::path inputCopy = environment::RunEnvironment::Get().GetOutputDirectory() / filePath.filename();
std::ofstream stream(inputCopy);
parser->Print(stream);
stream.close();
}
// run with the parser
Builder::Run(parser);
// check for unused parameters
auto unusedValues = parser->GetUnusedValues();
if (!unusedValues.empty()) {
std::cout << "WARNING: The following input parameters were not used:" << std::endl;
for (auto unusedValue : unusedValues) {
std::cout << unusedValue << std::endl;
}
}
}
PetscFinalize() >> checkError;
}