53Eigen::MatrixX3d
readJSON(TCLAP::ValueArg<std::string>
const& input_filename)
55 using json = nlohmann::json;
56 std::ifstream f(input_filename.getValue());
59 OGS_FATAL(
"Could not open file '{:s}'", input_filename.getValue());
61 json
const data = json::parse(f);
63 auto const number_of_anchors = data[
"anchor_start_points"].size();
64 if (number_of_anchors == 0)
66 OGS_FATAL(
"No anchors found in the json.");
68 if (number_of_anchors != data[
"anchor_end_points"].size())
71 "Number of anchor start points does not match the number of end "
75 Eigen::MatrixX3d realcoords(2 * number_of_anchors, 3);
77 auto get_coordinates = [&data](
const char* key, std::size_t
const i)
79 const auto& v = data[key][i].get_ref<json::array_t
const&>();
83 "Expected a vector of length three for {:s} {}. Got vector of "
87 return Eigen::RowVector3d{v[0].get<
double>(), v[1].get<double>(),
91 for (std::size_t i = 0; i < number_of_anchors; i++)
93 realcoords.row(2 * i).noalias() =
94 get_coordinates(
"anchor_start_points", i);
95 realcoords.row(2 * i + 1).noalias() =
96 get_coordinates(
"anchor_end_points", i);
107 "Computes natual coordinates from given real coordinates\n\n"
109 "OpenGeoSys-6 software, version " +
112 "Copyright (c) 2012-2025, OpenGeoSys Community "
113 "(http://www.opengeosys.org)",
116 TCLAP::ValueArg<std::string> log_level_arg(
118 "the verbosity of logging messages: none, error, warn, info, debug, "
128 TCLAP::ValueArg<std::string> input_filename_arg(
129 "i",
"input",
"Input bulk mesh",
true,
"",
"VTU_FILE", cmd);
131 TCLAP::ValueArg<std::string> output_filename_arg(
132 "o",
"output",
"Anchor mesh",
true,
"",
"VTU_FILE", cmd);
134 TCLAP::ValueArg<std::string> json_filename_arg(
135 "f",
"json-file",
"JSON file containing anchor start and end points",
136 true,
"",
"JSON_FILE", cmd);
138 TCLAP::ValueArg<double> tolerance_arg(
139 "",
"tolerance",
"Tolerance/Search length",
false,
140 std::numeric_limits<double>::epsilon(),
"float", cmd);
142 TCLAP::ValueArg<unsigned> max_iter_arg(
144 "maximum number of iterations of the internal root-finding algorithm",
145 false, 5,
"int", cmd);
147 cmd.parse(argc, argv);
150 spdlog::set_pattern(
"%^%l:%$ %v");
151 spdlog::set_error_handler(
152 [](
const std::string& msg)
154 std::cerr <<
"spdlog error: " << msg << std::endl;
155 OGS_FATAL(
"spdlog logger error occurred.");
158 auto const realcoords =
readJSON(json_filename_arg);
159 auto const bulk_mesh =
readGrid(input_filename_arg.getValue());
163 AU::ComputeNaturalCoordsResult
const result = AU::computeNaturalCoords(
164 bulk_mesh, realcoords, tolerance_arg.getValue(),
165 max_iter_arg.getValue());
167 auto const output_mesh = AU::toVTKGrid(result);
168 writeGrid(output_mesh, output_filename_arg.getValue());
172 OGS_FATAL(
"Failed to compute natural coordinates.");