#include <iostream>
struct Scale_options {
};
{
std::cout <<
"Usage: scale [OPTION] <E> <alpha> <dim>\n\n"
"Print action under a change of units.\n\n"
"Example: scale 1.0 0.6 2.0\n\n"
"Options:\n"
" -h, --help print this help message\n"
" -v, --verbose produce verbose output"
<< std::endl;
}
bool starts_with(
const std::string& option,
const std::string& prefix)
{
return !option.compare(0, prefix.size(), prefix);
}
Scale_options& options)
{
const auto n_positional_args = args.size();
if (n_positional_args == 0) {
throw Setup_error(
"value of E must be provided");
} else if (n_positional_args == 1) {
throw Setup_error(
"value of alpha must be provided");
} else if (n_positional_args == 2) {
throw Setup_error(
"scale factor must be provided");
} else if (n_positional_args > 3) {
throw Setup_error(
"unrecognized command line argument '"
+ args[3] + "'");
}
try {
options.E = std::stod(args[0]);
} catch (const std::invalid_argument& e) {
throw Setup_error(
"invalid value for E, '" + args[0] + "'");
}
try {
options.alpha = std::stod(args[1]);
} catch (const std::invalid_argument& e) {
throw Setup_error(
"invalid value for alpha, '" + args[1] + "'");
}
try {
options.scale = std::stod(args[2]);
} catch (const std::invalid_argument& e) {
throw Setup_error(
"invalid value for scale factor '" + args[2] + "'");
}
}
{
Scale_options options;
std::vector<std::string> positional_args;
int i = 1;
bool finished_optionals{false};
while (i < argc) {
const std::string opt(argv[i++]);
if (opt == "--") {
finished_optionals = true;
continue;
}
positional_args.push_back(opt);
continue;
}
if (opt == "-h" || opt == "--help") {
exit(EXIT_SUCCESS);
}
if (opt == "-v" || opt == "--verbose") {
options.verbose = true;
continue;
}
throw Setup_error(
"unrecognized command line argument '" + opt + "'");
}
return options;
}
}
int main(
int argc,
const char* argv[])
{
if (argc == 1) {
std::cerr << "Usage: scale [OPTION] <E> <alpha> <scale>\n"
<< "Try 'scale --help' for more information."
<< std::endl;
return EXIT_FAILURE;
}
int exit_code = 0;
try {
if (options.verbose) {
}
const double E = options.E;
const double alpha = options.alpha;
const double scale = options.scale;
const double false_min = 0.;
const double true_min =
scale;
const double barrier = (0.75 / alpha - 1.) *
scale;
return -pow(scale, 4) * E * (-alpha * phi * phi * phi * phi
+ phi * phi * phi
+ 0.5 * (4. * alpha - 3.) * phi * phi);
};
const auto potential_first = [
E,
alpha,
scale](
double phi) {
return -pow(scale, 3) * E * (-4. * alpha * phi * phi * phi
+ 3. * phi * phi
+ (4. * alpha - 3.) * phi);
};
const auto potential_second = [
E,
alpha,
scale](
double phi) {
return -pow(scale, 2) * E * (-12. * alpha * phi * phi
+ 6. * phi + (4. * alpha - 3.));
};
one_dim.
solve(potential, potential_first, potential_second,
false_min, true_min, barrier,
4, Shooting::Solver_options::Compute_action);
}
catch (
const Error& e) {
std::cerr << "Error: " << e.what() << std::endl;
exit_code = EXIT_FAILURE;
} catch (...) {
std::cerr << "Error: unrecognized error occurred."
<< std::endl;
exit_code = EXIT_FAILURE;
}
return exit_code;
}